ViennaCL - The Vienna Computing Library  1.2.0
range.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_RANGE_HPP_
2 #define VIENNACL_RANGE_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2011, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8 
9  -----------------
10  ViennaCL - The Vienna Computing Library
11  -----------------
12 
13  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
14 
15  (A list of authors and contributors can be found in the PDF manual)
16 
17  License: MIT (X11), see file LICENSE in the base directory
18 ============================================================================= */
19 
24 #include <vector>
25 #include <stddef.h>
26 #include <assert.h>
27 #include "viennacl/forwards.h"
28 
29 namespace viennacl
30 {
31 
36  template <typename SizeType /* see forwards.h for default argument*/,
37  typename DistanceType /* see forwards.h for default argument*/>
39  {
40  public:
41  typedef SizeType size_type;
42  typedef DistanceType difference_type;
46 
47  basic_range() : start_(0), size_(0) {}
48  basic_range(size_type start_index, size_type stop_index) : start_(start_index), size_(stop_index - start_index)
49  {
50  assert(start_index <= stop_index);
51  }
52 
53 
54  size_type start() const { return start_; }
55  size_type size() const { return size_; }
56 
58  {
59  assert(i < size());
60  return start_ + i;
61  }
63 
64  bool operator==(const basic_range & r) const { return (start_ == r.start_) && (size_ == r.size_); }
65  bool operator!=(const basic_range & r) const { return !(*this == r); }
66 
67  private:
68  size_type start_;
69  size_type size_;
70  };
71 
72 
73 }
74 
75 #endif