extent_gen.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2002 The Trustees of Indiana University.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Boost.MultiArray Library
  6. // Authors: Ronald Garcia
  7. // Jeremy Siek
  8. // Andrew Lumsdaine
  9. // See http://www.boost.org/libs/multi_array for documentation.
  10. #ifndef BOOST_MULTI_ARRAY_EXTENT_GEN_HPP
  11. #define BOOST_MULTI_ARRAY_EXTENT_GEN_HPP
  12. #include "boost/multi_array/extent_range.hpp"
  13. #include "boost/multi_array/range_list.hpp"
  14. #include "boost/multi_array/types.hpp"
  15. #include "boost/array.hpp"
  16. #include <algorithm>
  17. namespace boost {
  18. namespace detail {
  19. namespace multi_array {
  20. template <std::size_t NumRanges>
  21. class extent_gen {
  22. public:
  23. typedef boost::detail::multi_array::index index;
  24. typedef boost::detail::multi_array::size_type size_type;
  25. typedef extent_range<index,size_type> range;
  26. private:
  27. typedef typename range_list_generator<range,NumRanges>::type range_list;
  28. public:
  29. template <std::size_t Ranges>
  30. struct gen_type {
  31. typedef extent_gen<Ranges> type;
  32. };
  33. range_list ranges_;
  34. extent_gen() { }
  35. // Used by operator[] to expand extent_gens
  36. extent_gen(const extent_gen<NumRanges-1>& rhs,
  37. const range& a_range)
  38. {
  39. std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin());
  40. *ranges_.rbegin() = a_range;
  41. }
  42. extent_gen<NumRanges+1>
  43. operator[](const range& a_range)
  44. {
  45. return extent_gen<NumRanges+1>(*this,a_range);
  46. }
  47. extent_gen<NumRanges+1>
  48. operator[](index idx)
  49. {
  50. return extent_gen<NumRanges+1>(*this,range(0,idx));
  51. }
  52. static extent_gen<0> extents() {
  53. return extent_gen<0>();
  54. }
  55. };
  56. } // namespace multi_array
  57. } // namespace detail
  58. } // namespace boost
  59. #endif