Skip to content

Commit b56de86

Browse files
committed
Workaround for libcpp++ partial implementation of concepts
1 parent 9a0905a commit b56de86

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

include/boost/math/concepts/concepts.hpp

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ template <typename T>
9595
concept Real = std::is_floating_point_v<T>;
9696

9797
template <typename T>
98-
concept Arithmetic = Integral<T> || Real<T>;
98+
concept Arithmetic = std::is_arithmetic_v<T>;
9999

100100
template <typename T>
101101
concept Signed_arithmetic = Arithmetic<T> && std::is_signed_v<T>;
@@ -145,13 +145,38 @@ concept Aribitrary_real_type = Arbitrary_arithmetic_type<T> &&
145145
template <typename T>
146146
concept policy = boost::math::policies::is_policy<T>::value;
147147

148+
// Workaround for LIBCPP versions that have <concepts> but have not implemented concepts in <iterator>
149+
#if defined(_LIBCPP_VERSION) && !defined(_LIBCPP___ITERATOR_CONCEPTS_H)
150+
151+
template <typename T>
152+
concept forward_iterator = std::is_same_v<typename std::iterator_traits<T>::iterator_category(), std::forward_iterator_tag>;
153+
154+
template <typename T>
155+
concept bidirectional_iterator = std::is_same_v<typename std::iterator_traits<T>::iterator_category(), std::bidirectional_iterator_tag>;
156+
157+
template <typename T>
158+
concept random_access_iterator = std::is_same_v<typename std::iterator_traits<T>::iterator_category(), std::random_access_iterator_tag>;
159+
160+
#else
161+
162+
template <typename T>
163+
concept forward_iterator = std::forward_iterator<T>;
164+
165+
template <typename T>
166+
concept bidirectional_iterator = std::bidirectional_iterator<T>;
167+
168+
template <typename T>
169+
concept random_access_iterator = std::random_access_iterator<T>;
170+
171+
#endif
172+
148173
template <typename T>
149174
concept is_container = detail::has_begin_v<T> &&
150175
detail::has_end_v<T>;
151176

152177
template <typename T>
153178
concept random_access_container = is_container<T> &&
154-
std::random_access_iterator<typename T::iterator>;
179+
boost::math::concepts::random_access_iterator<typename T::iterator>;
155180

156181
} // boost::math::concepts
157182

@@ -170,14 +195,25 @@ concept random_access_container = is_container<T> &&
170195
#define BOOST_MATH_ARBITRARY_INTEGER boost::math::concepts::Aribitrary_integer_type
171196
#define BOOST_MATH_ARBITRARY_REAL boost::math::concepts::Aribitrary_real_type
172197
#define BOOST_MATH_POLICY boost::math::concepts::policy
173-
#define BOOST_MATH_FORWARD_ITER std::forward_iterator
174-
#define BOOST_MATH_BIDIRECTIONAL_ITER std::bidirectional_iterator
175-
#define BOOST_MATH_RANDOM_ACCESS_ITER std::random_access_iterator
176-
#define BOOST_MATH_OUTPUT_ITER std::output_iterator
177198
#define BOOST_MATH_CONTAINER boost::math::concepts::is_container
178199
#define BOOST_MATH_RANDOM_ACCESS_CONTAINER boost::math::concepts::random_access_container
179200
#define BOOST_MATH_REQUIRES(X, T) requires X<T>
180201

202+
// Workaround for LIBCPP versions that have <concepts> but have not implemented concepts in <iterator>
203+
#if defined(_LIBCPP_VERSION) && !defined(_LIBCPP___ITERATOR_CONCEPTS_H)
204+
205+
#define BOOST_MATH_FORWARD_ITER boost::math::concepts::forward_iterator
206+
#define BOOST_MATH_BIDIRECTIONAL_ITER boost::math::concepts::bidirectional_iterator
207+
#define BOOST_MATH_RANDOM_ACCESS_ITER boost::math::concepts::random_access_iterator
208+
209+
#else
210+
211+
#define BOOST_MATH_FORWARD_ITER std::forward_iterator
212+
#define BOOST_MATH_BIDIRECTIONAL_ITER std::bidirectional_iterator
213+
#define BOOST_MATH_RANDOM_ACCESS_ITER std::random_access_iterator
214+
215+
#endif
216+
181217
#endif
182218
#endif
183219

0 commit comments

Comments
 (0)