no need to deduce the size, I would do it like this:

#include <cstdint>

template<std::size_t IX, typename T>
auto const &get(T const *a){
return a[IX];
}

int main(){
int x[100] = { 0, 1, 2, 3 };

return get<3>(x);
}





On Mon, Feb 28, 2022 at 8:56 PM Giuseppe D'Angelo via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
On 28/02/2022 17:47, Paolo Di Giglio via Std-Proposals wrote:
>
> template <std::size_t Idx, typename T, std::size_t N>
> constexpr T& get(T (&arr)[N]) noexcept
> {
>      static_assert(Idx < N, "Index out of bounds");
>      return arr[Idx];
> }
>
> As far as I know, it's not possible to pass a C-style array by value to
> a function nor to return one from a function. So I think there's no need
> for a r-value reference overload.

Pedantically, there's still the need, as you _can_ form rvalue
references to arrays (and the array type can be hidden behind a typedef,
so it's not "obvious").

E.g. a prvalue array can be formed like this:

   using A = int[3];
   get<1>(A{1,2,3})

And a xvalue like this:

   A a = {1,2,3};
   get<1>(std::move(a));

P2165 is related to this proposal, because by putting get overload in
namespace std, P2165 would make this work:

   int a[] = {1,2,3};
   std::tuple<int, int, int> t = a;


My 2 c,
--
Giuseppe D'Angelo

--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals