Home > Mobile >  How to declare concept function signature with a template type?
How to declare concept function signature with a template type?

Time:01-07

Is there a way to have a concept function signature that has a template argument?

Something like this:

template<typename SomeTypeT, typename U>
concept SomeType = requires(SomeTypeT s) {
    { s.SomeFunction<U>() };
};

?

CodePudding user response:

The shown concept definition works, except that you need to tell the compiler that SomeFunction is a template:

template<typename SomeTypeT, typename U>
concept SomeType = requires(SomeTypeT s) {
    { s.template SomeFunction<U>() };
};

This is always necessary if you want to reference a template member of a dependent name in a template definition, not specific to concepts. When parsing the definition, the compiler doesn't know yet what type s is and so can't know that SomeFunction is supposed to be a template. But it needs to know, since the meaning of the angle brackets and the whole expression can dependent on it.

  •  Tags:  
  • Related