How to make the boost::apply_visitor (either of two variants) a friend-function of class-visitor?
I have tried the following: friend result_type boost::apply_visitor<>(decltype(*this) &, instruction_type const &);, but this does not work. *this derived from boost::static_visitor (or have using result_type = ...; typedef) and instruction type is the boost::variant of some specific types. *this have all required operator ()-s in private section.
What is the right form of such declaration?
If you insist, you could wrap your actual visitor in a visitor that exposes the required interface, and declare that as a friend of your visitor-impl (that now combines the impl and visitor concepts).
(The "good" (cough) thing here is that there is not need for the
implto be polymorphic or dynamically allocated.)Here's a stratight-forward proof of concept:
And here's how you'd use it with a demo visitor that hides all implementation details:
Of course, it has the cost of needing to instantiate the wrapped visitor at the call site:
See it all Live on Coliru