C ++ concepts: wrong reference to function concept

I tried this small piece of code, which I modified from the Concepts Technical Spec:

  template < typename T >
    concept bool C_Object() {
      return requires {
        T();
      };
    }

  template < typename Object >
  requires C_Object<Object>
  class  Foo {
    public:
      Object  test;
  };

struct Component {
  int data;
  Component() : data(0) {}
};

int main() {
  Foo<Component> test;
  return 0;
}

But I get this error:

test.cpp:10:12: error: invalid reference to function concepttemplate<class T> concept bool C_Object()’
   requires C_Object<Object>
            ^~~~~~~~~~~~~~~~
test.cpp: In functionint main()’:
test.cpp:26:16: error: template constraint failure
   Foo<Component> test;
                ^
test.cpp:26:16: note:   constraints not satisfied
test.cpp:26:16: note: ill-formed constraint

The first time I try a new version of C ++ concepts, where am I missing?

thank

Excellent day

+4
source share
1 answer

This definition:

template < typename T >
concept bool C_Object() {
  return requires {
    T();
  };
}

defines C_Objectas a concept of function. It:

template < typename Object >
requires C_Object<Object>
class Foo {
public:
  Object test;
};

uses C_Objectas if it were the concept of a variable. In the require condition, you must use ()to call functions:

template < typename Object >
requires C_Object<Object>()
class Foo {
public:
  Object test;
};

"terse" placeholder Object, :

template < C_Object Object >
class Foo {
public:
  Object test;
};
+4

Source: https://habr.com/ru/post/1662174/


All Articles