All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
range.hpp
Go to the documentation of this file.
#ifndef VIENNACL_RANGE_HPP_
#define VIENNACL_RANGE_HPP_
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <vector>
#include <stddef.h>
#include <assert.h>
#include "viennacl/forwards.h"
namespace viennacl
{
template<typename SizeT /* see forwards.h for default argument*/,
typename DistanceT /* see forwards.h for default argument*/>
class basic_range
{
public:
typedef SizeT size_type;
typedef DistanceT difference_type;
typedef size_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
basic_range() : start_(0), size_(0) {}
basic_range(size_type start_index, size_type stop_index) : start_(start_index), size_(stop_index - start_index)
{
assert(start_index <= stop_index);
}
size_type start() const { return start_; }
size_type size() const { return size_; }
const_reference operator()(size_type i) const
{
assert(i < size());
return start_ + i;
}
const_reference operator[](size_type i) const { return operator()(i); }
bool operator==(const basic_range & r) const { return (start_ == r.start_) && (size_ == r.size_); }
bool operator!=(const basic_range & r) const { return !(*this == r); }
private:
size_type start_;
size_type size_;
};
}
#endif
viennacl::basic_range::basic_range
basic_range(size_type start_index, size_type stop_index)
Definition: range.hpp:49
viennacl::basic_range::difference_type
DistanceT difference_type
Definition: range.hpp:43
viennacl::basic_range::reference
const_reference reference
Definition: range.hpp:46
viennacl::basic_range::operator()
const_reference operator()(size_type i) const
Definition: range.hpp:58
viennacl::basic_range::start
size_type start() const
Definition: range.hpp:55
viennacl::basic_range::operator!=
bool operator!=(const basic_range &r) const
Definition: range.hpp:66
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::basic_range::value_type
size_type value_type
Definition: range.hpp:44
viennacl::basic_range::basic_range
basic_range()
Definition: range.hpp:48
viennacl::basic_range::operator[]
const_reference operator[](size_type i) const
Definition: range.hpp:63
viennacl::basic_range::const_reference
value_type const_reference
Definition: range.hpp:45
viennacl::basic_range
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:424
viennacl::basic_range::operator==
bool operator==(const basic_range &r) const
Definition: range.hpp:65
viennacl::basic_range::size_type
SizeT size_type
Definition: range.hpp:42
viennacl::basic_range::size
size_type size() const
Definition: range.hpp:56