C++ Logo

std-proposals

Advanced search

Re: Remove non-type template limitations for consteval functions

From: Bastien penavayre <bastienpenava_at_[hidden]>
Date: Wed, 24 Feb 2021 19:24:20 +0100
On 24/02/2021 12:57, Robert J. Simpson via Std-Proposals wrote:
> One of the requirements is that types must be comparable and in the case
of non-type templates that means comparing values. E.g. if you have a
'const char*' value then what does it mean for two of these values to be
equal?

Yes indeed and the reason why we needed comparable types is that we can
separate instantiation of a template and its usage.

For instance, we can:
- prototype a template
- use it
- give its definition later / give it in a different TU and instantiate it
with the desired value

template<auto T>
void func();

auto func_int = &func<42>;
template<auto T>
void func() {}

//or in different TU
template<auto T>
void func();

template<>
void func<42>();

But this isn't the case for consteval function as can't use them before
they're defined nor get their address.

Therefor for a consteval function the comparable requirement isn't meaning
full, it's just a leftover of previous unrelated constrains.

Received on 2021-02-24 12:21:49