@@ -46,7 +46,7 @@ template<typename T> class name_or_other
46
46
47
47
#line 12 "pure2-union.cpp2"
48
48
public: [[nodiscard]] auto to_string () const & -> std::string;
49
-
49
+
50
50
private: std::aligned_storage_t <cpp2::max(sizeof (std::string), sizeof (T))> _storage {}; private: cpp2::i8 _discriminator {-1 }; public: [[nodiscard]] auto is_name () const & -> bool;
51
51
public: [[nodiscard]] auto name () const & -> std::string const &;
52
52
public: [[nodiscard]] auto name () & -> std::string&;
@@ -63,15 +63,13 @@ public: ~name_or_other() noexcept;
63
63
public: name_or_other() = default ;
64
64
public: name_or_other(name_or_other const &) = delete ; /* No 'that' constructor, suppress copy */
65
65
public: auto operator =(name_or_other const &) -> void = delete ;
66
-
67
-
68
- #line 16 "pure2-union.cpp2"
66
+ #line 17 "pure2-union.cpp2"
69
67
};
70
68
71
69
auto print_name (cpp2::in<name_or_number> non) -> void;
72
70
73
71
74
- #line 27 "pure2-union.cpp2"
72
+ #line 28 "pure2-union.cpp2"
75
73
auto main () -> int;
76
74
77
75
@@ -102,8 +100,9 @@ auto name_or_number::destroy() & -> void{
102
100
name_or_number::~name_or_number () noexcept {destroy ();}
103
101
#line 12 "pure2-union.cpp2"
104
102
template <typename T> [[nodiscard]] auto name_or_other<T>::to_string() const & -> std::string{
105
- if (is_name ()) {return name (); }
106
- else { return cpp2::as_<std::string>(other ()); }
103
+ if (is_name ()) { return name (); }
104
+ else {if (is_other ()) {return cpp2::as_<std::string>(other ()); }
105
+ else { return " invalid value" ; }}
107
106
}
108
107
109
108
@@ -130,7 +129,7 @@ template <typename T> auto name_or_other<T>::destroy() & -> void{
130
129
131
130
template <typename T> name_or_other<T>::~name_or_other () noexcept {destroy ();}
132
131
133
- #line 18 "pure2-union.cpp2"
132
+ #line 19 "pure2-union.cpp2"
134
133
auto print_name (cpp2::in<name_or_number> non) -> void{
135
134
if (CPP2_UFCS_0 (is_name, non)) {
136
135
std::cout << CPP2_UFCS_0 (name, non) << " \n " ;
0 commit comments