array_getfail2.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* tests using std::get on boost:array
  2. * (C) Copyright Marshall Clow 2012
  3. * Distributed under the Boost Software License, Version 1.0. (See
  4. * accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <string>
  8. #include <iostream>
  9. #include <boost/array.hpp>
  10. #include <algorithm>
  11. #ifndef BOOST_NO_CXX11_HDR_ARRAY
  12. #include <array>
  13. #endif
  14. #include <boost/core/lightweight_test_trait.hpp>
  15. namespace {
  16. #ifndef BOOST_NO_CXX11_HDR_ARRAY
  17. template< class T >
  18. void RunStdTests()
  19. {
  20. typedef boost::array< T, 5 > test_type;
  21. typedef T arr[5];
  22. test_type test_case; // = { 1, 1, 2, 3, 5 };
  23. T &aRef = std::get<0> ( test_case );
  24. BOOST_TEST ( &*test_case.begin () == &aRef );
  25. const T &caRef = std::get<0> ( test_case );
  26. BOOST_TEST ( &*test_case.cbegin () == &caRef );
  27. }
  28. #endif
  29. template< class T >
  30. void RunBoostTests()
  31. {
  32. typedef boost::array< T, 5 > test_type;
  33. typedef T arr[5];
  34. test_type test_case; // = { 1, 1, 2, 3, 5 };
  35. T &aRef = boost::get<5> ( test_case );
  36. BOOST_TEST ( &*test_case.begin () == &aRef );
  37. }
  38. }
  39. int main()
  40. {
  41. RunBoostTests< bool >();
  42. RunBoostTests< void * >();
  43. RunBoostTests< long double >();
  44. RunBoostTests< std::string >();
  45. #ifndef BOOST_NO_CXX11_HDR_ARRAY
  46. RunStdTests< bool >();
  47. RunStdTests< void * >();
  48. RunStdTests< long double >();
  49. RunStdTests< std::string >();
  50. #endif
  51. return boost::report_errors();
  52. }