C++ Logo

std-proposals

Advanced search

Pure value templates

From: Ramkumar Ramachandra <artagnon_at_[hidden]>
Date: Mon, 21 Sep 2020 21:28:06 +0200
I would like to propose:

```
template <typename T = decltype(V), T V>
constexpr auto Sz = std::extent_v(V);
```

The motivation for this is to shorten a table lookup like this:

```
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)>);
```

Unfortunately, the template parameters are processed in order, due to which
the above fails. Any idea how one would go about this?

R.

Received on 2020-09-21 14:28:44