diff --git a/optional.hpp b/optional.hpp index e11f9ba..4a8230b 100644 --- a/optional.hpp +++ b/optional.hpp @@ -17,38 +17,40 @@ #include namespace tl { - template using remove_cv_t = typename std::remove_cv::type; - template using remove_const_t = typename std::remove_const::type; - template using remove_volatile_t = typename std::remove_volatile::type; - template using add_cv_t = typename std::add_cv::type; - template using add_const_t = typename std::add_const::type; - template using add_volatile_t = typename std::add_volatile::type; - template using remove_reference_t = typename std::remove_reference::type; - template using add_lvalue_reference_t = typename std::add_lvalue_reference::type; - template using add_rvalue_reference_t = typename std::add_rvalue_reference::type; - template using remove_pointer_t = typename std::remove_pointer::type; - template using add_pointer_t = typename std::add_pointer::type; - template using make_signed_t = typename std::make_signed::type; - template using make_unsigned_t = typename std::make_unsigned::type; - template using remove_extent_t = typename std::remove_extent::type; - template using remove_all_extents_t = typename std::remove_all_extents::type; - template using aligned_storage_t = typename std::aligned_storage::type; - template using aligned_union_t = typename std::aligned_union::type; - template using decay_t = typename std::decay::type; - template using enable_if_t = typename std::enable_if::type; - template using conditional_t = typename std::conditional::type; - template using common_type_t = typename std::common_type::type; - template using underlying_type_t = typename std::underlying_type::type; - template using result_of_t = typename std::result_of::type; + namespace detail { + template using remove_cv_t = typename std::remove_cv::type; + template using remove_const_t = typename std::remove_const::type; + template using remove_volatile_t = typename std::remove_volatile::type; + template using add_cv_t = typename std::add_cv::type; + template using add_const_t = typename std::add_const::type; + template using add_volatile_t = typename std::add_volatile::type; + template using remove_reference_t = typename std::remove_reference::type; + template using add_lvalue_reference_t = typename std::add_lvalue_reference::type; + template using add_rvalue_reference_t = typename std::add_rvalue_reference::type; + template using remove_pointer_t = typename std::remove_pointer::type; + template using add_pointer_t = typename std::add_pointer::type; + template using make_signed_t = typename std::make_signed::type; + template using make_unsigned_t = typename std::make_unsigned::type; + template using remove_extent_t = typename std::remove_extent::type; + template using remove_all_extents_t = typename std::remove_all_extents::type; + template using aligned_storage_t = typename std::aligned_storage::type; + template using aligned_union_t = typename std::aligned_union::type; + template using decay_t = typename std::decay::type; + template using enable_if_t = typename std::enable_if::type; + template using conditional_t = typename std::conditional::type; + template using common_type_t = typename std::common_type::type; + template using underlying_type_t = typename std::underlying_type::type; + template using result_of_t = typename std::result_of::type; - template struct conjunction : std::true_type { }; - template struct conjunction : B { }; - template - struct conjunction - : std::conditional, B>::type {}; + template struct conjunction : std::true_type { }; + template struct conjunction : B { }; + template + struct conjunction + : std::conditional, B>::type {}; - template struct voider { using type = void; }; - template using void_t = typename voider::type; + template struct voider { using type = void; }; + template using void_t = typename voider::type; + } struct in_place_t { explicit in_place_t() = default; @@ -61,14 +63,14 @@ namespace tl { namespace detail { template - using enable_forward_value = enable_if_t< + using enable_forward_value = detail::enable_if_t< std::is_constructible::value && - !std::is_same, in_place_t>::value && - !std::is_same, tl::decay_t>::value + !std::is_same, in_place_t>::value && + !std::is_same, detail::decay_t>::value >; template - using enable_from_other = enable_if_t< + using enable_from_other = detail::enable_if_t< std::is_constructible::value && !std::is_constructible&>::value && !std::is_constructible&&>::value && @@ -81,15 +83,15 @@ namespace tl { >; template - using enable_assign_forward = enable_if_t< - !std::is_same, tl::decay_t>::value && - !tl::conjunction, std::is_same>>::value && + using enable_assign_forward = detail::enable_if_t< + !std::is_same, detail::decay_t>::value && + !detail::conjunction, std::is_same>>::value && std::is_constructible::value && std::is_assignable::value >; template - using enable_assign_from_other = enable_if_t< + using enable_assign_from_other = detail::enable_if_t< std::is_constructible::value && std::is_assignable::value && !std::is_constructible&>::value && @@ -243,15 +245,15 @@ namespace tl { // [optional.specalg], specialized algorithms - template ::value>* = nullptr, - enable_if_t::value>* = nullptr> + template ::value>* = nullptr, + detail::enable_if_t::value>* = nullptr> void swap(optional& lhs, optional& rhs) noexcept(noexcept(lhs.swap(rhs))) { return lhs.swap(rhs); } template - inline constexpr optional> make_optional(T&& v) { - return optional>(std::forward(v)); + inline constexpr optional> make_optional(T&& v) { + return optional>(std::forward(v)); } template inline constexpr optional make_optional(Args&&... args) { @@ -272,7 +274,7 @@ namespace std { if (!o.has_value()) return 0; - return hash>()(*o); + return hash>()(*o); } }; } @@ -350,41 +352,41 @@ namespace tl { } } template - constexpr explicit optional(enable_if_t::value, in_place_t>, + constexpr explicit optional(detail::enable_if_t::value, in_place_t>, Args&&... args) : base(in_place, std::forward(args)...) {} template constexpr explicit optional( - enable_if_t&, Args&&...>::value, in_place_t>, + detail::enable_if_t&, Args&&...>::value, in_place_t>, std::initializer_list il, Args&&... args) { this->m_has_value = true; new (std::addressof(this->m_value)) T (il, std::forward(args)...); } - template ::value>* = nullptr, + template ::value>* = nullptr, detail::enable_forward_value* = nullptr> constexpr optional(U&& u) : base(in_place, std::forward(u)) {} - template ::value>* = nullptr, + template ::value>* = nullptr, detail::enable_forward_value* = nullptr> constexpr explicit optional(U&& u) : base(in_place, std::forward(u)) {} template * = nullptr, - enable_if_t::value>* = nullptr> + detail::enable_if_t::value>* = nullptr> optional(const optional& rhs) { this->m_has_value = true; new (std::addressof(this->m_value)) T (*rhs); } template * = nullptr, - enable_if_t::value>* = nullptr> + detail::enable_if_t::value>* = nullptr> optional(const optional& rhs) { this->m_has_value = true; new (std::addressof(this->m_value)) T (*rhs); } template * = nullptr, - enable_if_t::value>* = nullptr> + detail::enable_if_t::value>* = nullptr> optional(optional&& rhs) { this->m_has_value = true; new (std::addressof(this->m_value)) T (std::move(*rhs)); @@ -392,7 +394,7 @@ namespace tl { template * = nullptr, - enable_if_t::value>* = nullptr> + detail::enable_if_t::value>* = nullptr> explicit optional(optional&& rhs) { this->m_has_value = true; new (std::addressof(this->m_value)) T (std::move(*rhs)); @@ -506,7 +508,7 @@ namespace tl { } template - enable_if_t&, Args&&...>::value, T&> + detail::enable_if_t&, Args&&...>::value, T&> emplace(std::initializer_list il, Args&&... args) { *this = nullopt; new (std::addressof(this->m_value)) T(il, std::forward(args)...);