From 7dee3b84eea82ef3ca13b79b611d975a48550489 Mon Sep 17 00:00:00 2001 From: Steven WdV <> Date: Tue, 16 Jan 2024 13:31:52 +0100 Subject: [PATCH 1/2] Fix C++20 compatibility Closes ReactiveX#602 --- Rx/v2/src/rxcpp/rx-util.hpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Rx/v2/src/rxcpp/rx-util.hpp b/Rx/v2/src/rxcpp/rx-util.hpp index cde8ea86c..cf641812e 100644 --- a/Rx/v2/src/rxcpp/rx-util.hpp +++ b/Rx/v2/src/rxcpp/rx-util.hpp @@ -996,22 +996,16 @@ struct filtered_hash::value>::type> }; template struct filtered_hash>::value>::type> { - using argument_type = T; - using result_type = std::size_t; - - result_type operator()(argument_type const & dur) const + std::size_t operator()(T const & dur) const { - return std::hash{}(dur.count()); + return std::hash{}(dur.count()); } }; template struct filtered_hash>::value>::type> { - using argument_type = T; - using result_type = std::size_t; - - result_type operator()(argument_type const & tp) const + std::size_t operator()(T const & tp) const { - return std::hash{}(tp.time_since_epoch().count()); + return std::hash{}(tp.time_since_epoch().count()); } }; @@ -1022,8 +1016,6 @@ struct is_hashable template struct is_hashable::result_type, - typename filtered_hash::argument_type, typename rxu::callable_result, T>::type>::type> : std::true_type {}; From 320f7362b0cecfc39da41c418f1751a909ff49e9 Mon Sep 17 00:00:00 2001 From: Steven WdV Date: Tue, 5 Nov 2024 10:32:36 +0100 Subject: [PATCH 2/2] Fix C++23 compatibility --- Rx/v2/src/rxcpp/operators/rx-concat_map.hpp | 4 - Rx/v2/src/rxcpp/operators/rx-reduce.hpp | 5 - Rx/v2/src/rxcpp/operators/rx-subscribe_on.hpp | 6 - Rx/v2/src/rxcpp/rx-includes.hpp | 1 + Rx/v2/src/rxcpp/rx-util.hpp | 109 ++++++------------ 5 files changed, 34 insertions(+), 91 deletions(-) diff --git a/Rx/v2/src/rxcpp/operators/rx-concat_map.hpp b/Rx/v2/src/rxcpp/operators/rx-concat_map.hpp index ba91e6619..bfce4ab6d 100644 --- a/Rx/v2/src/rxcpp/operators/rx-concat_map.hpp +++ b/Rx/v2/src/rxcpp/operators/rx-concat_map.hpp @@ -115,8 +115,6 @@ struct concat_map collection_selector_type selectCollection; result_selector_type selectResult; coordination_type coordination; - private: - values& operator=(const values&) RXCPP_DELETE; }; values initial; @@ -275,8 +273,6 @@ struct concat_map source->subscribe(std::move(selectedSink.get())); } -private: - concat_map& operator=(const concat_map&) RXCPP_DELETE; }; } diff --git a/Rx/v2/src/rxcpp/operators/rx-reduce.hpp b/Rx/v2/src/rxcpp/operators/rx-reduce.hpp index 724d4f7ae..285a9668a 100644 --- a/Rx/v2/src/rxcpp/operators/rx-reduce.hpp +++ b/Rx/v2/src/rxcpp/operators/rx-reduce.hpp @@ -124,9 +124,6 @@ struct reduce : public operator_base diff --git a/Rx/v2/src/rxcpp/operators/rx-subscribe_on.hpp b/Rx/v2/src/rxcpp/operators/rx-subscribe_on.hpp index 1a4d854e7..31ff4b914 100644 --- a/Rx/v2/src/rxcpp/operators/rx-subscribe_on.hpp +++ b/Rx/v2/src/rxcpp/operators/rx-subscribe_on.hpp @@ -59,8 +59,6 @@ struct subscribe_on : public operator_base } source_type source; coordination_type coordination; - private: - subscribe_on_values& operator=(subscribe_on_values o) RXCPP_DELETE; }; const subscribe_on_values initial; @@ -87,8 +85,6 @@ struct subscribe_on : public operator_base } composite_subscription source_lifetime; output_type out; - private: - subscribe_on_state_type& operator=(subscribe_on_state_type o) RXCPP_DELETE; }; composite_subscription coordinator_lifetime; @@ -138,8 +134,6 @@ struct subscribe_on : public operator_base controller.schedule(selectedProducer.get()); } -private: - subscribe_on& operator=(subscribe_on o) RXCPP_DELETE; }; } diff --git a/Rx/v2/src/rxcpp/rx-includes.hpp b/Rx/v2/src/rxcpp/rx-includes.hpp index 55b1e0be1..3e53fbcc7 100644 --- a/Rx/v2/src/rxcpp/rx-includes.hpp +++ b/Rx/v2/src/rxcpp/rx-includes.hpp @@ -181,6 +181,7 @@ #include #include #include +#include #include #include #include diff --git a/Rx/v2/src/rxcpp/rx-util.hpp b/Rx/v2/src/rxcpp/rx-util.hpp index cf641812e..11c490e3a 100644 --- a/Rx/v2/src/rxcpp/rx-util.hpp +++ b/Rx/v2/src/rxcpp/rx-util.hpp @@ -490,8 +490,6 @@ struct endline void operator()() const { os << std::endl; } -private: - endline& operator=(const endline&) RXCPP_DELETE; }; template @@ -503,8 +501,6 @@ struct insert_value void operator()() const { os << value; } -private: - insert_value& operator=(const insert_value&) RXCPP_DELETE; }; template @@ -516,8 +512,6 @@ struct insert_function void operator()() const { call(os); } -private: - insert_function& operator=(const insert_function&) RXCPP_DELETE; }; template @@ -568,131 +562,94 @@ namespace detail { template class maybe { - bool is_set; - typename std::aligned_storage::value>::type - storage; + std::optional val_; public: - maybe() - : is_set(false) - { - } + maybe() = default; maybe(const T& value) - : is_set(false) + : val_(value) { - new (reinterpret_cast(&storage)) T(value); - is_set = true; } maybe(T&& value) - : is_set(false) - { - new (reinterpret_cast(&storage)) T(std::move(value)); - is_set = true; - } - - maybe(const maybe& other) - : is_set(false) - { - if (other.is_set) { - new (reinterpret_cast(&storage)) T(other.get()); - is_set = true; - } - } - maybe(maybe&& other) - : is_set(false) + : val_(std::move(value)) { - if (other.is_set) { - new (reinterpret_cast(&storage)) T(std::move(other.get())); - is_set = true; - other.reset(); - } } - ~maybe() - { - reset(); - } + maybe(const maybe& other) = default; + maybe(maybe&& other) = default; using value_type = T; using iterator = T *; using const_iterator = const T *; bool empty() const { - return !is_set; + return !val_; } std::size_t size() const { - return is_set ? 1 : 0; + return val_ ? 1 : 0; } iterator begin() { - return reinterpret_cast(&storage); + return val_ ? &*val_ : nullptr; } const_iterator begin() const { - return reinterpret_cast(&storage); + return val_ ? &*val_ : nullptr; } iterator end() { - return reinterpret_cast(&storage) + size(); + return begin() + size(); } const_iterator end() const { - return reinterpret_cast(&storage) + size(); + return begin() + size(); } T* operator->() { - if (!is_set) std::terminate(); - return reinterpret_cast(&storage); + if (!val_) std::terminate(); + return val_.operator->(); } const T* operator->() const { - if (!is_set) std::terminate(); - return reinterpret_cast(&storage); + if (!val_) std::terminate(); + return val_.operator->(); } T& operator*() { - if (!is_set) std::terminate(); - return *reinterpret_cast(&storage); + if (!val_) std::terminate(); + return *val_; } const T& operator*() const { - if (!is_set) std::terminate(); - return *reinterpret_cast(&storage); + if (!val_) std::terminate(); + return *val_; } T& get() { - if (!is_set) std::terminate(); - return *reinterpret_cast(&storage); + return **this; } const T& get() const { - if (!is_set) std::terminate(); - return *reinterpret_cast(&storage); + return **this; } void reset() { - if (is_set) { - is_set = false; - reinterpret_cast(&storage)->~T(); - //std::fill_n(reinterpret_cast(&storage), sizeof(T), 0); - } + val_.reset(); } - template + template void reset(U&& value) { - reset(); - new (reinterpret_cast(&storage)) T(std::forward(value)); - is_set = true; + *this = std::forward(value); } - maybe& operator=(const T& other) { - reset(other); + maybe& operator=(const maybe& other) = default; + maybe& operator=(maybe&& other) = default; + + maybe& operator=(const T& value) { + val_ = value; return *this; } - maybe& operator=(const maybe& other) { - if (!other.empty()) { - reset(other.get()); - } else { - reset(); - } + + maybe& operator=(T&& value) { + val_ = std::move(value); return *this; } };