Fix STL feature detection for c++20.

This commit is contained in:
Antonio Sánchez 2025-02-28 19:52:37 +00:00 committed by Rasmus Munk Larsen
parent 179a49684a
commit be5147b090
3 changed files with 16 additions and 12 deletions

View File

@ -325,7 +325,7 @@ class pointer_based_stl_iterator {
public:
typedef Index difference_type;
typedef typename XprType::Scalar value_type;
#if EIGEN_CPLUSPLUS >= 202002L
#if EIGEN_COMP_CXXVER >= 20 && defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
typedef std::conditional_t<XprType::InnerStrideAtCompileTime == 1, std::contiguous_iterator_tag,
std::random_access_iterator_tag>
iterator_category;

View File

@ -1316,7 +1316,8 @@ inline int queryTopLevelCacheSize() {
* This wraps C++20's std::construct_at, using placement new instead if it is not available.
*/
#if EIGEN_COMP_CXXVER >= 20
#if EIGEN_COMP_CXXVER >= 20 && defined(__cpp_lib_constexpr_dynamic_alloc) && \
__cpp_lib_constexpr_dynamic_alloc >= 201907L
using std::construct_at;
#else
template <class T, class... Args>

View File

@ -220,7 +220,7 @@ struct is_void : is_same<void, std::remove_const_t<T>> {};
*
* Post C++17: Uses std::void_t
*/
#if EIGEN_COMP_CXXVER >= 17
#if EIGEN_COMP_CXXVER >= 17 && defined(__cpp_lib_void_t) && __cpp_lib_void_t >= 201411L
using std::void_t;
#else
template <typename...>
@ -338,7 +338,16 @@ struct array_size<std::array<T, N>> {
*
* For C++20, this function just forwards to `std::ssize`, or any ADL discoverable `ssize` function.
*/
#if EIGEN_COMP_CXXVER < 20 || EIGEN_GNUC_STRICT_LESS_THAN(10, 0, 0)
#if EIGEN_COMP_CXXVER >= 20 && defined(__cpp_lib_ssize) && __cpp_lib_ssize >= 201902L
template <typename T>
EIGEN_CONSTEXPR auto index_list_size(T&& x) {
using std::ssize;
return ssize(std::forward<T>(x));
}
#else
template <typename T>
EIGEN_CONSTEXPR auto index_list_size(const T& x) {
using R = std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(x.size())>>;
@ -349,13 +358,7 @@ template <typename T, std::ptrdiff_t N>
EIGEN_CONSTEXPR std::ptrdiff_t index_list_size(const T (&)[N]) {
return N;
}
#else
template <typename T>
EIGEN_CONSTEXPR auto index_list_size(T&& x) {
using std::ssize;
return ssize(std::forward<T>(x));
}
#endif // EIGEN_COMP_CXXVER
#endif
/** \internal
* Convenient struct to get the result type of a nullary, unary, binary, or
@ -745,7 +748,7 @@ inline constexpr bool logical_xor(bool a, bool b) { return a != b; }
inline constexpr bool check_implication(bool a, bool b) { return !a || b; }
/// \internal Provide fallback for std::is_constant_evaluated for pre-C++20.
#if EIGEN_COMP_CXXVER >= 20
#if EIGEN_COMP_CXXVER >= 20 && defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
using std::is_constant_evaluated;
#else
constexpr bool is_constant_evaluated() { return false; }