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