On Sun, Jan 23, 2022 at 11:59 AM Avi Kivity <avi@scylladb.com> wrote:


On 1/19/22 19:25, Михаил Найденов via Std-Proposals wrote:
> Hello,
> I have written a small proposal, based on a recent discussion
> (https://lists.isocpp.org/std-proposals/2022/01/3472.php)
>
> Thanks
>

>
> This paper suggest to use the concept, constraining a type to query
> what its members are.
>
> template<class T>
> concept SomeClasses = requires(T t){
>   typename T::type;                      //< `type` MUST BE a type
>   t.template doGreatWork<std::string>(); //< `doGreatWork` MUST BE a
> function template
> }
>
> template<SomeClasses AnyClass>
> void someGreatCode(AnyClass c)
> {
>    AnyClass::type t;             //< proposed `type` IS A type, no
> disambiguation needed
>    // use t
>    c.doGreatWork<std::string>(); //< proposed `doGreatWork` IS A
> function template, no disambiguation needed
>    ...
> }
>

What about optional constraints?


Say


template <typename T>
concept SomeOtherClasses = SomeClasses<T> || std::same_as<T, int>


template<SomeOtherClasses AnyClass>
void someOtherGreatCode(AnyClass c)


How is the compiler supposed to react to AnyClass::type? I suppose it
can fall back to requiring a typename. But then I think the proposal
should list the conditions under which the code is allowed to drop the
typename, so we can expect code that compiles under one compiler to
compile under all.

I think, even in this case, typename should not be needed, because if in one instantiation the name is a type, unless concexpr-if is used, it must be in all.
In this example the int path will fail to compile anyway.

@Jason McKesson
To be honest, avoiding `template` is much more of value, because it has real consequences in how we design APIs at the moment (the fact that we must take into accumet, the user will have a massively more verbose experience when the template is member) 
As for typename, considering right now we have a hard-coded list when it is not required, having a more general "solution" that covers all cases is valuable I believe as well.