1 #include <type_traits> 2 #include <utility> 3 4 #if REVISION == 0 5 // Pre-a3942b3 layout. 6 #define NO_REMOVE_CV 7 #endif 8 // REVISION == 1: current layout 9 10 namespace std { 11 namespace __lldb { 12 13 struct in_place_t { 14 explicit in_place_t() = default; 15 }; 16 constexpr in_place_t in_place{}; 17 18 template <class _Tp, bool = is_trivially_destructible<_Tp>::value> 19 struct __optional_destruct_base { 20 typedef _Tp value_type; 21 union { 22 char __null_state_; 23 #ifdef NO_REMOVE_CV 24 value_type __val_; 25 #else // !NO_REMOVE_CV 26 remove_cv_t<value_type> __val_; 27 #endif 28 }; 29 bool __engaged_; 30 31 template <class... _Args> 32 constexpr explicit __optional_destruct_base(in_place_t, _Args &&...__args) 33 : __val_(std::forward<_Args>(__args)...), __engaged_(true) {} 34 }; 35 36 template <class _Tp, bool = is_reference<_Tp>::value> 37 struct __optional_storage_base : __optional_destruct_base<_Tp> { 38 using __base = __optional_destruct_base<_Tp>; 39 using value_type = _Tp; 40 using __base::__base; 41 }; 42 43 template <class _Tp, bool = is_trivially_copy_constructible<_Tp>::value> 44 struct __optional_copy_base : __optional_storage_base<_Tp> { 45 using __optional_storage_base<_Tp>::__optional_storage_base; 46 }; 47 48 template <class _Tp, bool = is_trivially_move_constructible<_Tp>::value> 49 struct __optional_move_base : __optional_copy_base<_Tp> { 50 using __optional_copy_base<_Tp>::__optional_copy_base; 51 }; 52 53 template <class _Tp, bool = is_trivially_destructible<_Tp>::value && 54 is_trivially_copy_constructible<_Tp>::value && 55 is_trivially_copy_assignable<_Tp>::value> 56 struct __optional_copy_assign_base : __optional_move_base<_Tp> { 57 using __optional_move_base<_Tp>::__optional_move_base; 58 }; 59 60 template <class _Tp, bool = is_trivially_destructible<_Tp>::value && 61 is_trivially_move_constructible<_Tp>::value && 62 is_trivially_move_assignable<_Tp>::value> 63 struct __optional_move_assign_base : __optional_copy_assign_base<_Tp> { 64 using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base; 65 }; 66 67 template <bool _CanCopy, bool _CanMove> struct __sfinae_ctor_base {}; 68 69 template <class _Tp> 70 using __optional_sfinae_ctor_base_t = 71 __sfinae_ctor_base<is_copy_constructible<_Tp>::value, 72 is_move_constructible<_Tp>::value>; 73 74 template <bool _CanCopy, bool _CanMove> struct __sfinae_assign_base {}; 75 76 template <class _Tp> 77 using __optional_sfinae_assign_base_t = __sfinae_assign_base< 78 (is_copy_constructible<_Tp>::value && is_copy_assignable<_Tp>::value), 79 (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value)>; 80 81 template <class _Tp> 82 class optional : private __optional_move_assign_base<_Tp>, 83 private __optional_sfinae_ctor_base_t<_Tp>, 84 private __optional_sfinae_assign_base_t<_Tp> { 85 using __base = __optional_move_assign_base<_Tp>; 86 87 public: 88 using value_type = _Tp; 89 90 public: 91 template <class _Up = value_type> 92 constexpr explicit optional(_Up &&__v) 93 : __base(in_place, std::forward<_Up>(__v)) {} 94 }; 95 96 } // namespace __lldb 97 } // namespace std 98 99 int main() { 100 std::__lldb::optional<char const *> maybe_string{"Hello"}; 101 std::__lldb::optional<int> maybe_int{42}; 102 return 0; // Break here 103 } 104