fork download
  1. #include <boost/fusion/adapted/struct/define_struct.hpp>
  2. #include <boost/mpl/contains.hpp>
  3.  
  4. BOOST_FUSION_DEFINE_STRUCT(
  5. (your_namespace), foo,
  6. (int, a)
  7. (char, c))
  8.  
  9. template<typename source_type, typename search_type>
  10. struct has_type
  11. {
  12. typedef typename boost::mpl::contains<source_type, search_type>::type value_type;
  13. static const bool value = value_type::value;
  14. };
  15.  
  16. #include <iostream>
  17.  
  18. int main()
  19. {
  20. bool foo_has_int_pointer = has_type<your_namespace::foo, int*>::value;
  21. bool foo_has_int = has_type<your_namespace::foo, int>::value;
  22.  
  23. std::cout << "foo_has_int_pointer: " << foo_has_int_pointer << "\n";
  24. std::cout << "foo_has_int: " << foo_has_int << "\n";
  25.  
  26. your_namespace::foo my_foo;
  27.  
  28. my_foo.a = 10;
  29. my_foo.c = 'x';
  30.  
  31. std::cout << "my_foo: " << my_foo.a << ", " << my_foo.c;
  32. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
foo_has_int_pointer: 0
foo_has_int: 1
my_foo: 10, x