#include #include #include struct check : boost::static_visitor<> { template void operator() (T const& val) const { if (val != 0) throw std::runtime_error("invalid"); } }; int main() { typedef boost::variant variant_type; variant_type v(0); boost::apply_visitor(check(), v); return 0; }