Clang format, support cohabitation with tl::expected

This commit is contained in:
Simon Brand
2017-11-16 11:17:26 +00:00
parent a1d27b2aba
commit b9486ce776

View File

@@ -73,6 +73,7 @@
#endif #endif
namespace tl { namespace tl {
#ifndef TL_OPTIONAL_EXPECTED_MUTEX
/// \brief Used to represent an optional with no data; essentially a bool /// \brief Used to represent an optional with no data; essentially a bool
class monostate {}; class monostate {};
@@ -82,12 +83,13 @@
}; };
/// \brief A tag to tell optional to construct its value in-place /// \brief A tag to tell optional to construct its value in-place
static constexpr in_place_t in_place{}; static constexpr in_place_t in_place{};
#endif
template <class T> class optional; template <class T> class optional;
/// \exclude /// \exclude
namespace detail { namespace detail {
#ifndef TL_OPTIONAL_EXPECTED_MUTEX
// C++14-style aliases for brevity // C++14-style aliases for brevity
template <class T> using remove_const_t = typename std::remove_const<T>::type; template <class T> using remove_const_t = typename std::remove_const<T>::type;
template <class T> template <class T>
@@ -105,15 +107,6 @@
struct conjunction<B, Bs...> struct conjunction<B, Bs...>
: std::conditional<bool(B::value), conjunction<Bs...>, B>::type {}; : std::conditional<bool(B::value), conjunction<Bs...>, B>::type {};
// std::void_t from C++17
template <class...> struct voider { using type = void; };
template <class... Ts> using void_t = typename voider<Ts...>::type;
// Trait for checking if a type is a tl::optional
template <class T> struct is_optional_impl : std::false_type {};
template <class T> struct is_optional_impl<optional<T>> : std::true_type {};
template <class T> using is_optional = is_optional_impl<decay_t<T>>;
// std::invoke from C++17 // std::invoke from C++17
// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround // https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround
template <typename Fn, typename... Args, template <typename Fn, typename... Args,
@@ -148,6 +141,16 @@
template <class F, class... Us> template <class F, class... Us>
using invoke_result_t = typename invoke_result<F, Us...>::type; using invoke_result_t = typename invoke_result<F, Us...>::type;
#endif
// std::void_t from C++17
template <class...> struct voider { using type = void; };
template <class... Ts> using void_t = typename voider<Ts...>::type;
// Trait for checking if a type is a tl::optional
template <class T> struct is_optional_impl : std::false_type {};
template <class T> struct is_optional_impl<optional<T>> : std::true_type {};
template <class T> using is_optional = is_optional_impl<decay_t<T>>;
// Change void to tl::monostate // Change void to tl::monostate
template <class U> template <class U>
@@ -171,8 +174,8 @@
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 = detail::enable_if_t< using enable_forward_value =
std::is_constructible<T, U &&>::value && detail::enable_if_t<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,8 +219,7 @@
// 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> template <class T, class U = T> struct is_nothrow_swappable : std::true_type {};
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 {
@@ -336,8 +338,7 @@ struct is_nothrow_swappable
// 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> template <class T> struct optional_operations_base : optional_storage_base<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 {
@@ -414,8 +415,7 @@ struct is_nothrow_swappable
#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> template <class T> struct optional_move_base<T, false> : optional_copy_base<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;
@@ -1085,8 +1085,7 @@ template <class T, bool = false> struct optional_move_assign_base;
/// optional(in_place_t, 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, detail::enable_if_t<std::is_constructible<T, Args...>::value, in_place_t>,
in_place_t>,
Args &&... args) Args &&... args)
: base(in_place, std::forward<Args>(args)...) {} : base(in_place, std::forward<Args>(args)...) {}
@@ -1119,9 +1118,9 @@ template <class T, bool = false> struct optional_move_assign_base;
/// 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 <class U, detail::enable_from_other<T, U, const U &> * = nullptr, template <
detail::enable_if_t<std::is_convertible<const U &, T>::value> * = class U, detail::enable_from_other<T, U, const U &> * = nullptr,
nullptr> detail::enable_if_t<std::is_convertible<const U &, T>::value> * = nullptr>
optional(const optional<U> &rhs) { optional(const optional<U> &rhs) {
this->construct(*rhs); this->construct(*rhs);
} }
@@ -1314,9 +1313,7 @@ template <class T, bool = false> struct optional_move_assign_base;
#ifndef TL_OPTIONAL_NO_CONSTRR #ifndef TL_OPTIONAL_NO_CONSTRR
/// \exclude /// \exclude
constexpr const T &&operator*() const && { constexpr const T &&operator*() const && { return std::move(this->m_value); }
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
@@ -1561,8 +1558,7 @@ template <class T, bool = false> struct optional_move_assign_base;
/// \synopsis template <class T>\nvoid swap(optional<T> &lhs, optional<T> /// \synopsis template <class T>\nvoid swap(optional<T> &lhs, optional<T>
/// &rhs); /// &rhs);
template <class T, template <class T,
detail::enable_if_t<std::is_move_constructible<T>::value> * = detail::enable_if_t<std::is_move_constructible<T>::value> * = nullptr,
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))) {
@@ -1654,4 +1650,5 @@ template <class T> struct hash<tl::optional<T>> {
}; };
} // namespace std } // namespace std
#define TL_OPTIONAL_EXPECTED_MUTEX
#endif #endif