@@ -46,7 +46,7 @@ template<typename T> class name_or_other
4646
4747#line 12 "pure2-union.cpp2"
4848 public: [[nodiscard]] auto to_string () const & -> std::string;
49-
49+
5050 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;
5151public: [[nodiscard]] auto name () const & -> std::string const &;
5252public: [[nodiscard]] auto name () & -> std::string&;
@@ -63,15 +63,13 @@ public: ~name_or_other() noexcept;
6363 public: name_or_other() = default ;
6464 public: name_or_other(name_or_other const &) = delete ; /* No 'that' constructor, suppress copy */
6565 public: auto operator =(name_or_other const &) -> void = delete ;
66-
67-
68- #line 16 "pure2-union.cpp2"
66+ #line 17 "pure2-union.cpp2"
6967};
7068
7169auto print_name (cpp2::in<name_or_number> non) -> void;
7270
7371
74- #line 27 "pure2-union.cpp2"
72+ #line 28 "pure2-union.cpp2"
7573auto main () -> int;
7674
7775
@@ -102,8 +100,9 @@ auto name_or_number::destroy() & -> void{
102100 name_or_number::~name_or_number () noexcept {destroy ();}
103101#line 12 "pure2-union.cpp2"
104102 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" ; }}
107106 }
108107
109108
@@ -130,7 +129,7 @@ template <typename T> auto name_or_other<T>::destroy() & -> void{
130129
131130 template <typename T> name_or_other<T>::~name_or_other () noexcept {destroy ();}
132131
133- #line 18 "pure2-union.cpp2"
132+ #line 19 "pure2-union.cpp2"
134133auto print_name (cpp2::in<name_or_number> non) -> void{
135134 if (CPP2_UFCS_0 (is_name, non)) {
136135 std::cout << CPP2_UFCS_0 (name, non) << " \n " ;
0 commit comments