tuple.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // tuple.hpp - Boost Tuple Library --------------------------------------
  2. // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // For more information, see http://www.boost.org
  8. // -----------------------------------------------------------------
  9. #ifndef BOOST_TUPLE_HPP
  10. #define BOOST_TUPLE_HPP
  11. #if defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730
  12. // Work around a compiler bug.
  13. // boost::python::tuple has to be seen by the compiler before the
  14. // boost::tuple class template.
  15. namespace boost { namespace python { class tuple; }}
  16. #endif
  17. #include "boost/config.hpp"
  18. #include "boost/static_assert.hpp"
  19. #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  20. // The MSVC version
  21. #include "boost/tuple/detail/tuple_basic_no_partial_spec.hpp"
  22. #else
  23. // other compilers
  24. #include "boost/ref.hpp"
  25. #include "boost/tuple/detail/tuple_basic.hpp"
  26. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  27. namespace boost {
  28. using tuples::tuple;
  29. using tuples::make_tuple;
  30. using tuples::tie;
  31. #if !defined(BOOST_NO_USING_TEMPLATE)
  32. using tuples::get;
  33. #elif !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  34. //
  35. // The "using tuples::get" statement causes the
  36. // Borland compiler to ICE, use forwarding
  37. // functions instead:
  38. //
  39. template<int N, class HT, class TT>
  40. inline typename tuples::access_traits<
  41. typename tuples::element<N, tuples::cons<HT, TT> >::type
  42. >::non_const_type
  43. get(tuples::cons<HT, TT>& c) {
  44. return tuples::get<N,HT,TT>(c);
  45. }
  46. // get function for const cons-lists, returns a const reference to
  47. // the element. If the element is a reference, returns the reference
  48. // as such (that is, can return a non-const reference)
  49. template<int N, class HT, class TT>
  50. inline typename tuples::access_traits<
  51. typename tuples::element<N, tuples::cons<HT, TT> >::type
  52. >::const_type
  53. get(const tuples::cons<HT, TT>& c) {
  54. return tuples::get<N,HT,TT>(c);
  55. }
  56. #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  57. //
  58. // MSVC, using declarations don't mix with templates well,
  59. // so use forwarding functions instead:
  60. //
  61. template<int N, typename Head, typename Tail>
  62. typename tuples::detail::element_ref<N, tuples::cons<Head, Tail> >::RET
  63. get(tuples::cons<Head, Tail>& t, tuples::detail::workaround_holder<N>* = 0)
  64. {
  65. return tuples::detail::get_class<N>::get(t);
  66. }
  67. template<int N, typename Head, typename Tail>
  68. typename tuples::detail::element_const_ref<N, tuples::cons<Head, Tail> >::RET
  69. get(const tuples::cons<Head, Tail>& t, tuples::detail::workaround_holder<N>* = 0)
  70. {
  71. return tuples::detail::get_class<N>::get(t);
  72. }
  73. #endif // BOOST_NO_USING_TEMPLATE
  74. } // end namespace boost
  75. #endif // BOOST_TUPLE_HPP