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
namespace tl {
#ifndef TL_OPTIONAL_EXPECTED_MUTEX
/// \brief Used to represent an optional with no data; essentially a bool
class monostate {};
@ -82,12 +83,13 @@
};
/// \brief A tag to tell optional to construct its value in-place
static constexpr in_place_t in_place{};
#endif
template <class T> class optional;
/// \exclude
namespace detail {
#ifndef TL_OPTIONAL_EXPECTED_MUTEX
// C++14-style aliases for brevity
template <class T> using remove_const_t = typename std::remove_const<T>::type;
template <class T>
@ -105,15 +107,6 @@
struct conjunction<B, Bs...>
: 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
// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround
template <typename Fn, typename... Args,
@ -148,6 +141,16 @@
template <class F, class... Us>
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
template <class U>
@ -171,8 +174,8 @@
using disable_if_ret_void = enable_if_t<!returns_void<T &&, U...>::value>;
template <class T, class U>
using enable_forward_value = detail::enable_if_t<
std::is_constructible<T, U &&>::value &&
using enable_forward_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<optional<T>, detail::decay_t<U>>::value>;
@ -216,8 +219,7 @@
// 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_nothrow_swappable : std::true_type {};
template <class T, class U = T> struct is_nothrow_swappable : std::true_type {};
#else
// https://stackoverflow.com/questions/26744589/what-is-a-proper-way-to-implement-is-swappable-to-test-for-the-swappable-concept
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
// 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;
void hard_reset() noexcept {
@ -414,8 +415,7 @@ struct is_nothrow_swappable
#else
template <class T, bool = false> struct optional_move_base;
#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;
optional_move_base() = default;
@ -1085,8 +1085,7 @@ template <class T, bool = false> struct optional_move_assign_base;
/// optional(in_place_t, Args&&... args);
template <class... Args>
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)
: base(in_place, std::forward<Args>(args)...) {}
@ -1119,9 +1118,9 @@ template <class T, bool = false> struct optional_move_assign_base;
/// Converting copy constructor.
/// \synopsis template <class U> optional(const optional<U> &rhs);
template <class U, detail::enable_from_other<T, U, const U &> * = nullptr,
detail::enable_if_t<std::is_convertible<const U &, T>::value> * =
nullptr>
template <
class U, detail::enable_from_other<T, U, const U &> * = nullptr,
detail::enable_if_t<std::is_convertible<const U &, T>::value> * = nullptr>
optional(const optional<U> &rhs) {
this->construct(*rhs);
}
@ -1314,9 +1313,7 @@ template <class T, bool = false> struct optional_move_assign_base;
#ifndef TL_OPTIONAL_NO_CONSTRR
/// \exclude
constexpr const T &&operator*() const && {
return std::move(this->m_value);
}
constexpr const T &&operator*() const && { return std::move(this->m_value); }
#endif
/// \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>
/// &rhs);
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>
void swap(optional<T> &lhs,
optional<T> &rhs) noexcept(noexcept(lhs.swap(rhs))) {
@ -1654,4 +1650,5 @@ template <class T> struct hash<tl::optional<T>> {
};
} // namespace std
#define TL_OPTIONAL_EXPECTED_MUTEX
#endif