Date: Sun, 23 Jan 2022 11:59:33 +0200
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.
> 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.
Received on 2022-01-23 09:59:36