
On Fri, 12 Aug 2011 02:31:10 -0700, John Maddock <boost.regex@virgin.net> wrote:
From your description, I think I've done exactly this. E.g.
--8<---------------cut here---------------start------------->8--- template <class U> struct X { // member function void f(int) becomes something like: template <class T> typename enable_if< mpl::and_< is_convertible<T,int> , some_condition_on<U> > >::type f(T x_) { int x = x_; ... } }; --8<---------------cut here---------------end--------------->8---
That works as long as the function has at least one parameter that can be turned into a template, but I have some cases that are operators or else have no parameters.
In case of no-parameter functions or operators, what's wrong with: template <class U> struct T { void f() { f_impl(<static_cast<void *>(0)); } private: template <class T> typename enable_if< mpl::and_< is_convertible<T, void *>, some_condition_on<U> >::type f_impl(T) { .... } };
BTW, it would be great if all these techniques could be added to the enable_if docs.
+1 It would be great if all the docs had a best-practices section and a commonly-encountered-techniques section. -Mostafa