intro.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_VARIABLE_TEMPLATES
  8. int main(){ return 0; }
  9. #else
  10. //[ intro
  11. #include <type_traits>
  12. #include <tuple>
  13. #include <boost/callable_traits.hpp>
  14. namespace ct = boost::callable_traits;
  15. // This function template helps keep our example code neat
  16. template<typename A, typename B>
  17. void assert_same(){ static_assert(std::is_same<A, B>::value, ""); }
  18. // foo is a function object
  19. struct foo {
  20. void operator()(int, char, float) const {}
  21. };
  22. int main() {
  23. // Use args_t to retrieve a parameter list as a std::tuple:
  24. assert_same<
  25. ct::args_t<foo>,
  26. std::tuple<int, char, float>
  27. >();
  28. // has_void_return lets us perform a quick check for a void return type
  29. static_assert(ct::has_void_return<foo>::value, "");
  30. // Detect C-style variadics (ellipses) in a signature (e.g. printf)
  31. static_assert(!ct::has_varargs<foo>::value, "");
  32. // pmf is a pointer-to-member function: void (foo::*)(int, char, float) const
  33. using pmf = decltype(&foo::operator());
  34. // remove_member_const_t lets you remove the const member qualifier
  35. assert_same<
  36. ct::remove_member_const_t<pmf>,
  37. void (foo::*)(int, char, float) /*no const!*/
  38. >();
  39. // Conversely, add_member_const_t adds a const member qualifier
  40. assert_same<
  41. pmf,
  42. ct::add_member_const_t<void (foo::*)(int, char, float)>
  43. >();
  44. // is_const_member_v checks for the presence of member const
  45. static_assert(ct::is_const_member<pmf>::value, "");
  46. }
  47. //]
  48. #endif