libcopp 2.3.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
poller.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
8
9LIBCOPP_COPP_NAMESPACE_BEGIN
10namespace future {
11template <class T, class TPTR = typename poll_storage_ptr_selector<T>::type>
12class LIBCOPP_COPP_API_HEAD_ONLY poller {
13 public:
15 // If T is trivial and is smaller than size of four pointers, using small object optimization
20
21 public:
22 inline poller() noexcept { poll_storage::construct_default_storage(storage_data_); }
23
24 inline ~poller() noexcept(std::is_nothrow_destructible<storage_type>::value) {
25 poll_storage::construct_default_storage(storage_data_);
26 }
27
28 template <class... U>
29 inline poller(U &&...in) noexcept(noexcept(poll_storage::construct_storage(std::declval<storage_type &>(),
30 std::forward<U>(in)...))) {
31 setup_from(std::forward<U>(in)...);
32 }
33
34 inline poller(self_type &&other) noexcept(noexcept(poll_storage::move_storage(std::declval<storage_type &>(),
35 std::declval<storage_type>()))) {
36 setup_from(std::move(other));
37 }
38
39 inline poller &operator=(self_type &&other) noexcept(
40 noexcept(poll_storage::move_storage(std::declval<storage_type &>(), std::declval<storage_type>()))) {
41 setup_from(std::move(other));
42 return *this;
43 }
44
45 template <class U>
46 inline poller &operator=(U &&in) noexcept(noexcept(poll_storage::construct_storage(std::declval<storage_type &>(),
47 std::forward<U>(in)))) {
48 setup_from(std::forward<U>(in));
49 return *this;
50 }
51
52 LIBCOPP_UTIL_FORCEINLINE bool is_ready() const noexcept { return !!poll_storage::unwrap(storage_data_); }
53
54 LIBCOPP_UTIL_FORCEINLINE bool is_pending() const noexcept { return !poll_storage::unwrap(storage_data_); }
55
56 LIBCOPP_UTIL_FORCEINLINE const value_type *data() const noexcept { return poll_storage::unwrap(storage_data_).get(); }
57 LIBCOPP_UTIL_FORCEINLINE value_type *data() noexcept { return poll_storage::unwrap(storage_data_).get(); }
58
59 LIBCOPP_UTIL_FORCEINLINE const ptr_type &raw_ptr() const noexcept { return poll_storage::unwrap(storage_data_); }
60 LIBCOPP_UTIL_FORCEINLINE ptr_type &raw_ptr() noexcept { return poll_storage::unwrap(storage_data_); }
61
62 LIBCOPP_UTIL_FORCEINLINE void reset() noexcept(noexcept(poll_storage::reset(std::declval<storage_type &>()))) {
63 poll_storage::reset(storage_data_);
64 }
65 LIBCOPP_UTIL_FORCEINLINE void swap(self_type &other) noexcept {
66 poll_storage::swap(storage_data_, other.storage_data_);
67 }
68 LIBCOPP_UTIL_FORCEINLINE friend void swap(self_type &l, self_type &r) noexcept { l.swap(r); }
69
70 private:
71 template <class U, class UDELETER,
72 typename std::enable_if<std::is_base_of<T, typename std::decay<U>::type>::value, bool>::type = false>
73 inline void setup_from(std::unique_ptr<U, UDELETER> &&in) noexcept(
74 noexcept(poll_storage::construct_storage(std::declval<storage_type &>(), std::move(in)))) {
75 poll_storage::construct_storage(storage_data_, std::move(in));
76 }
77
78 template <class... TARGS>
79 inline void setup_from(TARGS &&...args) noexcept(
80 noexcept(poll_storage::construct_storage(std::declval<storage_type &>(), std::forward<TARGS>(args)...))) {
81 poll_storage::construct_storage(storage_data_, std::forward<TARGS>(args)...);
82 }
83
84 inline void setup_from(self_type &&other) noexcept(
85 noexcept(poll_storage::move_storage(std::declval<storage_type &>(), std::move(other.storage_data_)))) {
86 poll_storage::move_storage(storage_data_, std::move(other.storage_data_));
87 }
88
89 private:
91};
92} // namespace future
93LIBCOPP_COPP_NAMESPACE_END
LIBCOPP_UTIL_FORCEINLINE const value_type * data() const noexcept
Definition poller.h:56
void setup_from(TARGS &&...args) noexcept(noexcept(poll_storage::construct_storage(std::declval< storage_type & >(), std::forward< TARGS >(args)...)))
Definition poller.h:79
typename poll_storage::ptr_type ptr_type
Definition poller.h:18
storage_type storage_data_
Definition poller.h:90
poller & operator=(U &&in) noexcept(noexcept(poll_storage::construct_storage(std::declval< storage_type & >(), std::forward< U >(in))))
Definition poller.h:46
typename poll_storage::storage_type storage_type
Definition poller.h:17
LIBCOPP_UTIL_FORCEINLINE bool is_ready() const noexcept
Definition poller.h:52
LIBCOPP_UTIL_FORCEINLINE friend void swap(self_type &l, self_type &r) noexcept
Definition poller.h:68
~poller() noexcept(std::is_nothrow_destructible< storage_type >::value)
Definition poller.h:24
poller(U &&...in) noexcept(noexcept(poll_storage::construct_storage(std::declval< storage_type & >(), std::forward< U >(in)...)))
Definition poller.h:29
poller(self_type &&other) noexcept(noexcept(poll_storage::move_storage(std::declval< storage_type & >(), std::declval< storage_type >())))
Definition poller.h:34
LIBCOPP_UTIL_FORCEINLINE void reset() noexcept(noexcept(poll_storage::reset(std::declval< storage_type & >())))
Definition poller.h:62
LIBCOPP_UTIL_FORCEINLINE ptr_type & raw_ptr() noexcept
Definition poller.h:60
poller & operator=(self_type &&other) noexcept(noexcept(poll_storage::move_storage(std::declval< storage_type & >(), std::declval< storage_type >())))
Definition poller.h:39
void setup_from(self_type &&other) noexcept(noexcept(poll_storage::move_storage(std::declval< storage_type & >(), std::move(other.storage_data_))))
Definition poller.h:84
LIBCOPP_UTIL_FORCEINLINE value_type * data() noexcept
Definition poller.h:57
LIBCOPP_UTIL_FORCEINLINE void swap(self_type &other) noexcept
Definition poller.h:65
void setup_from(std::unique_ptr< U, UDELETER > &&in) noexcept(noexcept(poll_storage::construct_storage(std::declval< storage_type & >(), std::move(in))))
Definition poller.h:73
LIBCOPP_UTIL_FORCEINLINE const ptr_type & raw_ptr() const noexcept
Definition poller.h:59
typename poll_storage::value_type value_type
Definition poller.h:19
poller() noexcept
Definition poller.h:22
LIBCOPP_UTIL_FORCEINLINE bool is_pending() const noexcept
Definition poller.h:54
#define LIBCOPP_UTIL_FORCEINLINE
STL namespace.