00001 #ifndef VIENNACL_RANGE_HPP_ 00002 #define VIENNACL_RANGE_HPP_ 00003 00004 /* ========================================================================= 00005 Copyright (c) 2010-2011, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 00009 ----------------- 00010 ViennaCL - The Vienna Computing Library 00011 ----------------- 00012 00013 Project Head: Karl Rupp rupp@iue.tuwien.ac.at 00014 00015 (A list of authors and contributors can be found in the PDF manual) 00016 00017 License: MIT (X11), see file LICENSE in the base directory 00018 ============================================================================= */ 00019 00024 #include <vector> 00025 #include <stddef.h> 00026 #include <assert.h> 00027 #include "viennacl/forwards.h" 00028 00029 namespace viennacl 00030 { 00031 00036 template <typename SizeType /* see forwards.h for default argument*/, 00037 typename DistanceType /* see forwards.h for default argument*/> 00038 class basic_range 00039 { 00040 public: 00041 typedef SizeType size_type; 00042 typedef DistanceType difference_type; 00043 typedef size_type value_type; 00044 typedef value_type const_reference; 00045 typedef const_reference reference; 00046 00047 basic_range() : start_(0), size_(0) {} 00048 basic_range(size_type start_index, size_type stop_index) : start_(start_index), size_(stop_index - start_index) 00049 { 00050 assert(start_index <= stop_index); 00051 } 00052 00053 00054 size_type start() const { return start_; } 00055 size_type size() const { return size_; } 00056 00057 const_reference operator()(size_type i) const 00058 { 00059 assert(i < size()); 00060 return start_ + i; 00061 } 00062 const_reference operator[](size_type i) const { return operator()(i); } 00063 00064 bool operator==(const basic_range & r) const { return (start_ == r.start_) && (size_ == r.size_); } 00065 bool operator!=(const basic_range & r) const { return !(*this == r); } 00066 00067 private: 00068 size_type start_; 00069 size_type size_; 00070 }; 00071 00072 00073 } 00074 00075 #endif