-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace use of constexpr if in headers used to implement p0009 in order to allow compilation for C++14 without C++17 extensions.
- Loading branch information
Showing
6 changed files
with
201 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <type_traits> | ||
|
||
namespace MDSPAN_IMPL_STANDARD_NAMESPACE { | ||
namespace detail { | ||
|
||
// type alias used for rank-based tag dispatch | ||
// | ||
// this is used to enable alternatives to constexpr if when building for C++14 | ||
// | ||
template <std::size_t N> | ||
using with_rank = std::integral_constant<std::size_t, N>; | ||
|
||
template <class I1, class I2> | ||
constexpr bool common_integral_compare(I1 x, I2 y) | ||
{ | ||
static_assert(std::is_integral<I1>::value and | ||
std::is_integral<I2>::value, ""); | ||
|
||
using I = std::common_type_t<I1, I2>; | ||
return static_cast<I>(x) == static_cast<I>(y); | ||
} | ||
|
||
template <class T1, class T2, class F> | ||
constexpr bool rankwise_equal(with_rank<0>, const T1&, const T2&, F) | ||
{ | ||
return true; | ||
} | ||
template <std::size_t N, class T1, class T2, class F> | ||
constexpr bool rankwise_equal(with_rank<N>, const T1& x, const T2& y, F func) | ||
{ | ||
bool match = true; | ||
|
||
for (std::size_t r = 0; r < N; r++) { | ||
match = match && common_integral_compare(func(x, r), func(y, r)); | ||
} | ||
|
||
return match; | ||
} | ||
|
||
constexpr struct | ||
{ | ||
template <class T, class I> | ||
constexpr auto operator()(const T& x, I i) const | ||
{ | ||
return x.extent(i); | ||
} | ||
} extent; | ||
|
||
constexpr struct | ||
{ | ||
template <class T, class I> | ||
constexpr auto operator()(const T& x, I i) const | ||
{ | ||
return x.stride(i); | ||
} | ||
} stride; | ||
|
||
} // namespace detail | ||
} // namespace MDSPAN_IMPL_STANDARD_NAMESPACE |
Oops, something went wrong.