C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Function only accepts parameter that will persist

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 04 May 2024 13:52:28 -0700
On Saturday 4 May 2024 10:56:07 GMT-7 Thiago Macieira via Std-Proposals wrote:
> I hope so. There are many programming techniques that get unblocked by
> having the ability to turn formal parameters into constant expressions,
> when run in a constant expression environment.

The specific use-case I have in mind is: write a function that returns a
std::array<char, N> that is the concatenation of the strings passed as the
argument to:

consteval auto concatenate(std::initializer_list<const char *>) // or span

The use-case for this is to create optimal string tables using offsets to the
beginning instead of an array of pointers that the argument is.

I can do it with:

template<size_t... N> consteval auto(const char (&... strings)[N])

Which suffices but doesn't allow extending to a map with string keys to
something else.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Principal Engineer - Intel DCAI Cloud Engineering

Received on 2024-05-04 20:52:35