假设模板类的成员不应该被实例化,除非它们被使用.
但是,这个示例似乎实例化了do_something成员,并且enable_if失败了(如果我们实例化了 – 但是AFAIK,我们没有这样做).
但是,这个示例似乎实例化了do_something成员,并且enable_if失败了(如果我们实例化了 – 但是AFAIK,我们没有这样做).
我错过了一些非常基本的东西吗?
#include <string> #include <boost/utility.hpp> struct some_policy { typedef boost::integral_constant<bool,false> condition; }; struct other_policy { typedef boost::integral_constant<bool,true> condition; }; template <typename policy> class test { void do_something(typename boost::enable_if<typename policy::condition>::type* = 0) {} }; int main() { test<other_policy> p1; test<some_policy> p2; }