Clang format

This commit is contained in:
Simon Brand
2017-11-03 14:29:02 +00:00
parent 59cf950873
commit f6802daada

View File

@@ -171,8 +171,8 @@ template <class T, class... U>
using disable_if_ret_void = enable_if_t<!returns_void<T &&, U...>::value>; using disable_if_ret_void = enable_if_t<!returns_void<T &&, U...>::value>;
template <class T, class U> template <class T, class U>
using enable_forward_value = using enable_forward_value = detail::enable_if_t<
detail::enable_if_t<std::is_constructible<T, U &&>::value && std::is_constructible<T, U &&>::value &&
!std::is_same<detail::decay_t<U>, in_place_t>::value && !std::is_same<detail::decay_t<U>, in_place_t>::value &&
!std::is_same<optional<T>, detail::decay_t<U>>::value>; !std::is_same<optional<T>, detail::decay_t<U>>::value>;
@@ -216,7 +216,8 @@ using enable_assign_from_other = detail::enable_if_t<
// TODO make a version which works with MSVC // TODO make a version which works with MSVC
template <class T, class U = T> struct is_swappable : std::true_type {}; template <class T, class U = T> struct is_swappable : std::true_type {};
template <class T, class U = T> struct is_nothrow_swappable : std::true_type {}; template <class T, class U = T>
struct is_nothrow_swappable : std::true_type {};
#else #else
// https://stackoverflow.com/questions/26744589/what-is-a-proper-way-to-implement-is-swappable-to-test-for-the-swappable-concept // https://stackoverflow.com/questions/26744589/what-is-a-proper-way-to-implement-is-swappable-to-test-for-the-swappable-concept
namespace swap_adl_tests { namespace swap_adl_tests {
@@ -285,8 +286,9 @@ struct is_nothrow_swappable
}; };
#endif #endif
// The storage base manages the actual storage, and correctly propagates trivial // The storage base manages the actual storage, and correctly propagates
// destruction from T This case is for when T is trivially destructible // trivial destruction from T This case is for when T is trivially
// destructible
template <class T, bool = ::std::is_trivially_destructible<T>::value> template <class T, bool = ::std::is_trivially_destructible<T>::value>
struct optional_storage_base { struct optional_storage_base {
TL_OPTIONAL_11_CONSTEXPR optional_storage_base() noexcept TL_OPTIONAL_11_CONSTEXPR optional_storage_base() noexcept
@@ -334,7 +336,8 @@ template <class T> struct optional_storage_base<T, true> {
// This base class provides some handy member functions which can be used in // This base class provides some handy member functions which can be used in
// further derived classes // further derived classes
template <class T> struct optional_operations_base : optional_storage_base<T> { template <class T>
struct optional_operations_base : optional_storage_base<T> {
using optional_storage_base<T>::optional_storage_base; using optional_storage_base<T>::optional_storage_base;
void hard_reset() noexcept { void hard_reset() noexcept {
@@ -411,7 +414,8 @@ struct optional_move_base : optional_copy_base<T> {
#else #else
template <class T, bool = false> struct optional_move_base; template <class T, bool = false> struct optional_move_base;
#endif #endif
template <class T> struct optional_move_base<T, false> : optional_copy_base<T> { template <class T>
struct optional_move_base<T, false> : optional_copy_base<T> {
using optional_copy_base<T>::optional_copy_base; using optional_copy_base<T>::optional_copy_base;
optional_move_base() = default; optional_move_base() = default;
@@ -608,12 +612,12 @@ public:
const char *what() const noexcept { return "Optional has no value"; } const char *what() const noexcept { return "Optional has no value"; }
}; };
/// An optional object is an object that contains the storage for another object /// An optional object is an object that contains the storage for another
/// and manages the lifetime of this contained object, if any. The contained /// object and manages the lifetime of this contained object, if any. The
/// object may be initialized after the optional object has been initialized, /// contained object may be initialized after the optional object has been
/// and may be destroyed before the optional object has been destroyed. The /// initialized, and may be destroyed before the optional object has been
/// initialization state of the contained object is tracked by the optional /// destroyed. The initialization state of the contained object is tracked by
/// object. /// the optional object.
template <class T> template <class T>
class optional : private detail::optional_move_assign_base<T>, class optional : private detail::optional_move_assign_base<T>,
private detail::optional_delete_ctor_base<T>, private detail::optional_delete_ctor_base<T>,
@@ -628,11 +632,10 @@ public:
#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \ #if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \
!defined(TL_EXPECTED_GCC54) !defined(TL_EXPECTED_GCC54)
/// \group and_then /// \group and_then
/// Carries out some operation which returns an optional on the stored object /// Carries out some operation which returns an optional on the stored
/// if there is one. /// object if there is one. \requires `std::invoke(std::forward<F>(f),
/// \requires `std::invoke(std::forward<F>(f), value())` /// value())` returns a `std::optional<U>` for some `U`. \returns Let `U` be
/// returns a `std::optional<U>` for some `U`. \returns Let `U` be the result /// the result of `std::invoke(std::forward<F>(f), value())`. Returns a
/// of `std::invoke(std::forward<F>(f), value())`. Returns a
/// `std::optional<U>`. The return value is empty if `*this` is empty, /// `std::optional<U>`. The return value is empty if `*this` is empty,
/// otherwise the return value of `std::invoke(std::forward<F>(f), value())` /// otherwise the return value of `std::invoke(std::forward<F>(f), value())`
/// is returned. /// is returned.
@@ -928,8 +931,8 @@ public:
} }
#endif #endif
/// \brief Maps the stored value with `f` if there is one, otherwise calls `u` /// \brief Maps the stored value with `f` if there is one, otherwise calls
/// and returns the result. /// `u` and returns the result.
/// ///
/// \details If there is a value stored, then `f` is /// \details If there is a value stored, then `f` is
/// called with `**this` and the value is returned. Otherwise /// called with `**this` and the value is returned. Otherwise
@@ -944,7 +947,8 @@ public:
} }
/// \group map_or_else /// \group map_or_else
/// \synopsis template <class F, class U>\nauto map_or_else(F &&f, U &&u) &&; /// \synopsis template <class F, class U>\nauto map_or_else(F &&f, U &&u)
/// &&;
template <class F, class U> template <class F, class U>
detail::invoke_result_t<U> map_or_else(F &&f, U &&u) && { detail::invoke_result_t<U> map_or_else(F &&f, U &&u) && {
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this)) return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
@@ -1065,23 +1069,24 @@ public:
/// Copy constructor /// Copy constructor
/// ///
/// If `rhs` contains a value, the stored value is direct-initialized with it. /// If `rhs` contains a value, the stored value is direct-initialized with
/// Otherwise, the constructed optional is empty. /// it. Otherwise, the constructed optional is empty.
TL_OPTIONAL_11_CONSTEXPR optional(const optional &rhs) = default; TL_OPTIONAL_11_CONSTEXPR optional(const optional &rhs) = default;
/// Move constructor /// Move constructor
/// ///
/// If `rhs` contains a value, the stored value is direct-initialized with it. /// If `rhs` contains a value, the stored value is direct-initialized with
/// Otherwise, the constructed optional is empty. /// it. Otherwise, the constructed optional is empty.
TL_OPTIONAL_11_CONSTEXPR optional(optional &&rhs) = default; TL_OPTIONAL_11_CONSTEXPR optional(optional &&rhs) = default;
/// Constructs the stored value in-place using the given arguments. /// Constructs the stored value in-place using the given arguments.
/// \group in_place /// \group in_place
/// \synopsis template <class... Args> constexpr explicit optional(in_place_t, /// \synopsis template <class... Args> constexpr explicit
/// Args&&... args); /// optional(in_place_t, Args&&... args);
template <class... Args> template <class... Args>
constexpr explicit optional( constexpr explicit optional(
detail::enable_if_t<std::is_constructible<T, Args...>::value, in_place_t>, detail::enable_if_t<std::is_constructible<T, Args...>::value,
in_place_t>,
Args &&... args) Args &&... args)
: base(in_place, std::forward<Args>(args)...) {} : base(in_place, std::forward<Args>(args)...) {}
@@ -1114,9 +1119,9 @@ public:
/// Converting copy constructor. /// Converting copy constructor.
/// \synopsis template <class U> optional(const optional<U> &rhs); /// \synopsis template <class U> optional(const optional<U> &rhs);
template < template <class U, detail::enable_from_other<T, U, const U &> * = nullptr,
class U, detail::enable_from_other<T, U, const U &> * = nullptr, detail::enable_if_t<std::is_convertible<const U &, T>::value> * =
detail::enable_if_t<std::is_convertible<const U &, T>::value> * = nullptr> nullptr>
optional(const optional<U> &rhs) { optional(const optional<U> &rhs) {
this->construct(*rhs); this->construct(*rhs);
} }
@@ -1233,8 +1238,8 @@ public:
return *this; return *this;
} }
/// Constructs the value in-place, destroying the current one if there is one. /// Constructs the value in-place, destroying the current one if there is
/// \group emplace /// one. \group emplace
template <class... Args> T &emplace(Args &&... args) { template <class... Args> T &emplace(Args &&... args) {
static_assert(std::is_constructible<T, Args &&...>::value, static_assert(std::is_constructible<T, Args &&...>::value,
"T must be constructible with Args"); "T must be constructible with Args");
@@ -1309,7 +1314,9 @@ public:
#ifndef TL_OPTIONAL_NO_CONSTRR #ifndef TL_OPTIONAL_NO_CONSTRR
/// \exclude /// \exclude
constexpr const T &&operator*() const && { return std::move(this->m_value); } constexpr const T &&operator*() const && {
return std::move(this->m_value);
}
#endif #endif
/// \returns whether or not the optional has a value /// \returns whether or not the optional has a value
@@ -1383,8 +1390,8 @@ public:
/// \brief Compares two optional objects /// \brief Compares two optional objects
/// \details If both optionals contain a value, they are compared with `T`s /// \details If both optionals contain a value, they are compared with `T`s
/// relational operators. Otherwise `lhs` and `rhs` are equal only if they are /// relational operators. Otherwise `lhs` and `rhs` are equal only if they are
/// both empty, and `lhs` is less than `rhs` only if `rhs` is empty and `lhs` is /// both empty, and `lhs` is less than `rhs` only if `rhs` is empty and `lhs`
/// not. /// is not.
template <class T, class U> template <class T, class U>
inline constexpr bool operator==(const optional<T> &lhs, inline constexpr bool operator==(const optional<T> &lhs,
const optional<U> &rhs) { const optional<U> &rhs) {
@@ -1489,8 +1496,8 @@ inline constexpr bool operator>=(nullopt_t, const optional<T> &rhs) noexcept {
/// \group relop_t /// \group relop_t
/// \brief Compares the optional with a value. /// \brief Compares the optional with a value.
/// \details If the optional has a value, it is compared with the other value /// \details If the optional has a value, it is compared with the other value
/// using `T`s relational operators. Otherwise, the optional is considered less /// using `T`s relational operators. Otherwise, the optional is considered
/// than the value. /// less than the value.
template <class T, class U> template <class T, class U>
inline constexpr bool operator==(const optional<T> &lhs, const U &rhs) { inline constexpr bool operator==(const optional<T> &lhs, const U &rhs) {
return lhs.has_value() ? *lhs == rhs : false; return lhs.has_value() ? *lhs == rhs : false;
@@ -1551,9 +1558,11 @@ inline constexpr bool operator>=(const U &lhs, const optional<T> &rhs) {
return rhs.has_value() ? lhs >= *rhs : true; return rhs.has_value() ? lhs >= *rhs : true;
} }
/// \synopsis template <class T>\nvoid swap(optional<T> &lhs, optional<T> &rhs); /// \synopsis template <class T>\nvoid swap(optional<T> &lhs, optional<T>
/// &rhs);
template <class T, template <class T,
detail::enable_if_t<std::is_move_constructible<T>::value> * = nullptr, detail::enable_if_t<std::is_move_constructible<T>::value> * =
nullptr,
detail::enable_if_t<detail::is_swappable<T>::value> * = nullptr> detail::enable_if_t<detail::is_swappable<T>::value> * = nullptr>
void swap(optional<T> & lhs, void swap(optional<T> & lhs,
optional<T> & rhs) noexcept(noexcept(lhs.swap(rhs))) { optional<T> & rhs) noexcept(noexcept(lhs.swap(rhs))) {