Skip to content

Commit 320f736

Browse files
committed
Fix C++23 compatibility
1 parent 7dee3b8 commit 320f736

File tree

5 files changed

+34
-91
lines changed

5 files changed

+34
-91
lines changed

Rx/v2/src/rxcpp/operators/rx-concat_map.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ struct concat_map
115115
collection_selector_type selectCollection;
116116
result_selector_type selectResult;
117117
coordination_type coordination;
118-
private:
119-
values& operator=(const values&) RXCPP_DELETE;
120118
};
121119
values initial;
122120

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

277275
}
278-
private:
279-
concat_map& operator=(const concat_map&) RXCPP_DELETE;
280276
};
281277

282278
}

Rx/v2/src/rxcpp/operators/rx-reduce.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ struct reduce : public operator_base<rxu::value_type_t<reduce_traits<T, Observab
124124
accumulator_type accumulator;
125125
result_selector_type result_selector;
126126
seed_type seed;
127-
128-
private:
129-
reduce_initial_type& operator=(reduce_initial_type o) RXCPP_DELETE;
130127
};
131128
reduce_initial_type initial;
132129

@@ -181,8 +178,6 @@ struct reduce : public operator_base<rxu::value_type_t<reduce_traits<T, Observab
181178
}
182179
);
183180
}
184-
private:
185-
reduce& operator=(reduce o) RXCPP_DELETE;
186181
};
187182

188183
template<class T>

Rx/v2/src/rxcpp/operators/rx-subscribe_on.hpp

-6
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ struct subscribe_on : public operator_base<T>
5959
}
6060
source_type source;
6161
coordination_type coordination;
62-
private:
63-
subscribe_on_values& operator=(subscribe_on_values o) RXCPP_DELETE;
6462
};
6563
const subscribe_on_values initial;
6664

@@ -87,8 +85,6 @@ struct subscribe_on : public operator_base<T>
8785
}
8886
composite_subscription source_lifetime;
8987
output_type out;
90-
private:
91-
subscribe_on_state_type& operator=(subscribe_on_state_type o) RXCPP_DELETE;
9288
};
9389

9490
composite_subscription coordinator_lifetime;
@@ -138,8 +134,6 @@ struct subscribe_on : public operator_base<T>
138134

139135
controller.schedule(selectedProducer.get());
140136
}
141-
private:
142-
subscribe_on& operator=(subscribe_on o) RXCPP_DELETE;
143137
};
144138

145139
}

Rx/v2/src/rxcpp/rx-includes.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
#include <map>
182182
#include <set>
183183
#include <mutex>
184+
#include <optional>
184185
#include <deque>
185186
#include <thread>
186187
#include <future>

Rx/v2/src/rxcpp/rx-util.hpp

+33-76
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,6 @@ struct endline
490490
void operator()() const {
491491
os << std::endl;
492492
}
493-
private:
494-
endline& operator=(const endline&) RXCPP_DELETE;
495493
};
496494

497495
template<class OStream, class ValueType>
@@ -503,8 +501,6 @@ struct insert_value
503501
void operator()() const {
504502
os << value;
505503
}
506-
private:
507-
insert_value& operator=(const insert_value&) RXCPP_DELETE;
508504
};
509505

510506
template<class OStream, class Function>
@@ -516,8 +512,6 @@ struct insert_function
516512
void operator()() const {
517513
call(os);
518514
}
519-
private:
520-
insert_function& operator=(const insert_function&) RXCPP_DELETE;
521515
};
522516

523517
template<class OStream, class Delimit>
@@ -568,131 +562,94 @@ namespace detail {
568562
template <class T>
569563
class maybe
570564
{
571-
bool is_set;
572-
typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type
573-
storage;
565+
std::optional<T> val_;
574566
public:
575-
maybe()
576-
: is_set(false)
577-
{
578-
}
567+
maybe() = default;
579568

580569
maybe(const T& value)
581-
: is_set(false)
570+
: val_(value)
582571
{
583-
new (reinterpret_cast<T*>(&storage)) T(value);
584-
is_set = true;
585572
}
586573

587574
maybe(T&& value)
588-
: is_set(false)
589-
{
590-
new (reinterpret_cast<T*>(&storage)) T(std::move(value));
591-
is_set = true;
592-
}
593-
594-
maybe(const maybe& other)
595-
: is_set(false)
596-
{
597-
if (other.is_set) {
598-
new (reinterpret_cast<T*>(&storage)) T(other.get());
599-
is_set = true;
600-
}
601-
}
602-
maybe(maybe&& other)
603-
: is_set(false)
575+
: val_(std::move(value))
604576
{
605-
if (other.is_set) {
606-
new (reinterpret_cast<T*>(&storage)) T(std::move(other.get()));
607-
is_set = true;
608-
other.reset();
609-
}
610577
}
611578

612-
~maybe()
613-
{
614-
reset();
615-
}
579+
maybe(const maybe& other) = default;
580+
maybe(maybe&& other) = default;
616581

617582
using value_type = T;
618583
using iterator = T *;
619584
using const_iterator = const T *;
620585

621586
bool empty() const {
622-
return !is_set;
587+
return !val_;
623588
}
624589

625590
std::size_t size() const {
626-
return is_set ? 1 : 0;
591+
return val_ ? 1 : 0;
627592
}
628593

629594
iterator begin() {
630-
return reinterpret_cast<T*>(&storage);
595+
return val_ ? &*val_ : nullptr;
631596
}
632597
const_iterator begin() const {
633-
return reinterpret_cast<T*>(&storage);
598+
return val_ ? &*val_ : nullptr;
634599
}
635600

636601
iterator end() {
637-
return reinterpret_cast<T*>(&storage) + size();
602+
return begin() + size();
638603
}
639604
const_iterator end() const {
640-
return reinterpret_cast<T*>(&storage) + size();
605+
return begin() + size();
641606
}
642607

643608
T* operator->() {
644-
if (!is_set) std::terminate();
645-
return reinterpret_cast<T*>(&storage);
609+
if (!val_) std::terminate();
610+
return val_.operator->();
646611
}
647612
const T* operator->() const {
648-
if (!is_set) std::terminate();
649-
return reinterpret_cast<T*>(&storage);
613+
if (!val_) std::terminate();
614+
return val_.operator->();
650615
}
651616

652617
T& operator*() {
653-
if (!is_set) std::terminate();
654-
return *reinterpret_cast<T*>(&storage);
618+
if (!val_) std::terminate();
619+
return *val_;
655620
}
656621
const T& operator*() const {
657-
if (!is_set) std::terminate();
658-
return *reinterpret_cast<T*>(&storage);
622+
if (!val_) std::terminate();
623+
return *val_;
659624
}
660625

661626
T& get() {
662-
if (!is_set) std::terminate();
663-
return *reinterpret_cast<T*>(&storage);
627+
return **this;
664628
}
665629
const T& get() const {
666-
if (!is_set) std::terminate();
667-
return *reinterpret_cast<const T*>(&storage);
630+
return **this;
668631
}
669632

670633
void reset()
671634
{
672-
if (is_set) {
673-
is_set = false;
674-
reinterpret_cast<T*>(&storage)->~T();
675-
//std::fill_n(reinterpret_cast<char*>(&storage), sizeof(T), 0);
676-
}
635+
val_.reset();
677636
}
678637

679-
template<class U>
638+
template<class U = T>
680639
void reset(U&& value) {
681-
reset();
682-
new (reinterpret_cast<T*>(&storage)) T(std::forward<U>(value));
683-
is_set = true;
640+
*this = std::forward<U>(value);
684641
}
685642

686-
maybe& operator=(const T& other) {
687-
reset(other);
643+
maybe& operator=(const maybe& other) = default;
644+
maybe& operator=(maybe&& other) = default;
645+
646+
maybe& operator=(const T& value) {
647+
val_ = value;
688648
return *this;
689649
}
690-
maybe& operator=(const maybe& other) {
691-
if (!other.empty()) {
692-
reset(other.get());
693-
} else {
694-
reset();
695-
}
650+
651+
maybe& operator=(T&& value) {
652+
val_ = std::move(value);
696653
return *this;
697654
}
698655
};

0 commit comments

Comments
 (0)