Once again, why do we need the size?
Shall we check the size?
Via static_assert?
During runtime?
In the proposed std::get for C arrays, AIUI, the size would be part of the signature. It would look like this:
template<size_t X, class T, size_t N> requires (X < N)
constexpr T& get(T (&arr)[N]) noexcept {
return arr[X];
}
template<size_t X, class T, size_t N> requires (X < N)
constexpr T&& get(T (&&arr)[N]) noexcept {
return std::move(arr[X]);
}
template<size_t X, class T, size_t N> requires (X < N)
constexpr const T& get(const T (&arr)[N]) noexcept {
return arr[X];
}
template<size_t X, class T, size_t N> requires (X < N)
constexpr const T&& get(const T (&&arr)[N]) noexcept {
return std::move(arr[X]);
}
and then you could do things like
void f(auto& t) requires requires { std::get<1>(t); } { puts("yes"); }
void f(auto&) { puts("no"); }
int main() {
std::tuple<int> t; std::tuple<int, int> u; f(t); f(u); // prints "no yes"
int a[1]; int b[2]; f(a); f(b); // prints "no yes"
}
–Arthur