libcopp 2.3.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
future.h
Go to the documentation of this file.
1// Copyright 2023 owent
2
3#pragma once
4
5#include <libcopp/utils/config/libcopp_build_features.h>
6
7// clang-format off
8#include <libcopp/utils/config/stl_include_prefix.h> // NOLINT(build/include_order)
9// clang-format on
10#include <list>
11// clang-format off
12#include <libcopp/utils/config/stl_include_suffix.h> // NOLINT(build/include_order)
13// clang-format on
14
16
17LIBCOPP_COPP_NAMESPACE_BEGIN
18namespace future {
19
20template <class T, class TPTR = typename poll_storage_ptr_selector<T>::type>
21class LIBCOPP_COPP_API_HEAD_ONLY future {
22 public:
28
29 public:
30 future() noexcept(std::is_nothrow_constructible<poller_type>::value) {}
31 ~future() noexcept(std::is_nothrow_destructible<poller_type>::value) {}
32
33 LIBCOPP_UTIL_FORCEINLINE bool is_ready() const noexcept { return poll_data_.is_ready(); }
34
35 LIBCOPP_UTIL_FORCEINLINE bool is_pending() const noexcept { return poll_data_.is_pending(); }
36
37 LIBCOPP_UTIL_FORCEINLINE const value_type *data() const noexcept {
38 if (!is_ready()) {
39 return nullptr;
40 }
41
42 return poll_data_.data();
43 }
44
46 if (!is_ready()) {
47 return nullptr;
48 }
49
50 return poll_data_.data();
51 }
52
53 LIBCOPP_UTIL_FORCEINLINE const ptr_type &raw_ptr() const noexcept { return poll_data_.raw_ptr(); }
54 LIBCOPP_UTIL_FORCEINLINE ptr_type &raw_ptr() noexcept { return poll_data_.raw_ptr(); }
55 LIBCOPP_UTIL_FORCEINLINE const poller_type &poll_data() const noexcept { return poll_data_; }
56 LIBCOPP_UTIL_FORCEINLINE poller_type &poll_data() noexcept { return poll_data_; }
57 LIBCOPP_UTIL_FORCEINLINE void reset_data() noexcept(noexcept(::std::declval<poller_type>().reset())) {
58 poll_data_.reset();
59 }
60
61 template <class U>
62 LIBCOPP_UTIL_FORCEINLINE void reset_data(U &&in) noexcept(std::is_nothrow_assignable<poller_type, U>::value) {
63 poll_data_ = std::forward<U>(in);
64 }
65
66 private:
68};
69
70} // namespace future
71LIBCOPP_COPP_NAMESPACE_END
~future() noexcept(std::is_nothrow_destructible< poller_type >::value)
Definition future.h:31
LIBCOPP_UTIL_FORCEINLINE poller_type & poll_data() noexcept
Definition future.h:56
LIBCOPP_UTIL_FORCEINLINE bool is_ready() const noexcept
Definition future.h:33
LIBCOPP_UTIL_FORCEINLINE const poller_type & poll_data() const noexcept
Definition future.h:55
typename poller_type::storage_type storage_type
Definition future.h:25
LIBCOPP_UTIL_FORCEINLINE ptr_type & raw_ptr() noexcept
Definition future.h:54
LIBCOPP_UTIL_FORCEINLINE bool is_pending() const noexcept
Definition future.h:35
LIBCOPP_UTIL_FORCEINLINE void reset_data(U &&in) noexcept(std::is_nothrow_assignable< poller_type, U >::value)
Definition future.h:62
LIBCOPP_UTIL_FORCEINLINE value_type * data() noexcept
Definition future.h:45
poller_type poll_data_
Definition future.h:67
future() noexcept(std::is_nothrow_constructible< poller_type >::value)
Definition future.h:30
typename poller_type::value_type value_type
Definition future.h:26
LIBCOPP_UTIL_FORCEINLINE const value_type * data() const noexcept
Definition future.h:37
typename poller_type::ptr_type ptr_type
Definition future.h:27
LIBCOPP_UTIL_FORCEINLINE const ptr_type & raw_ptr() const noexcept
Definition future.h:53
LIBCOPP_UTIL_FORCEINLINE void reset_data() noexcept(noexcept(::std::declval< poller_type >().reset()))
Definition future.h:57
typename poll_storage::ptr_type ptr_type
Definition poller.h:18
typename poll_storage::storage_type storage_type
Definition poller.h:17
typename poll_storage::value_type value_type
Definition poller.h:19
#define LIBCOPP_UTIL_FORCEINLINE
STL namespace.