boost_no_decltype.ipp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // (C) Copyright Beman Dawes 2008
  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. // See http://www.boost.org/libs/config for more information.
  6. // MACRO: BOOST_NO_CXX11_DECLTYPE
  7. // TITLE: C++0x decltype unavailable
  8. // DESCRIPTION: The compiler does not support C++0x decltype
  9. namespace boost_no_cxx11_decltype {
  10. void quiet_warning(int){}
  11. struct test_class
  12. {
  13. test_class() {}
  14. };
  15. test_class get_test_class()
  16. {
  17. return test_class();
  18. }
  19. template<typename F>
  20. void baz(F f)
  21. {
  22. //
  23. // Strangely VC-10 deduces the return type of F
  24. // to be "test_class&". Remove the constructor
  25. // from test_class and then decltype does work OK!!
  26. //
  27. typedef decltype(f()) res;
  28. res r;
  29. }
  30. int test()
  31. {
  32. int i;
  33. decltype(i) j(0);
  34. quiet_warning(j);
  35. decltype(get_test_class()) k;
  36. #ifndef _MSC_VER
  37. // Although the VC++ decltype is buggy, we none the less enable support,
  38. // so don't test the bugs for now!
  39. baz(get_test_class);
  40. #endif
  41. return 0;
  42. }
  43. }