function_traits_test.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // (C) Copyright John Maddock 2000.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifdef TEST_STD
  6. # include <type_traits>
  7. #else
  8. # include <boost/type_traits/function_traits.hpp>
  9. #endif
  10. #include "test.hpp"
  11. #include "check_type.hpp"
  12. #include "check_integral_constant.hpp"
  13. typedef void(pf_zero1)();
  14. typedef int(pf_zero2)();
  15. typedef const int& (pf_zero3)();
  16. typedef void(pf_one1)(int);
  17. typedef int(pf_one2)(int);
  18. typedef const int&(pf_one3)(const int&);
  19. typedef void(pf_two1)(int,int);
  20. typedef int(pf_two2)(int,int);
  21. typedef const int&(pf_two3)(const int&,const int&);
  22. TT_TEST_BEGIN(function_traits)
  23. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_zero1>::arity, 0);
  24. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_zero2>::arity, 0);
  25. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_zero3>::arity, 0);
  26. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_one1>::arity, 1);
  27. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_one2>::arity, 1);
  28. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_one3>::arity, 1);
  29. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_two1>::arity, 2);
  30. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_two2>::arity, 2);
  31. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::function_traits<pf_two3>::arity, 2);
  32. BOOST_CHECK_TYPE(void, ::tt::function_traits<pf_zero1>::result_type);
  33. BOOST_CHECK_TYPE(::tt::function_traits<pf_zero2>::result_type, int);
  34. BOOST_CHECK_TYPE(::tt::function_traits<pf_zero3>::result_type, const int&);
  35. BOOST_CHECK_TYPE(::tt::function_traits<pf_one1>::result_type, void);
  36. BOOST_CHECK_TYPE(::tt::function_traits<pf_one2>::result_type, int);
  37. BOOST_CHECK_TYPE(::tt::function_traits<pf_one3>::result_type, const int&);
  38. BOOST_CHECK_TYPE(::tt::function_traits<pf_two1>::result_type, void);
  39. BOOST_CHECK_TYPE(::tt::function_traits<pf_two2>::result_type, int);
  40. BOOST_CHECK_TYPE(::tt::function_traits<pf_two3>::result_type, const int&);
  41. BOOST_CHECK_TYPE(::tt::function_traits<pf_one1>::arg1_type, int);
  42. BOOST_CHECK_TYPE(::tt::function_traits<pf_one2>::arg1_type, int);
  43. BOOST_CHECK_TYPE(::tt::function_traits<pf_one3>::arg1_type, const int&);
  44. BOOST_CHECK_TYPE(::tt::function_traits<pf_two1>::arg1_type, int);
  45. BOOST_CHECK_TYPE(::tt::function_traits<pf_two2>::arg1_type, int);
  46. BOOST_CHECK_TYPE(::tt::function_traits<pf_two3>::arg1_type, const int&);
  47. BOOST_CHECK_TYPE(::tt::function_traits<pf_two1>::arg2_type, int);
  48. BOOST_CHECK_TYPE(::tt::function_traits<pf_two2>::arg2_type, int);
  49. BOOST_CHECK_TYPE(::tt::function_traits<pf_two3>::arg2_type, const int&);
  50. TT_TEST_END