4

I'm currently testing the visual studio implementation of c++20 concepts.

The following concept works fine:

template <typename Cmd, typename T>
concept HasApplyState = requires (Cmd c, T x) { {c.apply_state(x)}->bool; };

as long as apply_state() method is public.

But, is there a way to grant access to protected members in requires expressions ?

Imagine a case of a template class declaration with a policy template parameter intended to be a base class:

template <typename T, typename Policy, bool = HasApplyState<Policy, T> >
class MyClass : protected Policy
{
    ...
};
template <typename T, typename Policy>
class MyClass<T, Policy, false> : protected Policy, protected DefaultApplyStateInterface<T>
{
    ...
};

I would like to know if MyClass will have access to apply_state() that may be protected.

Is that a limitation of the c++20 concepts design ?

sebrockm
  • 5,733
  • 2
  • 16
  • 39
JLM
  • 183
  • 6

0 Answers0