[clang] [Clang] [C++26] P1306R5: Iterating expansion statements using string injection (PR #208877)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 9 11:52:37 PDT 2026
ordinary-github-user wrote:
am i using template for correctly?
```c++
#include <cstdint>
#include <tuple>
struct RangeIterator
{
std::uint8_t value;
constexpr std::uint8_t operator*()const noexcept { return value; }
constexpr RangeIterator& operator++()noexcept { ++value; return *this; }
constexpr bool operator!=(RangeIterator r)const noexcept { return value != r.value; }
friend constexpr std::uint8_t operator-(RangeIterator l, RangeIterator r) noexcept { return std::uint8_t(l.value - r.value); }
friend constexpr RangeIterator operator-(RangeIterator l, u8 r)noexcept { return { std::uint8_t(l.value - r) }; }
friend constexpr RangeIterator operator+(RangeIterator l, u8 r)noexcept { return { std::uint8_t(l.value + r) }; }
};
template<std::uint8_t End>
struct Range
{
static consteval RangeIterator begin()noexcept { return { 0 }; }
static consteval RangeIterator end()noexcept { return { End }; }
static consteval std::uint8_t size()noexcept { return End; }
template<std::size_t Index>requires(Index < size())consteval friend std::uint8_t get(Range)noexcept { return Index; }
};
namespace std
{
template<std::uint8_t End>
struct tuple_size<Range<End>>
{
static constexpr std::uint8_t value{ End };
};
template<std::size_t Index, std::uint8_t End>
struct tuple_element<Index, Range<End>>
{
using type = std::uint8_t;
};
}
static_assert([]static
{
template for (constexpr auto _ : Range<2>{})
{
static constexpr auto [...c0] { Range<2>{} };
(..., c0);
}
return true;
}());
```
```
error: static assertion expression is not an integral constant expression
1411 | static_assert([]static
| ^~~~~~~~
1412 | {
| ~
1413 | template for (constexpr auto _ : Range<2>{})
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1414 | {
| ~
1415 | static constexpr auto [...c0] { Range<2>{} };
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1416 | (..., c0);
| ~~~~~~~~~~
1417 | }
| ~
1418 | return true;
| ~~~~~~~~~~~~
1419 | }());
| ~~~
1 error generated.
```
https://github.com/llvm/llvm-project/pull/208877
More information about the cfe-commits
mailing list