ViennaCL - The Vienna Computing Library  1.5.2
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-2014, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the PDF manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
25 #include <vector>
26 #include <stddef.h>
27 #include <assert.h>
28 #include "viennacl/forwards.h"
29 
30 namespace viennacl
31 {
32 
37  template <typename SizeType /* see forwards.h for default argument*/,
38  typename DistanceType /* see forwards.h for default argument*/>
39  class basic_range
40  {
41  public:
42  typedef SizeType size_type;
43  typedef DistanceType difference_type;
44  typedef size_type value_type;
45  typedef value_type const_reference;
46  typedef const_reference reference;
47 
48  basic_range() : start_(0), size_(0) {}
49  basic_range(size_type start_index, size_type stop_index) : start_(start_index), size_(stop_index - start_index)
50  {
51  assert(start_index <= stop_index);
52  }
53 
54 
55  size_type start() const { return start_; }
56  size_type size() const { return size_; }
57 
58  const_reference operator()(size_type i) const
59  {
60  assert(i < size());
61  return start_ + i;
62  }
63  const_reference operator[](size_type i) const { return operator()(i); }
64 
65  bool operator==(const basic_range & r) const { return (start_ == r.start_) && (size_ == r.size_); }
66  bool operator!=(const basic_range & r) const { return !(*this == r); }
67 
68  private:
69  size_type start_;
70  size_type size_;
71  };
72 
73 
74 }
75 
76 #endif
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:339
size_type start() const
Definition: range.hpp:55
const_reference reference
Definition: range.hpp:46
This file provides the forward declarations for the main types used within ViennaCL.
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
size_type size() const
Definition: range.hpp:56
bool operator==(const basic_range &r) const
Definition: range.hpp:65
size_type value_type
Definition: range.hpp:44
SizeType size_type
Definition: range.hpp:42
bool operator!=(const basic_range &r) const
Definition: range.hpp:66
DistanceType difference_type
Definition: range.hpp:43
value_type const_reference
Definition: range.hpp:45
const_reference operator[](size_type i) const
Definition: range.hpp:63
basic_range(size_type start_index, size_type stop_index)
Definition: range.hpp:49
basic_range()
Definition: range.hpp:48
const_reference operator()(size_type i) const
Definition: range.hpp:58