@@ -1360,7 +1360,7 @@ auto basic_enum(
13601360 std::vector<value_member_info> enumerators {};
13611361 cpp2::i64 min_value {};
13621362 cpp2::i64 max_value {};
1363- std::string underlying_type {} ;
1363+ cpp2::deferred_init< std::string> underlying_type;
13641364
13651365 CPP2_UFCS (reserve_names)(t, " operator=" , " operator<=>" );
13661366 if (bitwise) {
@@ -1369,7 +1369,7 @@ auto basic_enum(
13691369
13701370 // 1. Gather: The names of all the user-written members, and find/compute the type
13711371
1372- underlying_type = CPP2_UFCS (get_argument)(t, 0 );// use the first template argument, if there was one
1372+ underlying_type. construct ( CPP2_UFCS (get_argument)(t, 0 ) );// use the first template argument, if there was one
13731373
13741374 auto found_non_numeric {false };
13751375{
@@ -1415,23 +1415,23 @@ std::string value = "-1";
14151415
14161416 // Compute the default underlying type, if it wasn't explicitly specified
14171417#line 913 "reflect.h2"
1418- if (underlying_type == " " )
1418+ if (underlying_type. value () == " " )
14191419 {
14201420 CPP2_UFCS (require)(t, !(std::move (found_non_numeric)),
14211421 " if you write an enumerator with a non-numeric-literal value, you must specify the enumeration's underlying type" );
14221422
14231423 if (!(bitwise)) {
14241424 if (cpp2::cmp_greater_eq (min_value,std::numeric_limits<cpp2::i8 >::min ()) && cpp2::cmp_less_eq (max_value,std::numeric_limits<cpp2::i8 >::max ())) {
1425- underlying_type = " i8" ;
1425+ underlying_type. value () = " i8" ;
14261426 }
14271427 else {if (cpp2::cmp_greater_eq (min_value,std::numeric_limits<cpp2::i16 >::min ()) && cpp2::cmp_less_eq (max_value,std::numeric_limits<cpp2::i16 >::max ())) {
1428- underlying_type = " i16" ;
1428+ underlying_type. value () = " i16" ;
14291429 }
14301430 else {if (cpp2::cmp_greater_eq (min_value,std::numeric_limits<cpp2::i32 >::min ()) && cpp2::cmp_less_eq (max_value,std::numeric_limits<cpp2::i32 >::max ())) {
1431- underlying_type = " i32" ;
1431+ underlying_type. value () = " i32" ;
14321432 }
14331433 else {if (cpp2::cmp_greater_eq (std::move (min_value),std::numeric_limits<cpp2::i64 >::min ()) && cpp2::cmp_less_eq (std::move (max_value),std::numeric_limits<cpp2::i64 >::max ())) {
1434- underlying_type = " i64" ;
1434+ underlying_type. value () = " i64" ;
14351435 }
14361436 else {
14371437 CPP2_UFCS (error)(t, " values are outside the range representable by the largest supported underlying signed type (i64)" );
@@ -1440,16 +1440,16 @@ std::string value = "-1";
14401440 else {
14411441 auto umax {std::move (max_value) * cpp2::as_<cpp2::u64 , 2 >()};
14421442 if (cpp2::cmp_less_eq (umax,std::numeric_limits<cpp2::u8 >::max ())) {
1443- underlying_type = " u8" ;
1443+ underlying_type. value () = " u8" ;
14441444 }
14451445 else {if (cpp2::cmp_less_eq (umax,std::numeric_limits<cpp2::u16 >::max ())) {
1446- underlying_type = " u16" ;
1446+ underlying_type. value () = " u16" ;
14471447 }
14481448 else {if (cpp2::cmp_less_eq (std::move (umax),std::numeric_limits<cpp2::u32 >::max ())) {
1449- underlying_type = " u32" ;
1449+ underlying_type. value () = " u32" ;
14501450 }
14511451 else {
1452- underlying_type = " u64" ;
1452+ underlying_type. value () = " u64" ;
14531453 }}}
14541454 }
14551455 }
@@ -1462,9 +1462,9 @@ std::string value = "-1";
14621462 CPP2_UFCS (remove_marked_members)(t);
14631463
14641464 // Generate all the common material: value and common functions
1465- CPP2_UFCS (add_member)(t, " _value : " + cpp2::to_string (underlying_type) + " ;" );
1466- CPP2_UFCS (add_member)(t, " private operator= : (implicit out this, _val: i64) == _value = cpp2::unsafe_narrow<" + cpp2::to_string (underlying_type) + " >(_val);" );
1467- CPP2_UFCS (add_member)(t, " get_raw_value : (this) -> " + cpp2::to_string (std::move (underlying_type)) + " == _value;" );
1465+ CPP2_UFCS (add_member)(t, " _value : " + cpp2::to_string (underlying_type. value () ) + " ;" );
1466+ CPP2_UFCS (add_member)(t, " private operator= : (implicit out this, _val: i64) == _value = cpp2::unsafe_narrow<" + cpp2::to_string (underlying_type. value () ) + " >(_val);" );
1467+ CPP2_UFCS (add_member)(t, " get_raw_value : (this) -> " + cpp2::to_string (std::move (underlying_type. value () )) + " == _value;" );
14681468 CPP2_UFCS (add_member)(t, " operator= : (out this, that) == { }" );
14691469 CPP2_UFCS (add_member)(t, " operator<=> : (this, that) -> std::strong_ordering;" );
14701470
0 commit comments