Enable member functions of class templates using concepts

  • A+

So I have a concept Fooable:

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

And I have a class template Bar that takes type T as template parameter and I want to enable a member function only if T is Fooable:

template <typename T> class Bar { public:     template // ???         requires Fooable<T>     void MemFun(); }; 

Is it possible in C++17 with concepts TS or in C++2a?


In both the Concepts TS and C++20 designs, functions have an optional trailing requires-clause. So you don't need to make your member function a template to constrain it:

void MemFun() requires Fooable<T>; 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: