Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix C++23 compatibility #609

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Rx/v2/src/rxcpp/operators/rx-concat_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -275,8 +273,6 @@ struct concat_map
source->subscribe(std::move(selectedSink.get()));

}
private:
concat_map& operator=(const concat_map&) RXCPP_DELETE;
};

}
Expand Down
5 changes: 0 additions & 5 deletions Rx/v2/src/rxcpp/operators/rx-reduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ struct reduce : public operator_base<rxu::value_type_t<reduce_traits<T, Observab
accumulator_type accumulator;
result_selector_type result_selector;
seed_type seed;

private:
reduce_initial_type& operator=(reduce_initial_type o) RXCPP_DELETE;
};
reduce_initial_type initial;

Expand Down Expand Up @@ -181,8 +178,6 @@ struct reduce : public operator_base<rxu::value_type_t<reduce_traits<T, Observab
}
);
}
private:
reduce& operator=(reduce o) RXCPP_DELETE;
};

template<class T>
Expand Down
6 changes: 0 additions & 6 deletions Rx/v2/src/rxcpp/operators/rx-subscribe_on.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ struct subscribe_on : public operator_base<T>
}
source_type source;
coordination_type coordination;
private:
subscribe_on_values& operator=(subscribe_on_values o) RXCPP_DELETE;
};
const subscribe_on_values initial;

Expand All @@ -87,8 +85,6 @@ struct subscribe_on : public operator_base<T>
}
composite_subscription source_lifetime;
output_type out;
private:
subscribe_on_state_type& operator=(subscribe_on_state_type o) RXCPP_DELETE;
};

composite_subscription coordinator_lifetime;
Expand Down Expand Up @@ -138,8 +134,6 @@ struct subscribe_on : public operator_base<T>

controller.schedule(selectedProducer.get());
}
private:
subscribe_on& operator=(subscribe_on o) RXCPP_DELETE;
};

}
Expand Down
1 change: 1 addition & 0 deletions Rx/v2/src/rxcpp/rx-includes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
#include <map>
#include <set>
#include <mutex>
#include <optional>
#include <deque>
#include <thread>
#include <future>
Expand Down
125 changes: 37 additions & 88 deletions Rx/v2/src/rxcpp/rx-util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,6 @@ struct endline
void operator()() const {
os << std::endl;
}
private:
endline& operator=(const endline&) RXCPP_DELETE;
};

template<class OStream, class ValueType>
Expand All @@ -503,8 +501,6 @@ struct insert_value
void operator()() const {
os << value;
}
private:
insert_value& operator=(const insert_value&) RXCPP_DELETE;
};

template<class OStream, class Function>
Expand All @@ -516,8 +512,6 @@ struct insert_function
void operator()() const {
call(os);
}
private:
insert_function& operator=(const insert_function&) RXCPP_DELETE;
};

template<class OStream, class Delimit>
Expand Down Expand Up @@ -568,131 +562,94 @@ namespace detail {
template <class T>
class maybe
{
bool is_set;
typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type
storage;
std::optional<T> val_;
public:
maybe()
: is_set(false)
{
}
maybe() = default;

maybe(const T& value)
: is_set(false)
: val_(value)
{
new (reinterpret_cast<T*>(&storage)) T(value);
is_set = true;
}

maybe(T&& value)
: is_set(false)
{
new (reinterpret_cast<T*>(&storage)) T(std::move(value));
is_set = true;
}

maybe(const maybe& other)
: is_set(false)
{
if (other.is_set) {
new (reinterpret_cast<T*>(&storage)) T(other.get());
is_set = true;
}
}
maybe(maybe&& other)
: is_set(false)
: val_(std::move(value))
{
if (other.is_set) {
new (reinterpret_cast<T*>(&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<T*>(&storage);
return val_ ? &*val_ : nullptr;
}
const_iterator begin() const {
return reinterpret_cast<T*>(&storage);
return val_ ? &*val_ : nullptr;
}

iterator end() {
return reinterpret_cast<T*>(&storage) + size();
return begin() + size();
}
const_iterator end() const {
return reinterpret_cast<T*>(&storage) + size();
return begin() + size();
}

T* operator->() {
if (!is_set) std::terminate();
return reinterpret_cast<T*>(&storage);
if (!val_) std::terminate();
return val_.operator->();
}
const T* operator->() const {
if (!is_set) std::terminate();
return reinterpret_cast<T*>(&storage);
if (!val_) std::terminate();
return val_.operator->();
}

T& operator*() {
if (!is_set) std::terminate();
return *reinterpret_cast<T*>(&storage);
if (!val_) std::terminate();
return *val_;
}
const T& operator*() const {
if (!is_set) std::terminate();
return *reinterpret_cast<T*>(&storage);
if (!val_) std::terminate();
return *val_;
}

T& get() {
if (!is_set) std::terminate();
return *reinterpret_cast<T*>(&storage);
return **this;
}
const T& get() const {
if (!is_set) std::terminate();
return *reinterpret_cast<const T*>(&storage);
return **this;
}

void reset()
{
if (is_set) {
is_set = false;
reinterpret_cast<T*>(&storage)->~T();
//std::fill_n(reinterpret_cast<char*>(&storage), sizeof(T), 0);
}
val_.reset();
}

template<class U>
template<class U = T>
void reset(U&& value) {
reset();
new (reinterpret_cast<T*>(&storage)) T(std::forward<U>(value));
is_set = true;
*this = std::forward<U>(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;
}
};
Expand Down Expand Up @@ -996,22 +953,16 @@ struct filtered_hash<T, typename std::enable_if<rxu::is_string<T>::value>::type>
};
template <class T>
struct filtered_hash<T, typename std::enable_if<std::is_convertible<T, std::chrono::duration<typename T::rep, typename T::period>>::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<typename argument_type::rep>{}(dur.count());
return std::hash<typename T::rep>{}(dur.count());
}
};
template <class T>
struct filtered_hash<T, typename std::enable_if<std::is_convertible<T, std::chrono::time_point<typename T::clock, typename T::duration>>::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<typename argument_type::rep>{}(tp.time_since_epoch().count());
return std::hash<typename T::rep>{}(tp.time_since_epoch().count());
}
};

Expand All @@ -1022,8 +973,6 @@ struct is_hashable
template<typename T>
struct is_hashable<T,
typename rxu::types_checked_from<
typename filtered_hash<T>::result_type,
typename filtered_hash<T>::argument_type,
typename rxu::callable_result<filtered_hash<T>, T>::type>::type>
: std::true_type {};

Expand Down