result_of_example.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // (C) Copyright Douglas Gregor 2003-2004.
  2. // (C) Copyright Tobias Schwinger
  3. //
  4. // Use modification and distribution are subject to the boost Software License,
  5. // Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt).
  6. //------------------------------------------------------------------------------
  7. // This file is a modified copy of the original Boost.ResultOf test-suite.
  8. // See result_of.hpp in this directory for details.
  9. #include "result_of.hpp"
  10. #include <utility>
  11. #include <boost/static_assert.hpp>
  12. #include <boost/type_traits/is_same.hpp>
  13. struct int_result_type { typedef int result_type; };
  14. struct int_result_of
  15. {
  16. template<typename F> struct result { typedef int type; };
  17. };
  18. struct int_result_type_and_float_result_of
  19. {
  20. typedef int result_type;
  21. template<typename F> struct result { typedef float type; };
  22. };
  23. struct X {};
  24. int main()
  25. {
  26. using namespace boost;
  27. namespace e = example;
  28. typedef int (*func_ptr)(float, double);
  29. typedef int (&func_ref)(float, double);
  30. typedef int (X::*mem_func_ptr)(float);
  31. typedef int (X::*mem_func_ptr_c)(float) const;
  32. typedef int (X::*mem_func_ptr_v)(float) volatile;
  33. typedef int (X::*mem_func_ptr_cv)(float) const volatile;
  34. BOOST_STATIC_ASSERT((is_same<e::result_of<int_result_type(float)>::type, int>::value));
  35. BOOST_STATIC_ASSERT((is_same<e::result_of<int_result_of(double)>::type, int>::value));
  36. BOOST_STATIC_ASSERT((is_same<e::result_of<int_result_of(void)>::type, void>::value));
  37. BOOST_STATIC_ASSERT((is_same<e::result_of<const int_result_of(double)>::type, int>::value));
  38. BOOST_STATIC_ASSERT((is_same<e::result_of<volatile int_result_of(void)>::type, void>::value));
  39. BOOST_STATIC_ASSERT((is_same<e::result_of<int_result_type_and_float_result_of(char)>::type, int>::value));
  40. BOOST_STATIC_ASSERT((is_same<e::result_of<func_ptr(char, float)>::type, int>::value));
  41. BOOST_STATIC_ASSERT((is_same<e::result_of<func_ref(char, float)>::type, int>::value));
  42. BOOST_STATIC_ASSERT((is_same<e::result_of<mem_func_ptr(X,char)>::type, int>::value));
  43. BOOST_STATIC_ASSERT((is_same<e::result_of<mem_func_ptr_c(X,char)>::type, int>::value));
  44. BOOST_STATIC_ASSERT((is_same<e::result_of<mem_func_ptr_v(X,char)>::type, int>::value));
  45. BOOST_STATIC_ASSERT((is_same<e::result_of<mem_func_ptr_cv(X,char)>::type, int>::value));
  46. return 0;
  47. }