-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,11 +32,12 @@ public: auto set_num(cpp2::in<cpp2::i32> _value) & -> void; | |
public: auto set_num(auto&& ..._args) & -> void; | ||
private: auto _destroy() & -> void; | ||
public: ~name_or_number() noexcept; | ||
public: explicit name_or_number(); | ||
public: name_or_number(name_or_number const& that); | ||
|
||
public: name_or_number() = default; | ||
public: name_or_number(name_or_number const&) = delete; /* No 'that' constructor, suppress copy */ | ||
public: auto operator=(name_or_number const&) -> void = delete; | ||
|
||
public: auto operator=(name_or_number const& that) -> name_or_number& ; | ||
public: name_or_number(name_or_number&& that) noexcept; | ||
public: auto operator=(name_or_number&& that) noexcept -> name_or_number& ; | ||
|
||
#line 5 "pure2-union.cpp2" | ||
}; | ||
|
@@ -59,10 +60,12 @@ public: auto set_other(cpp2::in<T> _value) & -> void; | |
public: auto set_other(auto&& ..._args) & -> void; | ||
private: auto _destroy() & -> void; | ||
public: ~name_or_other() noexcept; | ||
public: explicit name_or_other(); | ||
public: name_or_other(name_or_other const& that); | ||
public: auto operator=(name_or_other const& that) -> name_or_other& ; | ||
public: name_or_other(name_or_other&& that) noexcept; | ||
public: auto operator=(name_or_other&& that) noexcept -> name_or_other& ; | ||
|
||
public: name_or_other() = default; | ||
public: name_or_other(name_or_other const&) = delete; /* No 'that' constructor, suppress copy */ | ||
public: auto operator=(name_or_other const&) -> void = delete; | ||
#line 17 "pure2-union.cpp2" | ||
}; | ||
|
||
|
@@ -98,6 +101,41 @@ auto name_or_number::_destroy() & -> void{ | |
} | ||
|
||
name_or_number::~name_or_number() noexcept{_destroy();} | ||
name_or_number::name_or_number() | ||
: _discriminator{ -1 }{} | ||
name_or_number::name_or_number(name_or_number const& that) | ||
: _storage{ that._storage } | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gregmarr
Contributor
|
||
, _discriminator{ that._discriminator }{ | ||
if (CPP2_UFCS_0(is_name, that)) {set_name(CPP2_UFCS_0(name, that));} | ||
if (CPP2_UFCS_0(is_num, that)) {set_num(CPP2_UFCS_0(num, that));} | ||
_discriminator = that._discriminator; | ||
} | ||
|
||
auto name_or_number::operator=(name_or_number const& that) -> name_or_number& { | ||
_storage = that._storage; | ||
_discriminator = that._discriminator; | ||
if (CPP2_UFCS_0(is_name, that)) {set_name(CPP2_UFCS_0(name, that));} | ||
if (CPP2_UFCS_0(is_num, that)) {set_num(CPP2_UFCS_0(num, that));} | ||
_discriminator = that._discriminator; | ||
return *this; | ||
} | ||
|
||
name_or_number::name_or_number(name_or_number&& that) noexcept | ||
: _storage{ std::move(that)._storage } | ||
, _discriminator{ std::move(that)._discriminator }{ | ||
if (CPP2_UFCS_0(is_name, std::move(that))) {set_name(CPP2_UFCS_0(name, std::move(that)));} | ||
if (CPP2_UFCS_0(is_num, std::move(that))) {set_num(CPP2_UFCS_0(num, std::move(that)));} | ||
_discriminator = std::move(that)._discriminator; | ||
} | ||
|
||
auto name_or_number::operator=(name_or_number&& that) noexcept -> name_or_number& { | ||
_storage = std::move(that)._storage; | ||
_discriminator = std::move(that)._discriminator; | ||
if (CPP2_UFCS_0(is_name, std::move(that))) {set_name(CPP2_UFCS_0(name, std::move(that)));} | ||
if (CPP2_UFCS_0(is_num, std::move(that))) {set_num(CPP2_UFCS_0(num, std::move(that)));} | ||
_discriminator = std::move(that)._discriminator; | ||
return *this; | ||
} | ||
#line 12 "pure2-union.cpp2" | ||
template <typename T> [[nodiscard]] auto name_or_other<T>::to_string() const& -> std::string{ | ||
if (is_name()) { return name(); } | ||
|
@@ -128,7 +166,42 @@ template <typename T> auto name_or_other<T>::_destroy() & -> void{ | |
} | ||
|
||
template <typename T> name_or_other<T>::~name_or_other() noexcept{_destroy();} | ||
template <typename T> name_or_other<T>::name_or_other() | ||
: _discriminator{ -1 }{} | ||
template <typename T> name_or_other<T>::name_or_other(name_or_other const& that) | ||
: _storage{ that._storage } | ||
, _discriminator{ that._discriminator }{ | ||
if (CPP2_UFCS_0(is_name, that)) {set_name(CPP2_UFCS_0(name, that));} | ||
if (CPP2_UFCS_0(is_other, that)) {set_other(CPP2_UFCS_0(other, that));} | ||
_discriminator = that._discriminator; | ||
} | ||
|
||
|
||
template <typename T> auto name_or_other<T>::operator=(name_or_other const& that) -> name_or_other& { | ||
_storage = that._storage; | ||
_discriminator = that._discriminator; | ||
if (CPP2_UFCS_0(is_name, that)) {set_name(CPP2_UFCS_0(name, that));} | ||
if (CPP2_UFCS_0(is_other, that)) {set_other(CPP2_UFCS_0(other, that));} | ||
_discriminator = that._discriminator; | ||
return *this; | ||
} | ||
|
||
template <typename T> name_or_other<T>::name_or_other(name_or_other&& that) noexcept | ||
: _storage{ std::move(that)._storage } | ||
, _discriminator{ std::move(that)._discriminator }{ | ||
if (CPP2_UFCS_0(is_name, std::move(that))) {set_name(CPP2_UFCS_0(name, std::move(that)));} | ||
if (CPP2_UFCS_0(is_other, std::move(that))) {set_other(CPP2_UFCS_0(other, std::move(that)));} | ||
_discriminator = std::move(that)._discriminator; | ||
} | ||
|
||
template <typename T> auto name_or_other<T>::operator=(name_or_other&& that) noexcept -> name_or_other& { | ||
_storage = std::move(that)._storage; | ||
_discriminator = std::move(that)._discriminator; | ||
if (CPP2_UFCS_0(is_name, std::move(that))) {set_name(CPP2_UFCS_0(name, std::move(that)));} | ||
if (CPP2_UFCS_0(is_other, std::move(that))) {set_other(CPP2_UFCS_0(other, std::move(that)));} | ||
_discriminator = std::move(that)._discriminator; | ||
return *this; | ||
} | ||
#line 19 "pure2-union.cpp2" | ||
auto print_name(cpp2::in<name_or_number> non) -> void{ | ||
if (CPP2_UFCS_0(is_name, non)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1191,6 +1191,22 @@ union: (inout t : meta::type_declaration) | |
|
||
// Add the destructor | ||
t.add_member( " operator=: (move this) = { _destroy(); } " ); | ||
|
||
// Add default constructor | ||
t.add_member( " operator=: (out this) = { _discriminator = -1; } " ); | ||
|
||
// Add value-set | ||
(copy value_set: std::string = " operator=: (out this, that) = {\n") | ||
{ | ||
for alternatives | ||
do (a) { | ||
value_set += " if that.is_(a.name)$() { set_(a.name)$( that.(a.name)$() ); }\n"; | ||
} | ||
|
||
value_set += " _discriminator = that._discriminator;\n"; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gregmarr
Contributor
|
||
value_set += " }\n"; | ||
t.add_member( value_set ); | ||
} | ||
} | ||
|
||
|
||
|
Now there's a redundant initialization/assignment of
_storage
.