2019-05-02 Jonathan Wakely <jwakely@redhat.com>
+ * include/experimental/bits/lfts_config.h: Improve doc markup.
+ * include/experimental/optional: Improve docs.
+ (_Has_addressof_mem, _Has_addressof_free, _Has_addressof)
+ (__constexpr_addressof): Remove.
+ (optional::operator->()): Use std::__addressof().
+ * include/std/optional (optional::operator->()): Adjust whitespace.
+ * testsuite/experimental/optional/constexpr/observers/2.cc: Check
+ that operator-> is still constexpr with overloaded operator&. Change
+ to compile-only test.
+ * testsuite/experimental/optional/constexpr/observers/3.cc: Change to
+ compile-only test.
+
* include/bits/shared_ptr.h: Improve docs.
* include/bits/shared_ptr_atomic.h: Likewise.
* include/bits/unique_ptr.h: Likewise. Adjust whitespace.
virtual ~bad_optional_access() noexcept = default;
};
+ /// @cond undocumented
+
void
__throw_bad_optional_access(const char*)
__attribute__((__noreturn__));
__throw_bad_optional_access(const char* __s)
{ _GLIBCXX_THROW_OR_ABORT(bad_optional_access(__s)); }
-#ifndef __cpp_lib_addressof_constexpr
- template<typename _Tp, typename = void>
- struct _Has_addressof_mem : std::false_type { };
-
- template<typename _Tp>
- struct _Has_addressof_mem<_Tp,
- __void_t<decltype( std::declval<const _Tp&>().operator&() )>
- >
- : std::true_type { };
-
- template<typename _Tp, typename = void>
- struct _Has_addressof_free : std::false_type { };
-
- template<typename _Tp>
- struct _Has_addressof_free<_Tp,
- __void_t<decltype( operator&(std::declval<const _Tp&>()) )>
- >
- : std::true_type { };
-
- /**
- * @brief Trait that detects the presence of an overloaded unary operator&.
- *
- * Practically speaking this detects the presence of such an operator when
- * called on a const-qualified lvalue (e.g.
- * declval<const _Tp&>().operator&()).
- */
- template<typename _Tp>
- struct _Has_addressof
- : std::__or_<_Has_addressof_mem<_Tp>, _Has_addressof_free<_Tp>>::type
- { };
-
- /**
- * @brief An overload that attempts to take the address of an lvalue as a
- * constant expression. Falls back to __addressof in the presence of an
- * overloaded addressof operator (unary operator&), in which case the call
- * will not be a constant expression.
- */
- template<typename _Tp>
- constexpr
- enable_if_t<!_Has_addressof<_Tp>::value, _Tp*>
- __constexpr_addressof(_Tp& __t)
- { return &__t; }
-
- /**
- * @brief Fallback overload that defers to __addressof.
- */
- template<typename _Tp>
- inline
- enable_if_t<_Has_addressof<_Tp>::value, _Tp*>
- __constexpr_addressof(_Tp& __t)
- { return std::__addressof(__t); }
-#endif // __cpp_lib_addressof_constexpr
-
/**
* @brief Class template that holds the necessary state for @ref optional
* and that has the responsibility for construction and the special members.
bool _M_engaged = false;
};
- template<typename _Tp>
- class optional;
-
template<typename _Tp, typename _Up>
using __converts_from_optional =
__or_<is_constructible<_Tp, const optional<_Up>&>,
is_assignable<_Tp&, const optional<_Up>&&>,
is_assignable<_Tp&, optional<_Up>&&>>;
+ /// @endcond
+
/**
* @brief Class template for optional values.
*/
// [X.Y.4.5] Observers.
constexpr const _Tp*
operator->() const
- {
-#ifndef __cpp_lib_addressof_constexpr
- return __constexpr_addressof(this->_M_get());
-#else
- return std::__addressof(this->_M_get());
-#endif
- }
+ { return std::__addressof(this->_M_get()); }
_Tp*
operator->()
}
};
+ /// @relates experimental::optional @{
+
// [X.Y.8] Comparisons between optional values.
template<typename _Tp>
constexpr bool
make_optional(_Tp&& __t)
{ return optional<decay_t<_Tp>> { std::forward<_Tp>(__t) }; }
+ // @} relates experimental::optional
// @} group optional
} // namespace fundamentals_v1
} // namespace experimental
// [X.Y.12]
+ /// std::hash partial specialization for experimental::optional
+ /// @relates experimental::optional
template<typename _Tp>
struct hash<experimental::optional<_Tp>>
{