@ UncleBens: не хотел редактировать ваше сообщение, вот пример кода (надеюсь, созрел для копирования / вставки), поместите его в свой пост и прокомментируйте этот ответ, чтобы я мог удалить его:)
template <class T>
class HasPrint1
{
public:
struct type
{
enum { value = ( sizeof(dummy((T*)0)) == sizeof(yes_t) ) };
};
typedef char yes_t;
struct no_t { yes_t[2] m; };
template <class C>
static yes_t dummy(C*, size_t = sizeof(&C::print1));
static no_t dummy(...);
};
// same for HasPrint2
template <class T>
boost::enable_if< HasPrint1<T> > Print(const T& t) { t.print1(); }
template <class T>
boost::enable_if< HasPrint2<T> > Print(const T& t) { t.print2(); }
template <class T>
boost::disable_if< boost::mpl::or_< HasPrint1<T>, HasPrint2<T> > >
Print(const T& t) { std::cout << t << std::endl; }
Я позволил себе добавить опцию disable_if
, чтобы показать сходство с блоком if / else if / else
.
Буду рад некоторым отзывам.