/* * mammal_traits.h * * Created on: May 25, 2009 * Author: mac */ #ifndef _MAMMAL_TRAITS_H_ #define _MAMMAL_TRAITS_H_ struct __yes_struct {}; struct __no_struct {}; template struct teach_traits { typedef __no_struct oktoteach; typedef __yes_struct oktostudy; static bool _canTeach(__no_struct) { return false; } static bool _canTeach(__yes_struct) { return true; } static bool canTeach() { return _canTeach(T()); } virtual void teachClass(T); void doTeachingDespatch(T v, __no_struct); void doTeachingDespatch(T v, __yes_struct); virtual void study(T); void studyDespatch(T v, __no_struct); void studyDespatch(T v, __yes_struct); }; template void teach_traits::teachClass(T v) { typedef typename teach_traits::oktoteach ok; doTeachingDespatch(v, ok()); } template void teach_traits::doTeachingDespatch(T v, __no_struct) { std::cout << "Don't teach" << std::endl; } template void teach_traits::doTeachingDespatch(T v, __yes_struct) { std::cout << "Teaching class" << std::endl; } template void teach_traits::study(T v) { typedef typename teach_traits::oktostudy ok; studyDespatch(v, ok()); } template void teach_traits::studyDespatch(T v, __no_struct) { std::cout << "Don't study" << std::endl; } template void teach_traits::studyDespatch(T v, __yes_struct) { std::cout << "Read books!" << std::endl; } #endif