On Mon, 21 Sep 2020 at 22:44, Ramkumar Ramachandra via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
There's however a problem doing that with my code:

Better to compute the extent in a constexpr function I think:

https://godbolt.org/z/747csf
 

```
template <typename T>constexpr std::pair<TableEntry<i32 T::*> *, size_t> M;

template <>
constexpr inline auto M<Page> = std::make_pair(PageTable, std::extent_v<decltype(PageTable)>);
template <>
constexpr inline auto M<Layer> = std::make_pair(LayerTable, std::extent_v<decltype(LayerTable)>);
template <>
constexpr inline auto M<Line> = std::make_pair(LineTable, std::extent_v<decltype(LineTable)>);
template <>
constexpr inline auto M<Point> = std::make_pair(PointTable, std::extent_v<decltype(PointTable)>);
```

If I factor out the std::extent_v<decltype(...)> into an auto template, it picks the incorrect type (a pointer, as opposed to a sized-array), and I always get size 0. Any suggestions?

R.

On Mon, Sep 21, 2020 at 10:38 PM Ramkumar Ramachandra <artagnon@gmail.com> wrote:
Ah, thanks!

R.

On Mon, Sep 21, 2020 at 10:36 PM Jason McKesson via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
On Mon, Sep 21, 2020 at 3:29 PM Ramkumar Ramachandra via Std-Proposals
<std-proposals@lists.isocpp.org> wrote:
>
> I would like to propose:
>
> ```
> template <typename T = decltype(V), T V>
> constexpr auto Sz = std::extent_v(V);
> ```

That's a circular definition. The compiler can't know what `V` is
without knowing what `T` is and vice-versa.

Equally importantly, I'm pretty sure C++17 gives us similar
functionality as follows:

```
template<auto V>
constexpr auto Sz = std::extent_v<decltype(V)>;
```
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals


--
Richard Hodges
office: +442032898513
home: +376841522
mobile: +376380212