Skip to content

Commit 18e28ff

Browse files
authored
Merge pull request #45771 from Dr15Jones/concepts_propagate_const_array
Use C++ concepts for propagate_const_array
2 parents b4235b6 + 694a34a commit 18e28ff

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

FWCore/Utilities/interface/propagate_const_array.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,10 @@
1818
// forward declarations
1919

2020
namespace edm {
21-
2221
namespace impl {
2322

24-
// check if a type T has a subscript operator T[N]
25-
template <typename, typename = void>
26-
struct has_subscript_operator : std::false_type {};
27-
28-
template <typename T>
29-
struct has_subscript_operator<T, std::void_t<decltype(std::declval<T&>()[0])>> : std::true_type {};
30-
3123
template <typename T>
32-
constexpr auto has_subscript_operator_v = has_subscript_operator<T>::value;
24+
concept ArrayAddressable = requires(T& a) { a[0]; } or std::is_array_v<T>;
3325

3426
// for a type T, return the type of the return value of the subscript operator T[N]
3527
template <typename T, typename = void, typename = void>
@@ -48,7 +40,11 @@ namespace edm {
4840

4941
// for non-array types that implement the subscript operator[], a complete type is needed
5042
template <typename T>
51-
struct subscript_type<T, std::enable_if_t<not std::is_array_v<T>>, std::enable_if_t<has_subscript_operator_v<T>>> {
43+
requires requires {
44+
requires not std::is_array_v<T>;
45+
requires ArrayAddressable<T>;
46+
}
47+
struct subscript_type<T> {
5248
using type = typename std::remove_reference<decltype(std::declval<T&>()[0])>::type;
5349
};
5450

@@ -57,21 +53,21 @@ namespace edm {
5753

5854
} // namespace impl
5955

60-
template <typename T>
56+
template <impl::ArrayAddressable T>
6157
class propagate_const_array;
6258

6359
template <typename T>
6460
constexpr std::decay_t<T>& get_underlying(propagate_const_array<T>&);
6561
template <typename T>
6662
constexpr std::decay_t<T> const& get_underlying(propagate_const_array<T> const&);
6763

68-
template <typename T>
64+
template <impl::ArrayAddressable T>
6965
class propagate_const_array {
7066
public:
7167
friend constexpr std::decay_t<T>& get_underlying<T>(propagate_const_array<T>&);
7268
friend constexpr std::decay_t<T> const& get_underlying<T>(propagate_const_array<T> const&);
7369

74-
template <typename U>
70+
template <impl::ArrayAddressable U>
7571
friend class propagate_const_array;
7672

7773
using element_type = typename impl::subscript_type_t<T>;

0 commit comments

Comments
 (0)