Remove whitespace changes

This commit is contained in:
Simon Brand
2019-02-19 16:03:35 +00:00
parent 81d7cba98c
commit 2f642a5f0e

View File

@@ -71,31 +71,30 @@
#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \ #define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
std::is_trivially_destructible<T> std::is_trivially_destructible<T>
// GCC 5 < v < 8 has a bug in is_trivially_copy_constructible which breaks // GCC 5 < v < 8 has a bug in is_trivially_copy_constructible which breaks std::vector
// std::vector for non-copyable types // for non-copyable types
#elif (defined(__GNUC__) && __GNUC__ < 8 && !defined(__clang__)) #elif (defined(__GNUC__) && __GNUC__ < 8 && \
!defined(__clang__))
#ifndef TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX #ifndef TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
#define TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX #define TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
namespace tl { namespace tl {
namespace detail { namespace detail {
template <class T> template<class T>
struct is_trivially_copy_constructible struct is_trivially_copy_constructible : std::is_trivially_copy_constructible<T>{};
: std::is_trivially_copy_constructible<T> {};
#ifdef _GLIBCXX_VECTOR #ifdef _GLIBCXX_VECTOR
template <class T, class A> template<class T, class A>
struct is_trivially_copy_constructible<std::vector<T, A>> struct is_trivially_copy_constructible<std::vector<T,A>>
: std::is_trivially_copy_constructible<T> {}; : std::is_trivially_copy_constructible<T>{};
#endif #endif
} // namespace detail }
} // namespace tl }
#endif #endif
#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \ #define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
tl::detail::is_trivially_copy_constructible<T> tl::detail::is_trivially_copy_constructible<T>
#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \ #define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
std::is_trivially_copy_assignable<T> std::is_trivially_copy_assignable<T>
#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \ #define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) std::is_trivially_destructible<T>
std::is_trivially_destructible<T>
#else #else
/// \exclude /// \exclude
#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \ #define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
@@ -124,7 +123,7 @@ struct is_trivially_copy_constructible<std::vector<T, A>>
/// \exclude /// \exclude
#define TL_EXPECTED_11_CONSTEXPR #define TL_EXPECTED_11_CONSTEXPR
#else #else
/// \exclude /// \exclude
#define TL_EXPECTED_11_CONSTEXPR constexpr #define TL_EXPECTED_11_CONSTEXPR constexpr
#endif #endif
@@ -220,24 +219,23 @@ static constexpr unexpect_t unexpect{};
/// \exclude /// \exclude
namespace detail { namespace detail {
template <typename E> template<typename E>
[[noreturn]] TL_EXPECTED_11_CONSTEXPR void throw_exception(E &&e) { [[noreturn]] TL_EXPECTED_11_CONSTEXPR void throw_exception(E &&e) {
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED #ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
throw std::forward<E>(e); throw std::forward<E>(e);
#else #else
#ifdef _MSC_VER #ifdef _MSC_VER
__assume(0); __assume(0);
#else #else
__builtin_unreachable(); __builtin_unreachable();
#endif #endif
#endif #endif
} }
#ifndef TL_TRAITS_MUTEX #ifndef TL_TRAITS_MUTEX
#define TL_TRAITS_MUTEX #define TL_TRAITS_MUTEX
// C++14-style aliases for brevity // C++14-style aliases for brevity
template <class T> template <class T> using remove_const_t = typename std::remove_const<T>::type;
using remove_const_t = typename std::remove_const<T>::type;
template <class T> template <class T>
using remove_reference_t = typename std::remove_reference<T>::type; using remove_reference_t = typename std::remove_reference<T>::type;
template <class T> using decay_t = typename std::decay<T>::type; template <class T> using decay_t = typename std::decay<T>::type;
@@ -277,11 +275,9 @@ template <class F, class, class... Us> struct invoke_result_impl;
template <class F, class... Us> template <class F, class... Us>
struct invoke_result_impl< struct invoke_result_impl<
F, F, decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...), void()),
decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...), void()),
Us...> { Us...> {
using type = using type = decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...));
decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...));
}; };
template <class F, class... Us> template <class F, class... Us>
@@ -402,10 +398,14 @@ using is_move_constructible_or_void =
is_void_or<T, std::is_move_constructible<T>>; is_void_or<T, std::is_move_constructible<T>>;
template <class T> template <class T>
using is_copy_assignable_or_void = is_void_or<T, std::is_copy_assignable<T>>; using is_copy_assignable_or_void =
is_void_or<T, std::is_copy_assignable<T>>;
template <class T> template <class T>
using is_move_assignable_or_void = is_void_or<T, std::is_move_assignable<T>>; using is_move_assignable_or_void =
is_void_or<T, std::is_move_assignable<T>>;
} // namespace detail } // namespace detail
@@ -684,7 +684,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
this->m_has_val = false; this->m_has_val = false;
} }
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED #ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
// These assign overloads ensure that the most efficient assignment // These assign overloads ensure that the most efficient assignment
// implementation is used while maintaining the strong exception guarantee. // implementation is used while maintaining the strong exception guarantee.
@@ -776,7 +776,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
} }
} }
#else #else
// If exceptions are disabled then we can just copy-construct // If exceptions are disabled then we can just copy-construct
void assign(const expected_operations_base &rhs) noexcept { void assign(const expected_operations_base &rhs) noexcept {
@@ -797,7 +797,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
} }
} }
#endif #endif
// The common part of move/copy assigning // The common part of move/copy assigning
template <class Rhs> void assign_common(Rhs &&rhs) { template <class Rhs> void assign_common(Rhs &&rhs) {
@@ -805,7 +805,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
if (rhs.m_has_val) { if (rhs.m_has_val) {
get() = std::forward<Rhs>(rhs).get(); get() = std::forward<Rhs>(rhs).get();
} else { } else {
destroy_val(); destroy_val();
construct_error(std::forward<Rhs>(rhs).geterr()); construct_error(std::forward<Rhs>(rhs).geterr());
} }
} else { } else {
@@ -837,7 +837,9 @@ struct expected_operations_base : expected_storage_base<T, E> {
} }
#endif #endif
constexpr void destroy_val() { get().~T(); } constexpr void destroy_val() {
get().~T();
}
}; };
// 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
@@ -891,7 +893,7 @@ struct expected_operations_base<void, E> : expected_storage_base<void, E> {
#endif #endif
constexpr void destroy_val() { constexpr void destroy_val() {
// no-op //no-op
} }
}; };
@@ -1223,9 +1225,7 @@ class expected : private detail::expected_move_assign_base<T, E>,
T *valptr() { return std::addressof(this->m_val); } T *valptr() { return std::addressof(this->m_val); }
const T *valptr() const { return std::addressof(this->m_val); } const T *valptr() const { return std::addressof(this->m_val); }
unexpected<E> *errptr() { return std::addressof(this->m_unexpect); } unexpected<E> *errptr() { return std::addressof(this->m_unexpect); }
const unexpected<E> *errptr() const { const unexpected<E> *errptr() const { return std::addressof(this->m_unexpect); }
return std::addressof(this->m_unexpect);
}
template <class U = T, template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr> detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
@@ -1381,8 +1381,8 @@ public:
/// \group map /// \group map
/// \synopsis template <class F> constexpr auto map(F &&f) &&; /// \synopsis template <class F> constexpr auto map(F &&f) &&;
template <class F> template <class F>
TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval<expected>(), TL_EXPECTED_11_CONSTEXPR decltype(
std::declval<F &&>())) expected_map_impl(std::declval<expected>(), std::declval<F &&>()))
map(F &&f) && { map(F &&f) && {
return expected_map_impl(std::move(*this), std::forward<F>(f)); return expected_map_impl(std::move(*this), std::forward<F>(f));
} }
@@ -1494,8 +1494,8 @@ public:
/// \requires `F` is invokable with `E`, and `std::invoke_result_t<F>` /// \requires `F` is invokable with `E`, and `std::invoke_result_t<F>`
/// must be void or convertible to `expcted<T,E>`. /// must be void or convertible to `expcted<T,E>`.
/// \effects If `*this` has a value, returns `*this`. /// \effects If `*this` has a value, returns `*this`.
/// Otherwise, if `f` returns `void`, calls `std::forward<F>(f)(E)` and /// Otherwise, if `f` returns `void`, calls `std::forward<F>(f)(E)` and returns
/// returns `std::nullopt`. Otherwise, returns `std::forward<F>(f)(E)`. /// `std::nullopt`. Otherwise, returns `std::forward<F>(f)(E)`.
/// ///
/// \group or_else /// \group or_else
template <class F> expected TL_EXPECTED_11_CONSTEXPR or_else(F &&f) & { template <class F> expected TL_EXPECTED_11_CONSTEXPR or_else(F &&f) & {
@@ -1712,7 +1712,7 @@ public:
auto tmp = std::move(err()); auto tmp = std::move(err());
err().~unexpected<E>(); err().~unexpected<E>();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED #ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try { try {
::new (valptr()) T(std::forward<U>(v)); ::new (valptr()) T(std::forward<U>(v));
this->m_has_val = true; this->m_has_val = true;
@@ -1720,10 +1720,10 @@ public:
err() = std::move(tmp); err() = std::move(tmp);
throw; throw;
} }
#else #else
::new (valptr()) T(std::forward<U>(v)); ::new (valptr()) T(std::forward<U>(v));
this->m_has_val = true; this->m_has_val = true;
#endif #endif
} }
return *this; return *this;
@@ -1781,7 +1781,7 @@ public:
auto tmp = std::move(err()); auto tmp = std::move(err());
err().~unexpected<E>(); err().~unexpected<E>();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED #ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try { try {
::new (valptr()) T(std::forward<Args>(args)...); ::new (valptr()) T(std::forward<Args>(args)...);
this->m_has_val = true; this->m_has_val = true;
@@ -1789,10 +1789,10 @@ public:
err() = std::move(tmp); err() = std::move(tmp);
throw; throw;
} }
#else #else
::new (valptr()) T(std::forward<Args>(args)...); ::new (valptr()) T(std::forward<Args>(args)...);
this->m_has_val = true; this->m_has_val = true;
#endif #endif
} }
} }
@@ -1822,7 +1822,7 @@ public:
auto tmp = std::move(err()); auto tmp = std::move(err());
err().~unexpected<E>(); err().~unexpected<E>();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED #ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try { try {
::new (valptr()) T(il, std::forward<Args>(args)...); ::new (valptr()) T(il, std::forward<Args>(args)...);
this->m_has_val = true; this->m_has_val = true;
@@ -1830,10 +1830,10 @@ public:
err() = std::move(tmp); err() = std::move(tmp);
throw; throw;
} }
#else #else
::new (valptr()) T(il, std::forward<Args>(args)...); ::new (valptr()) T(il, std::forward<Args>(args)...);
this->m_has_val = true; this->m_has_val = true;
#endif #endif
} }
} }
@@ -1854,7 +1854,7 @@ private:
swap(val(), rhs.val()); swap(val(), rhs.val());
} }
void swap_where_only_one_has_value(expected &rhs, t_is_void) noexcept ( void swap_where_only_one_has_value(expected &rhs, t_is_void) noexcept(
std::is_nothrow_move_constructible<E>::value) { std::is_nothrow_move_constructible<E>::value) {
::new (errptr()) unexpected_type(std::move(rhs.err())); ::new (errptr()) unexpected_type(std::move(rhs.err()));
rhs.err().~unexpected_type(); rhs.err().~unexpected_type();
@@ -1863,8 +1863,8 @@ private:
void swap_where_only_one_has_value(expected &rhs, t_is_not_void) { void swap_where_only_one_has_value(expected &rhs, t_is_not_void) {
swap_where_only_one_has_value_and_t_is_not_void( swap_where_only_one_has_value_and_t_is_not_void(
rhs, std::is_nothrow_move_constructible<T>::type{}, rhs, typename std::is_nothrow_move_constructible<T>::type{},
std::is_nothrow_move_constructible<E>::type{}); typename std::is_nothrow_move_constructible<E>::type{});
} }
void swap_where_only_one_has_value_and_t_is_not_void( void swap_where_only_one_has_value_and_t_is_not_void(
@@ -1922,11 +1922,11 @@ public:
&&std::is_nothrow_move_constructible<E>::value &&std::is_nothrow_move_constructible<E>::value
&&detail::is_nothrow_swappable<E>::value) { &&detail::is_nothrow_swappable<E>::value) {
if (has_value() && rhs.has_value()) { if (has_value() && rhs.has_value()) {
swap_where_both_have_value(rhs, std::is_void<T>::type{}); swap_where_both_have_value(rhs, typename std::is_void<T>::type{});
} else if (!has_value() && rhs.has_value()) { } else if (!has_value() && rhs.has_value()) {
rhs.swap(*this); rhs.swap(*this);
} else if (has_value()) { } else if (has_value()) {
swap_where_only_one_has_value(rhs, std::is_void<T>::type{}); swap_where_only_one_has_value(rhs, typename std::is_void<T>::type{});
} else { } else {
using std::swap; using std::swap;
swap(err(), rhs.err()); swap(err(), rhs.err());
@@ -2323,9 +2323,9 @@ template <class Exp, class F,
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr> detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
constexpr auto or_else_impl(Exp &&exp, F &&f) { constexpr auto or_else_impl(Exp &&exp, F &&f) {
static_assert(detail::is_expected<Ret>::value, "F must return an expected"); static_assert(detail::is_expected<Ret>::value, "F must return an expected");
return exp.has_value() ? std::forward<Exp>(exp) return exp.has_value()
: detail::invoke(std::forward<F>(f), ? std::forward<Exp>(exp)
std::forward<Exp>(exp).error()); : detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
} }
template <class Exp, class F, template <class Exp, class F,
@@ -2333,32 +2333,32 @@ template <class Exp, class F,
std::declval<Exp>().error())), std::declval<Exp>().error())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr> detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) { detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) {
return exp.has_value() ? std::forward<Exp>(exp) return exp.has_value()
: (detail::invoke(std::forward<F>(f), ? std::forward<Exp>(exp)
std::forward<Exp>(exp).error()), : (detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error()),
std::forward<Exp>(exp)); std::forward<Exp>(exp));
} }
#else #else
template <class Exp, class F, template <class Exp, class F,
class Ret = decltype(detail::invoke(std::declval<F>(), class Ret = decltype(detail::invoke(std::declval<F>(),
std::declval<Exp>().error())), std::declval<Exp>().error())),
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr> detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
auto or_else_impl(Exp &&exp, F &&f) -> Ret { auto or_else_impl(Exp &&exp, F &&f) -> Ret {
static_assert(detail::is_expected<Ret>::value, "F must return an expected"); static_assert(detail::is_expected<Ret>::value, "F must return an expected");
return exp.has_value() ? std::forward<Exp>(exp) return exp.has_value()
: detail::invoke(std::forward<F>(f), ? std::forward<Exp>(exp)
std::forward<Exp>(exp).error()); : detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
} }
template <class Exp, class F, template <class Exp, class F,
class Ret = decltype(detail::invoke(std::declval<F>(), class Ret = decltype(detail::invoke(std::declval<F>(),
std::declval<Exp>().error())), std::declval<Exp>().error())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr> detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) { detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) {
return exp.has_value() ? std::forward<Exp>(exp) return exp.has_value()
: (detail::invoke(std::forward<F>(f), ? std::forward<Exp>(exp)
std::forward<Exp>(exp).error()), : (detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error()),
std::forward<Exp>(exp)); std::forward<Exp>(exp));
} }
#endif #endif
} // namespace detail } // namespace detail