Skip to content

Commit

Permalink
Fix C++23 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenwdv committed Nov 5, 2024
1 parent 7dee3b8 commit 320f736
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 91 deletions.
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
109 changes: 33 additions & 76 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

0 comments on commit 320f736

Please sign in to comment.