C++ Logo

std-proposals

Advanced search

Re: Forward declaration of concepts

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Sun, 21 Mar 2021 20:17:55 +0100
niedz., 21 mar 2021 o 20:05 Omer Rosler <omer.rosler_at_[hidden]> napisał(a):
>
> It does work, Thank you.
> I wonder if there is a use case for forward declaration of concepts which can't be worked around like so.
>

There are, if you would like to have:

```
template<typename T>
concept tag_type = other_concept<T> && different_concept<T>;
```
There is a subtle difference when you try to order specializations
based on concepts.
If you use a class template then there is no ordering between concepts.

If we have this forward declared concepts, the question is when you
could use them?
Because case like this should be forbidden:

```
template<typename T>
concept tag_type;

template<typename T>
concept tag_type = other_concept<T> && tag_type<T>; //direct recursion
```

> On Sun, Mar 21, 2021 at 4:54 PM Marcin Jaczewski <marcinjaczewski86_at_[hidden]> wrote:
>>
>> But this is not a mery forward declaration but circular definition (like CRTP).
>> This means even if we allow forward declaration it still could not
>> allow recursion there.
>>
>> Edward in other mail said that you can forward `is_tag_impl`, if this
>> will not work (compiler will throw some errors)
>> then the same will be with your example.
>>
>> niedz., 21 mar 2021 o 15:41 Omer Rosler via Std-Proposals
>> <std-proposals_at_[hidden]> napisał(a):
>> >
>> > Is there a reason forward declaration of concepts are not allowed?
>> >
>> > I wanted such feature in the following snippet:
>> >
>> > ```c++
>> > template<typename T>
>> > concept tag_type;
>> > //Use the concept in a template declaration, when instantiated, the concept definition will be avilable
>> > template<template<tag_type> typename ArgsType, template<ArgsType...> typename Templ>
>> > struct template_ {};
>> > template<typename T>
>> > struct is_tag_impl : std::false_type {};
>> > template<template<tag_type> typename ArgsType, template<ArgsType...> typename Templ>
>> > struct is_tag_impl<template_<ArgsType, Templ>> : std::true_type {};
>> >
>> > template<typename T>
>> > concept tag_type = is_tag_impl<T>::value;
>> >
>> >
>> >
>> > ```
>> > --
>> > Std-Proposals mailing list
>> > Std-Proposals_at_[hidden]
>> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2021-03-21 14:18:08