Boost logo

Boost :

From: Bjorn Reese (breese_at_[hidden])
Date: 2021-03-24 14:45:46


On 2021-03-24 14:46, Edward Diener via Boost wrote:

> Why are consts ignored in function parameters ? Is not
> void f(int const) different from void f(int) ? In one the argument
> passed can not be changed and in the other it can. How can they be the
> same ?

The standard states in [dcl.fct]/5 that

   "After producing the list of parameter types, any top-level
    cv-qualifiers modifying a parameter type are deleted when forming
    the function type."

>> Then the parameter is not
>> const and you have a mismatch. Can't you use different parameter types
>> and use SFINAE by comparing the two after removing const?
>
> Thanks ! Maybe I can. But to have to do so in such a simple situation
> seems very strange.

You can use C++20 std::type_identity (or roll your own) to prevent the
second T from being deduced. In Richard Smith's example:

template<class T, bool (*F)(std::type_identity_t<T>), int> struct X;
template<class T, bool (*F)(std::type_identity_t<T>)> struct X<T, F, 0> {};
X<char const, nullptr, 0> x;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk