overview.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*<-
  2. Copyright Barrett Adair 2016-2017
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt)
  5. ->*/
  6. #include <boost/callable_traits/detail/config.hpp>
  7. #ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
  8. int main(){}
  9. #else
  10. //[ overview
  11. #include <boost/callable_traits.hpp>
  12. #include <type_traits>
  13. #include <tuple>
  14. using std::is_same;
  15. using std::tuple;
  16. using namespace boost::callable_traits;
  17. struct number {
  18. int value;
  19. int add(int n) const { return value + n; }
  20. };
  21. using pmf = decltype(&number::add);
  22. //` Manipulate member functions pointers with ease:
  23. static_assert(is_same<
  24. remove_member_const_t<pmf>,
  25. int(number::*)(int)
  26. >{}, "");
  27. static_assert(is_same<
  28. add_member_volatile_t<pmf>,
  29. int(number::*)(int) const volatile
  30. >{}, "");
  31. static_assert(is_same<
  32. class_of_t<pmf>,
  33. number
  34. >{}, "");
  35. //` INVOKE-aware metafunctions:
  36. static_assert(is_same<
  37. args_t<pmf>,
  38. tuple<const number&, int>
  39. >{}, "");
  40. static_assert(is_same<
  41. return_type_t<pmf>,
  42. int
  43. >{}, "");
  44. static_assert(is_same<
  45. function_type_t<pmf>,
  46. int(const number&, int)
  47. >{}, "");
  48. static_assert(is_same<
  49. qualified_class_of_t<pmf>,
  50. const number&
  51. >{}, "");
  52. //` Here are a few other trait examples:
  53. static_assert(is_const_member<pmf>{}, "");
  54. static_assert(!is_volatile_member<pmf>{}, "");
  55. static_assert(!has_void_return<pmf>{}, "");
  56. static_assert(!has_varargs<pmf>{}, "");
  57. //]
  58. int main() {}
  59. #endif