Skip to content

Commit 087936f

Browse files
committed
Simplify first_of definition
1 parent f3da596 commit 087936f

1 file changed

Lines changed: 23 additions & 41 deletions

File tree

include/experimental/__p2630_bits/submdspan_extents.hpp

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,32 @@ struct index_pair_like<std::array<IdxT, 2>, IndexType> {
132132

133133
// first_of(slice): getting begin of slice specifier range
134134

135+
template <class OffsetType, class ExtentType, class StrideType>
136+
MDSPAN_INLINE_FUNCTION
137+
constexpr OffsetType
138+
first_of(const strided_slice<OffsetType, ExtentType, StrideType>& r) {
139+
return r.offset;
140+
}
141+
135142
#if defined(MDSPAN_ENABLE_P3663)
136143

137-
MDSPAN_TEMPLATE_REQUIRES(
138-
class Integral,
139-
/* requires */(std::is_signed_v<Integral> || std::is_unsigned_v<Integral>)
140-
)
144+
template<class T>
141145
MDSPAN_INLINE_FUNCTION
142-
constexpr Integral first_of(Integral i) {
143-
return i;
146+
constexpr T
147+
first_of([[maybe_unused]] T t) {
148+
if constexpr (std::is_signed_v<T> || std::is_unsigned_v<T>) {
149+
return t;
150+
}
151+
else { // if constexpr (is_constant_wrapper_v<T>) {
152+
static_assert(is_constant_wrapper<T>);
153+
return T{};
154+
}
155+
}
156+
157+
MDSPAN_INLINE_FUNCTION
158+
constexpr auto
159+
first_of([[maybe_unused]] ::MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent_t) {
160+
return cw<size_t(0)>;
144161
}
145162

146163
#else
@@ -178,16 +195,6 @@ constexpr Integral first_of(const Integral &i) {
178195
return i;
179196
}
180197

181-
#endif // MDSPAN_ENABLE_P3663
182-
183-
#if defined(MDSPAN_ENABLE_P3663)
184-
template<auto Value>
185-
MDSPAN_INLINE_FUNCTION
186-
constexpr constant_wrapper<Value>
187-
first_of(constant_wrapper<Value>) {
188-
return {};
189-
}
190-
#else
191198
// NOTE This is technically not conforming.
192199
// Pre-P3663, first_of should work on any integral-constant-like type.
193200
// Replacing the return type "Integral" with auto does not change test results.
@@ -197,20 +204,6 @@ constexpr Integral
197204
first_of(const std::integral_constant<Integral, v>&) {
198205
return integral_constant<Integral, v>();
199206
}
200-
#endif
201-
202-
203-
204-
#if defined(MDSPAN_ENABLE_P3663)
205-
206-
MDSPAN_INLINE_FUNCTION
207-
constexpr
208-
auto
209-
first_of(const ::MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent_t &) {
210-
return cw<size_t(0)>;
211-
}
212-
213-
#else
214207

215208
MDSPAN_INLINE_FUNCTION
216209
constexpr
@@ -219,14 +212,10 @@ first_of(const ::MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent_t &) {
219212
return {};
220213
}
221214

222-
#endif // MDSPAN_ENABLE_P3663
223-
224-
225215
// P3663 doesn't need any of these overloads,
226216
// because its version of first_of will never see pair-like types.
227217
// (The only "contiguous range of indices" slice types it sees are
228218
// full_extent_t and strided_slice with compile-time unit stride.)
229-
#if ! defined(MDSPAN_ENABLE_P3663)
230219

231220
MDSPAN_TEMPLATE_REQUIRES(
232221
class Slice,
@@ -262,13 +251,6 @@ constexpr auto first_of(const std::complex<T> &i) {
262251

263252
#endif
264253

265-
template <class OffsetType, class ExtentType, class StrideType>
266-
MDSPAN_INLINE_FUNCTION
267-
constexpr OffsetType
268-
first_of(const strided_slice<OffsetType, ExtentType, StrideType> &r) {
269-
return r.offset;
270-
}
271-
272254
// last_of(slice): getting end of slice specifier range
273255
// We need however not just the slice but also the extents
274256
// of the original view and which rank from the extents.

0 commit comments

Comments
 (0)