]> git.lyx.org Git - lyx.git/blob - boost/boost/multi_array/extent_gen.hpp
update boost
[lyx.git] / boost / boost / multi_array / extent_gen.hpp
1 // Copyright (C) 2002 Ronald Garcia
2 //
3 // Permission to copy, use, sell and distribute this software is granted
4 // provided this copyright notice appears in all copies. 
5 // Permission to modify the code and to distribute modified code is granted
6 // provided this copyright notice appears in all copies, and a notice 
7 // that the code was modified is included with the copyright notice.
8 //
9 // This software is provided "as is" without express or implied warranty, 
10 // and with no claim as to its suitability for any purpose.
11 //
12
13 #ifndef BOOST_EXTENT_GEN_RG071801_HPP
14 #define BOOST_EXTENT_GEN_RG071801_HPP
15
16 #include "boost/multi_array/extent_range.hpp"
17 #include "boost/multi_array/range_list.hpp"
18 #include "boost/multi_array/types.hpp"
19 #include "boost/array.hpp"
20 #include <algorithm>
21
22 namespace boost {
23 namespace detail {
24 namespace multi_array {
25
26
27 template <std::size_t NumRanges>
28 class extent_gen {
29 public:
30   typedef boost::detail::multi_array::index index;
31   typedef boost::detail::multi_array::size_type size_type;
32 private:
33   typedef extent_range<index,size_type> range;
34   typedef typename range_list_generator<range,NumRanges>::type range_list;
35 public:
36   template <std::size_t Ranges>
37   struct gen_type {
38     typedef extent_gen<Ranges> type;
39   };
40
41   range_list ranges_;
42
43   extent_gen() { }
44
45   // Used by operator[] to expand extent_gens
46   extent_gen(const extent_gen<NumRanges-1>& rhs,
47             const range& a_range)
48   {
49     std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin());
50     *ranges_.rbegin() = a_range;
51   }
52
53   extent_gen<NumRanges+1>
54   operator[](const range& a_range)
55   {
56     return extent_gen<NumRanges+1>(*this,a_range);    
57   }
58
59   extent_gen<NumRanges+1>
60   operator[](index idx)
61   {
62     return extent_gen<NumRanges+1>(*this,range(0,idx));    
63   }    
64
65   static extent_gen<0> extents() {
66     return extent_gen<0>();
67   }
68 };
69
70 } // namespace multi_array
71 } // namespace detail
72 } // namespace boost
73
74
75 #endif // BOOST_EXTENT_GEN_RG071801_HPP