Note: all that follows uses TS Concepts implementation in GCC 6.1
Say I have a Surface concept as shown below:
template <typename T> concept bool Surface() { return requires(T& t, point2f p, float radius) { { t.move_to(p) }; { t.line_to(p) }; { t.arc(p, radius) };
Now I want to define another Drawable concept that matches any type with a member function:
template <typename S> requires Surface<S>() void draw(S& surface) const;
i.e.
struct triangle { void draw(Surface& surface) const; }; static_assert(Drawable<triangle>(), "");
That is, Drawable is what has the templated const member draw() function, referencing an lvalue link to what meets the requirements of Surface . This is easy enough to indicate in words, but I canβt decide how to do this in C ++ using Concepts TS. The "obvious" syntax does not work:
template <typename T> concept bool Drawable() { return requires(const T& t, Surface& surface) { { t.draw(surface) } -> void; }; }
error: parameter 'auto' is not allowed in this context
Adding a second template parameter allows you to compile the concept, but:
template <typename T, Surface S> concept bool Drawable() { return requires(const T& t, S& s) { { t.draw(s) }; }; } static_assert(Drawable<triangle>(), "");
Error in outputting template argument: could not output template parameter 'S'
now we can only check whether a particular pair of < Drawable , Surface > Drawable concepts, which is not entirely correct. (Type D either has the required member function or not: it does not depend on which Surface we are testing.)
I am sure that it is possible to do what I need, but I can not understand the syntax, and so far there are not many examples online. Does anyone know how to write a definition of a concept that requires a type to have a limited member function?