C++ Logo

std-proposals

Advanced search

Re: Pure value templates

From: Ramkumar Ramachandra <artagnon_at_[hidden]>
Date: Mon, 21 Sep 2020 22:44:05 +0200
There's however a problem doing that with my code:

```
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_at_[hidden]>
wrote:

> Ah, thanks!
>
> R.
>
> On Mon, Sep 21, 2020 at 10:36 PM Jason McKesson via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> On Mon, Sep 21, 2020 at 3:29 PM Ramkumar Ramachandra via Std-Proposals
>> <std-proposals_at_[hidden]> 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_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>

Received on 2020-09-21 15:44:47