32
32
#include < utility>
33
33
34
34
#if (defined(_MSC_VER) && _MSC_VER == 1900)
35
- # define TL_OPTIONAL_MSVC2015
35
+ #define TL_OPTIONAL_MSVC2015
36
36
#endif
37
37
38
38
#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && !defined(__clang__))
39
- # define TL_OPTIONAL_GCC49
39
+ #define TL_OPTIONAL_GCC49
40
40
#endif
41
41
42
42
#if (defined(__GNUC__) && __GNUC__ == 5 && __GNUC_MINOR__ <= 4 && !defined(__clang__))
43
- # define TL_OPTIONAL_GCC54
43
+ #define TL_OPTIONAL_GCC54
44
44
#endif
45
45
46
46
#if (defined(__GNUC__) && __GNUC__ == 5 && __GNUC_MINOR__ <= 5 && !defined(__clang__))
47
- # define TL_OPTIONAL_GCC55
47
+ #define TL_OPTIONAL_GCC55
48
48
#endif
49
49
50
50
#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && !defined(__clang__))
51
51
// GCC < 5 doesn't support overloading on const&& for member functions
52
- # define TL_OPTIONAL_NO_CONSTRR
52
+ #define TL_OPTIONAL_NO_CONSTRR
53
53
54
54
// GCC < 5 doesn't support some standard C++11 type traits
55
- # define TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE (T ) \
56
- std::has_trivial_copy_constructor<T>::value
57
- # define TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE (T ) std::has_trivial_copy_assign<T>::value
55
+ #define TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE (T ) \
56
+ std::has_trivial_copy_constructor<T>::value
57
+ #define TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE (T ) std::has_trivial_copy_assign<T>::value
58
58
59
59
// This one will be different for GCC 5.7 if it's ever supported
60
- # define TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE (T ) std::is_trivially_destructible<T>::value
60
+ #define TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE (T ) std::is_trivially_destructible<T>::value
61
61
62
62
// GCC 5 < v < 8 has a bug in is_trivially_copy_constructible which breaks std::vector
63
63
// for non-copyable types
64
64
#elif (defined(__GNUC__) && __GNUC__ < 8 && !defined(__clang__))
65
- # ifndef TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
66
- # define TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
65
+ #ifndef TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
66
+ #define TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
67
67
namespace tl {
68
68
namespace detail {
69
69
template <class T >
70
70
struct is_trivially_copy_constructible : std::is_trivially_copy_constructible<T> {};
71
- # ifdef _GLIBCXX_VECTOR
71
+ #ifdef _GLIBCXX_VECTOR
72
72
template <class T , class A >
73
73
struct is_trivially_copy_constructible <std::vector<T, A>>
74
74
: std::is_trivially_copy_constructible<T> {};
75
- # endif
75
+ #endif
76
76
} // namespace detail
77
77
} // namespace tl
78
- # endif
78
+ #endif
79
79
80
- # define TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE (T ) \
81
- tl::detail::is_trivially_copy_constructible<T>::value
82
- # define TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE (T ) \
83
- std::is_trivially_copy_assignable<T>::value
84
- # define TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE (T ) std::is_trivially_destructible<T>::value
80
+ #define TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE (T ) \
81
+ tl::detail::is_trivially_copy_constructible<T>::value
82
+ #define TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE (T ) \
83
+ std::is_trivially_copy_assignable<T>::value
84
+ #define TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE (T ) std::is_trivially_destructible<T>::value
85
85
#else
86
- # define TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE (T ) \
87
- std::is_trivially_copy_constructible<T>::value
88
- # define TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE (T ) \
89
- std::is_trivially_copy_assignable<T>::value
90
- # define TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE (T ) std::is_trivially_destructible<T>::value
86
+ #define TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE (T ) \
87
+ std::is_trivially_copy_constructible<T>::value
88
+ #define TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE (T ) \
89
+ std::is_trivially_copy_assignable<T>::value
90
+ #define TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE (T ) std::is_trivially_destructible<T>::value
91
91
#endif
92
92
93
93
#if __cplusplus > 201103L
94
- # define TL_OPTIONAL_CXX14
94
+ #define TL_OPTIONAL_CXX14
95
95
#endif
96
96
97
97
// constexpr implies const in C++11, not C++14
98
98
#if (__cplusplus == 201103L || defined(TL_OPTIONAL_MSVC2015) || defined(TL_OPTIONAL_GCC49))
99
- # define TL_OPTIONAL_11_CONSTEXPR
99
+ #define TL_OPTIONAL_11_CONSTEXPR
100
100
#else
101
- # define TL_OPTIONAL_11_CONSTEXPR constexpr
101
+ #define TL_OPTIONAL_11_CONSTEXPR constexpr
102
102
#endif
103
103
104
104
namespace tl {
105
105
#ifndef TL_MONOSTATE_INPLACE_MUTEX
106
- # define TL_MONOSTATE_INPLACE_MUTEX
106
+ #define TL_MONOSTATE_INPLACE_MUTEX
107
107
// / Used to represent an optional with no data; essentially a bool
108
108
class monostate {};
109
109
@@ -120,7 +120,7 @@ class optional;
120
120
121
121
namespace detail {
122
122
#ifndef TL_TRAITS_MUTEX
123
- # define TL_TRAITS_MUTEX
123
+ #define TL_TRAITS_MUTEX
124
124
// C++14-style aliases for brevity
125
125
template <class T >
126
126
using remove_const_t = typename std::remove_const<T>::type;
@@ -142,14 +142,14 @@ template<class B, class... Bs>
142
142
struct conjunction <B, Bs...>
143
143
: std::conditional<bool (B::value), conjunction<Bs...>, B>::type {};
144
144
145
- # if defined(_LIBCPP_VERSION) && __cplusplus == 201103L
146
- # define TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
147
- # endif
145
+ #if defined(_LIBCPP_VERSION) && __cplusplus == 201103L
146
+ #define TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
147
+ #endif
148
148
149
149
// In C++11 mode, there's an issue in libc++'s std::mem_fn
150
150
// which results in a hard-error when using it in a noexcept expression
151
151
// in some cases. This is a check to workaround the common failing case.
152
- # ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
152
+ #ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
153
153
template <class T >
154
154
struct is_pointer_to_non_const_member_func : std::false_type {};
155
155
template <class T , class Ret , class ... Args>
@@ -171,14 +171,14 @@ template<class T>
171
171
struct is_const_or_const_ref <T const &> : std::true_type {};
172
172
template <class T >
173
173
struct is_const_or_const_ref <T const > : std::true_type {};
174
- # endif
174
+ #endif
175
175
176
176
// std::invoke from C++17
177
177
// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround
178
178
template <typename Fn, typename ... Args,
179
- # ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
179
+ #ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
180
180
typename = enable_if_t <!(is_pointer_to_non_const_member_func<Fn>::value && is_const_or_const_ref<Args...>::value)>,
181
- # endif
181
+ #endif
182
182
typename = enable_if_t <std::is_member_pointer<decay_t <Fn>>::value>,
183
183
int = 0 >
184
184
constexpr auto invoke (Fn&& f, Args&&... args) noexcept (
@@ -212,14 +212,14 @@ using invoke_result = invoke_result_impl<F, void, Us...>;
212
212
template <class F , class ... Us>
213
213
using invoke_result_t = typename invoke_result<F, Us...>::type;
214
214
215
- # if defined(_MSC_VER) && _MSC_VER <= 1900
215
+ #if defined(_MSC_VER) && _MSC_VER <= 1900
216
216
// TODO make a version which works with MSVC 2015
217
217
template <class T , class U = T>
218
218
struct is_swappable : std::true_type {};
219
219
220
220
template <class T , class U = T>
221
221
struct is_nothrow_swappable : std::true_type {};
222
- # else
222
+ #else
223
223
// https://stackoverflow.com/questions/26744589/what-is-a-proper-way-to-implement-is-swappable-to-test-for-the-swappable-concept
224
224
namespace swap_adl_tests {
225
225
// if swap ADL finds this then it would call std::swap otherwise (same
@@ -276,7 +276,7 @@ struct is_nothrow_swappable
276
276
bool ,
277
277
is_swappable<T, U>::value && ((decltype(detail::swap_adl_tests::uses_std<T, U>(0 ))::value && detail::swap_adl_tests::is_std_swap_noexcept<T>::value) || (!decltype(detail::swap_adl_tests::uses_std<T, U>(0 ))::value && detail::swap_adl_tests::is_adl_swap_noexcept<T, U>::value))> {
278
278
};
279
- # endif
279
+ #endif
280
280
#endif
281
281
282
282
// std::void_t from C++17
@@ -719,7 +719,7 @@ class optional : private detail::optional_move_assign_base<T>,
719
719
: result (nullopt);
720
720
}
721
721
722
- # ifndef TL_OPTIONAL_NO_CONSTRR
722
+ #ifndef TL_OPTIONAL_NO_CONSTRR
723
723
template <class F >
724
724
constexpr auto and_then (F&& f) const && {
725
725
using result = detail::invoke_result_t <F, const T&&>;
@@ -729,7 +729,7 @@ class optional : private detail::optional_move_assign_base<T>,
729
729
return has_value () ? detail::invoke (std::forward<F>(f), std::move (**this ))
730
730
: result (nullopt);
731
731
}
732
- # endif
732
+ #endif
733
733
#else
734
734
// / Carries out some operation which returns an optional on the stored
735
735
// / object if there is one.
@@ -763,7 +763,7 @@ class optional : private detail::optional_move_assign_base<T>,
763
763
: result (nullopt);
764
764
}
765
765
766
- # ifndef TL_OPTIONAL_NO_CONSTRR
766
+ #ifndef TL_OPTIONAL_NO_CONSTRR
767
767
template <class F >
768
768
constexpr detail::invoke_result_t <F, const T&&> and_then (F&& f) const && {
769
769
using result = detail::invoke_result_t <F, const T&&>;
@@ -773,7 +773,7 @@ class optional : private detail::optional_move_assign_base<T>,
773
773
return has_value () ? detail::invoke (std::forward<F>(f), std::move (**this ))
774
774
: result (nullopt);
775
775
}
776
- # endif
776
+ #endif
777
777
#endif
778
778
779
779
#if defined(TL_OPTIONAL_CXX14) && !defined(TL_OPTIONAL_GCC49) && !defined(TL_OPTIONAL_GCC54) && !defined(TL_OPTIONAL_GCC55)
@@ -820,14 +820,14 @@ class optional : private detail::optional_move_assign_base<T>,
820
820
return optional_map_impl (*this , std::forward<F>(f));
821
821
}
822
822
823
- # ifndef TL_OPTIONAL_NO_CONSTRR
823
+ #ifndef TL_OPTIONAL_NO_CONSTRR
824
824
template <class F >
825
825
constexpr decltype (optional_map_impl(std::declval<const optional&&>(),
826
826
std::declval<F&&>()))
827
827
map(F&& f) const && {
828
828
return optional_map_impl (std::move (*this ), std::forward<F>(f));
829
829
}
830
- # endif
830
+ #endif
831
831
#endif
832
832
833
833
#if defined(TL_OPTIONAL_CXX14) && !defined(TL_OPTIONAL_GCC49) && !defined(TL_OPTIONAL_GCC54) && !defined(TL_OPTIONAL_GCC55)
@@ -874,14 +874,14 @@ class optional : private detail::optional_move_assign_base<T>,
874
874
return optional_map_impl (*this , std::forward<F>(f));
875
875
}
876
876
877
- # ifndef TL_OPTIONAL_NO_CONSTRR
877
+ #ifndef TL_OPTIONAL_NO_CONSTRR
878
878
template <class F >
879
879
constexpr decltype (optional_map_impl(std::declval<const optional&&>(),
880
880
std::declval<F&&>()))
881
881
transform(F&& f) const && {
882
882
return optional_map_impl (std::move (*this ), std::forward<F>(f));
883
883
}
884
- # endif
884
+ #endif
885
885
#endif
886
886
887
887
// / Calls `f` if the optional is empty
@@ -1593,7 +1593,7 @@ class optional<T&> {
1593
1593
: result (nullopt);
1594
1594
}
1595
1595
1596
- # ifndef TL_OPTIONAL_NO_CONSTRR
1596
+ #ifndef TL_OPTIONAL_NO_CONSTRR
1597
1597
template <class F >
1598
1598
constexpr auto and_then (F&& f) const && {
1599
1599
using result = detail::invoke_result_t <F, const T&>;
@@ -1603,7 +1603,7 @@ class optional<T&> {
1603
1603
return has_value () ? detail::invoke (std::forward<F>(f), **this )
1604
1604
: result (nullopt);
1605
1605
}
1606
- # endif
1606
+ #endif
1607
1607
#else
1608
1608
// / Carries out some operation which returns an optional on the stored
1609
1609
// / object if there is one.
@@ -1637,7 +1637,7 @@ class optional<T&> {
1637
1637
: result (nullopt);
1638
1638
}
1639
1639
1640
- # ifndef TL_OPTIONAL_NO_CONSTRR
1640
+ #ifndef TL_OPTIONAL_NO_CONSTRR
1641
1641
template <class F >
1642
1642
constexpr detail::invoke_result_t <F, const T&> and_then (F&& f) const && {
1643
1643
using result = detail::invoke_result_t <F, const T&>;
@@ -1647,7 +1647,7 @@ class optional<T&> {
1647
1647
return has_value () ? detail::invoke (std::forward<F>(f), **this )
1648
1648
: result (nullopt);
1649
1649
}
1650
- # endif
1650
+ #endif
1651
1651
#endif
1652
1652
1653
1653
#if defined(TL_OPTIONAL_CXX14) && !defined(TL_OPTIONAL_GCC49) && !defined(TL_OPTIONAL_GCC54) && !defined(TL_OPTIONAL_GCC55)
@@ -1694,14 +1694,14 @@ class optional<T&> {
1694
1694
return detail::optional_map_impl (*this , std::forward<F>(f));
1695
1695
}
1696
1696
1697
- # ifndef TL_OPTIONAL_NO_CONSTRR
1697
+ #ifndef TL_OPTIONAL_NO_CONSTRR
1698
1698
template <class F >
1699
1699
constexpr decltype (detail::optional_map_impl(std::declval<const optional&&>(),
1700
1700
std::declval<F&&>()))
1701
1701
map(F&& f) const && {
1702
1702
return detail::optional_map_impl (std::move (*this ), std::forward<F>(f));
1703
1703
}
1704
- # endif
1704
+ #endif
1705
1705
#endif
1706
1706
1707
1707
#if defined(TL_OPTIONAL_CXX14) && !defined(TL_OPTIONAL_GCC49) && !defined(TL_OPTIONAL_GCC54) && !defined(TL_OPTIONAL_GCC55)
@@ -1750,14 +1750,14 @@ class optional<T&> {
1750
1750
return detail::optional_map_impl (*this , std::forward<F>(f));
1751
1751
}
1752
1752
1753
- # ifndef TL_OPTIONAL_NO_CONSTRR
1753
+ #ifndef TL_OPTIONAL_NO_CONSTRR
1754
1754
template <class F >
1755
1755
constexpr decltype (detail::optional_map_impl(std::declval<const optional&&>(),
1756
1756
std::declval<F&&>()))
1757
1757
transform(F&& f) const && {
1758
1758
return detail::optional_map_impl (std::move (*this ), std::forward<F>(f));
1759
1759
}
1760
- # endif
1760
+ #endif
1761
1761
#endif
1762
1762
1763
1763
// / Calls `f` if the optional is empty
0 commit comments