template // Detection helper struct struct can_eat // Detects presence of non-const member function void eat() { private: template struct SFINAE {}; template static char Test(SFINAE*); template static int Test(...); public: static constexpr bool value = sizeof(Test(0)) == sizeof(char); }; struct potato { void eat(); }; struct brick {}; template class FoodBox { //Using static assertion to prohibit non-edible types static_assert(can_eat::value, "Only edible items are allowed in foodbox"); //Rest of class definition }; int main() { FoodBox lunch; //Following leads to compile-time error //FoodBox practical_joke; }