at.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef BOOST_MPL_VECTOR_AUX_AT_HPP_INCLUDED
  2. #define BOOST_MPL_VECTOR_AUX_AT_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/at_fwd.hpp>
  14. #include <boost/mpl/vector/aux_/tag.hpp>
  15. #include <boost/mpl/long.hpp>
  16. #include <boost/mpl/void.hpp>
  17. #include <boost/mpl/aux_/nttp_decl.hpp>
  18. #include <boost/mpl/aux_/type_wrapper.hpp>
  19. #include <boost/mpl/aux_/value_wknd.hpp>
  20. #include <boost/mpl/aux_/config/typeof.hpp>
  21. #include <boost/mpl/aux_/config/ctps.hpp>
  22. namespace boost { namespace mpl {
  23. #if defined(BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES)
  24. template< typename Vector, long n_ >
  25. struct v_at_impl
  26. {
  27. typedef long_< (Vector::lower_bound_::value + n_) > index_;
  28. typedef __typeof__( Vector::item_(index_()) ) type;
  29. };
  30. template< typename Vector, long n_ >
  31. struct v_at
  32. : aux::wrapped_type< typename v_at_impl<Vector,n_>::type >
  33. {
  34. };
  35. template<>
  36. struct at_impl< aux::vector_tag >
  37. {
  38. template< typename Vector, typename N > struct apply
  39. : v_at<
  40. Vector
  41. , BOOST_MPL_AUX_VALUE_WKND(N)::value
  42. >
  43. {
  44. };
  45. };
  46. #else
  47. # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
  48. && !defined(BOOST_MPL_CFG_NO_NONTYPE_TEMPLATE_PARTIAL_SPEC)
  49. template< typename Vector, BOOST_MPL_AUX_NTTP_DECL(long, n_) > struct v_at;
  50. template< BOOST_MPL_AUX_NTTP_DECL(long, n_) >
  51. struct at_impl< aux::vector_tag<n_> >
  52. {
  53. template< typename Vector, typename N > struct apply
  54. #if !defined(__BORLANDC__)
  55. : v_at<
  56. Vector
  57. , BOOST_MPL_AUX_VALUE_WKND(N)::value
  58. >
  59. {
  60. #else
  61. {
  62. typedef typename v_at<
  63. Vector
  64. , BOOST_MPL_AUX_VALUE_WKND(N)::value
  65. >::type type;
  66. #endif
  67. };
  68. };
  69. # else
  70. namespace aux {
  71. template< BOOST_MPL_AUX_NTTP_DECL(long, n_) > struct v_at_impl
  72. {
  73. template< typename V > struct result_;
  74. };
  75. // to work around ETI, etc.
  76. template<> struct v_at_impl<-1>
  77. {
  78. template< typename V > struct result_
  79. {
  80. typedef void_ type;
  81. };
  82. };
  83. } // namespace aux
  84. template< typename T, BOOST_MPL_AUX_NTTP_DECL(long, n_) >
  85. struct v_at
  86. : aux::v_at_impl<n_>::template result_<T>
  87. {
  88. };
  89. # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  90. #endif // BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES
  91. }}
  92. #endif // BOOST_MPL_VECTOR_AUX_AT_HPP_INCLUDED