array.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  33. template <class T, size_t N>
  34. struct tuple_size< ::boost::array<T, N> >
  35. : public ::boost::integral_constant< ::std::size_t, N>{};
  36. template <int I, class T, size_t N>
  37. struct tuple_element<I, ::boost::array<T, N> >
  38. {
  39. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570))
  40. BOOST_STATIC_ASSERT(I < (int)N);
  41. BOOST_STATIC_ASSERT(I >= 0);
  42. #endif
  43. typedef T type;
  44. };
  45. #endif
  46. template <int I, class T, size_t N>
  47. T& get( ::boost::array<T, N>& a)
  48. {
  49. BOOST_STATIC_ASSERT(I < N);
  50. BOOST_STATIC_ASSERT(I >= 0);
  51. return a[I];
  52. }
  53. template <int I, class T, size_t N>
  54. const T& get(const array<T, N>& a)
  55. {
  56. BOOST_STATIC_ASSERT(I < N);
  57. BOOST_STATIC_ASSERT(I >= 0);
  58. return a[I];
  59. }
  60. #if !defined(BOOST_TR1_USE_OLD_TUPLE)
  61. }} namespace std{ namespace tr1{
  62. using ::boost::fusion::tuple_size;
  63. using ::boost::fusion::tuple_element;
  64. using ::boost::fusion::get;
  65. #endif
  66. } } // namespaces
  67. #endif
  68. #endif