array6.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* tests for using class array<> specialization for size 0
  2. * (C) Copyright Alisdair Meredith 2006.
  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. #include <boost/core/lightweight_test_trait.hpp>
  12. namespace {
  13. template< class T >
  14. void RunTests()
  15. {
  16. typedef boost::array< T, 5 > test_type;
  17. typedef T arr[5];
  18. test_type test_case; // = { 1, 1, 2, 3, 5 };
  19. arr &aRef = get_c_array ( test_case );
  20. BOOST_TEST ( &*test_case.begin () == &aRef[0] );
  21. const arr &caRef = get_c_array ( test_case );
  22. typename test_type::const_iterator iter = test_case.begin ();
  23. BOOST_TEST ( &*iter == &caRef[0] );
  24. // Confirm at() throws the std lib defined exception
  25. try {
  26. test_case.at( test_case.size());
  27. BOOST_TEST(false);
  28. }
  29. catch ( const std::out_of_range & ) {}
  30. try {
  31. test_case.at( test_case.size() + 1);
  32. BOOST_TEST(false);
  33. }
  34. catch ( const std::out_of_range & ) {}
  35. try {
  36. test_case.at( test_case.size() + 100);
  37. BOOST_TEST(false);
  38. }
  39. catch ( const std::out_of_range & ) {}
  40. }
  41. }
  42. int main ()
  43. {
  44. RunTests< bool >();
  45. RunTests< void * >();
  46. RunTests< long double >();
  47. RunTests< std::string >();
  48. return boost::report_errors();
  49. }