Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

My Integral concept

42 views
Skip to first unread message

porp...@gmail.com

unread,
Sep 15, 2019, 5:51:15 AM9/15/19
to
Hi,

I've defined the following concept.
But the compiler does not report constraint error with non-integral "Car" type.
Is my concept correct ?
If not, could you please write what should I do to make it correct.
I'm using gcc 7.4.0.

Thank you

template < typename T >
concept bool Integral = requires ( T t ) {
{ std::is_integral<T>::value } -> bool;
};

template < Integral T >
void fun ( T t )
{
}

struct Car {};

int main ()
{
Car c;
fun ( c );
return 0;
}

Juha Nieminen

unread,
Sep 15, 2019, 6:39:41 AM9/15/19
to
porp...@gmail.com wrote:
> I'm using gcc 7.4.0.

The latest version of gcc is 9.2.

Start with that.

Öö Tiib

unread,
Sep 15, 2019, 7:05:06 AM9/15/19
to
The g++ 9.2 also compiles OP's example without constraint errors.
Demo: http://coliru.stacked-crooked.com/a/5e968a4ed8bd8c08

Öö Tiib

unread,
Sep 15, 2019, 7:22:24 AM9/15/19
to
On Sunday, 15 September 2019 12:51:15 UTC+3, porp...@gmail.com wrote:
>
> template < typename T >
> concept bool Integral = requires ( T t ) {
> { std::is_integral<T>::value } -> bool;
> };

I guess you wanted to write here:

template < typename T >
concept Integral = std::is_integral<T>::value;

Bo Persson

unread,
Sep 15, 2019, 7:30:46 AM9/15/19
to
Right.

The problem with the first concept attempt is that
is_integral<Car>::value is still a bool, only with value false.


Bo Persson

porp...@gmail.com

unread,
Sep 21, 2019, 6:43:43 AM9/21/19
to
Thank all of you for answers.
Could you please give me some rules of when to use short form of a concept, like:
template < typename T >
concept Integral = std::is_integral<T>::value;

and when to use a longer one, like:
template < typename T >
concept bool Integral = requires ( T t ) {
{ std::is_integral<T>::value } -> bool;
};

I mean I have only 2 examples above and found others on the internet but I don't get the general rule.

Bo Persson

unread,
Sep 21, 2019, 8:34:38 AM9/21/19
to
The general rule is that the longer form is from the separate Concepts
TS (ISO Technical Specification), while the shorter form looks like what
made into the (still draft) C++20 language.

https://en.cppreference.com/w/cpp/experimental/constraints
https://en.cppreference.com/w/cpp/language/constraints

Then there is the problem of which version, if any, your compiler is
supposed to support. :-)



Bo Persson

0 new messages