array.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // (C) Copyright John Maddock 2005.
  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. #ifndef BOOST_TR1_ARRAY_HPP_INCLUDED
  6. # define BOOST_TR1_ARRAY_HPP_INCLUDED
  7. # include <boost/tr1/detail/config.hpp>
  8. #ifdef BOOST_HAS_TR1_ARRAY
  9. # if defined(BOOST_HAS_INCLUDE_NEXT) && !defined(BOOST_TR1_DISABLE_INCLUDE_NEXT)
  10. # include_next BOOST_TR1_HEADER(array)
  11. # else
  12. # include <boost/tr1/detail/config_all.hpp>
  13. # include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(array))
  14. # endif
  15. #else
  16. #include <boost/array.hpp>
  17. #include <boost/static_assert.hpp>
  18. #include <boost/type_traits/integral_constant.hpp>
  19. #include <boost/detail/workaround.hpp>
  20. namespace std{ namespace tr1{
  21. using ::boost::array;
  22. #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582)
  23. // [6.1.3.2] Tuple creation functions
  24. using ::boost::swap;
  25. #endif
  26. #if !defined(BOOST_TR1_USE_OLD_TUPLE)
  27. }} namespace boost{ namespace fusion{
  28. #endif
  29. // [6.2.2.5] Tuple interface to class template array
  30. template <class T> struct tuple_size; // forward declaration
  31. template <int I, class T> struct tuple_element; // forward declaration
  32. template <class T, size_t N>
  33. struct tuple_size< ::boost::array<T, N> >
  34. : public ::boost::integral_constant< ::std::size_t, N>{};
  35. template <int I, class T, size_t N>
  36. struct tuple_element<I, ::boost::array<T, N> >
  37. {
  38. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570))
  39. BOOST_STATIC_ASSERT(I < (int)N);
  40. BOOST_STATIC_ASSERT(I >= 0);
  41. #endif
  42. typedef T type;
  43. };
  44. template <int I, class T, size_t N>
  45. T& get( ::boost::array<T, N>& a)
  46. {
  47. BOOST_STATIC_ASSERT(I < N);
  48. BOOST_STATIC_ASSERT(I >= 0);
  49. return a[I];
  50. }
  51. template <int I, class T, size_t N>
  52. const T& get(const array<T, N>& a)
  53. {
  54. BOOST_STATIC_ASSERT(I < N);
  55. BOOST_STATIC_ASSERT(I >= 0);
  56. return a[I];
  57. }
  58. #if !defined(BOOST_TR1_USE_OLD_TUPLE)
  59. }} namespace std{ namespace tr1{
  60. using ::boost::fusion::tuple_size;
  61. using ::boost::fusion::tuple_element;
  62. using ::boost::fusion::get;
  63. #endif
  64. } } // namespaces
  65. #endif
  66. #endif