📄 storage.hpp
字号:
BOOST_UBLAS_CHECK (i < size_, bad_index ());
return data_ [i];
}
// Assignment
BOOST_UBLAS_INLINE
shallow_array_adaptor &operator = (const shallow_array_adaptor &a) {
if (this != &a) {
resize (a.size_);
std::copy (a.data_.get (), a.data_.get () + a.size_, data_.get ());
}
return *this;
}
BOOST_UBLAS_INLINE
shallow_array_adaptor &assign_temporary (shallow_array_adaptor &a) {
if (own_ && a.own_)
swap (a);
else
*this = a;
return *this;
}
// Swapping
BOOST_UBLAS_INLINE
void swap (shallow_array_adaptor &a) {
if (this != &a) {
std::swap (size_, a.size_);
std::swap (own_, a.own_);
std::swap (data_, a.data_);
}
}
BOOST_UBLAS_INLINE
friend void swap (shallow_array_adaptor &a1, shallow_array_adaptor &a2) {
a1.swap (a2);
}
// Iterators simply are pointers.
typedef const_pointer const_iterator;
BOOST_UBLAS_INLINE
const_iterator begin () const {
return data_.get ();
}
BOOST_UBLAS_INLINE
const_iterator end () const {
return data_.get () + size_;
}
typedef pointer iterator;
BOOST_UBLAS_INLINE
iterator begin () {
return data_.get ();
}
BOOST_UBLAS_INLINE
iterator end () {
return data_.get () + size_;
}
// Reverse iterators
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
BOOST_UBLAS_INLINE
const_reverse_iterator rbegin () const {
return const_reverse_iterator (end ());
}
BOOST_UBLAS_INLINE
const_reverse_iterator rend () const {
return const_reverse_iterator (begin ());
}
BOOST_UBLAS_INLINE
reverse_iterator rbegin () {
return reverse_iterator (end ());
}
BOOST_UBLAS_INLINE
reverse_iterator rend () {
return reverse_iterator (begin ());
}
private:
size_type size_;
bool own_;
shared_array<value_type> data_;
};
#endif
// Range class
template <class Z, class D>
class basic_range {
typedef basic_range<Z, D> self_type;
public:
typedef Z size_type;
typedef D difference_type;
typedef size_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
typedef const value_type *const_pointer;
typedef value_type *pointer;
// Construction and destruction
BOOST_UBLAS_INLINE
basic_range ():
start_ (0), size_ (0) {}
BOOST_UBLAS_INLINE
basic_range (size_type start, size_type stop):
start_ (start), size_ (stop - start) {
BOOST_UBLAS_CHECK (start_ <= stop, bad_index ());
}
BOOST_UBLAS_INLINE
size_type start () const {
return start_;
}
BOOST_UBLAS_INLINE
size_type size () const {
return size_;
}
// Random Access Container
BOOST_UBLAS_INLINE
size_type max_size () const {
return size_;
}
BOOST_UBLAS_INLINE
bool empty () const {
return size_ == 0;
}
// Element access
BOOST_UBLAS_INLINE
const_reference operator () (size_type i) const {
BOOST_UBLAS_CHECK (i < size_, bad_index ());
return start_ + i;
}
// Composition
BOOST_UBLAS_INLINE
basic_range compose (const basic_range &r) const {
return basic_range (start_ + r.start_, start_ + r.start_ + r.size_);
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const basic_range &r) const {
return start_ == r.start_ && size_ == r.size_;
}
BOOST_UBLAS_INLINE
bool operator != (const basic_range &r) const {
return ! (*this == r);
}
// Iterator types
private:
// Use and index
typedef size_type const_subiterator_type;
public:
#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
typedef indexed_const_iterator<self_type, std::random_access_iterator_tag> const_iterator;
#else
class const_iterator:
public container_const_reference<basic_range>,
public random_access_iterator_base<std::random_access_iterator_tag,
const_iterator, value_type> {
public:
typedef typename basic_range::value_type value_type;
typedef typename basic_range::difference_type difference_type;
typedef typename basic_range::const_reference reference;
typedef typename basic_range::const_pointer pointer;
// Construction and destruction
BOOST_UBLAS_INLINE
const_iterator ():
container_const_reference<basic_range> (), it_ () {}
BOOST_UBLAS_INLINE
const_iterator (const basic_range &r, const const_subiterator_type &it):
container_const_reference<basic_range> (r), it_ (it) {}
// Arithmetic
BOOST_UBLAS_INLINE
const_iterator &operator ++ () {
++ it_;
return *this;
}
BOOST_UBLAS_INLINE
const_iterator &operator -- () {
BOOST_UBLAS_CHECK (it_ > 0, bad_index ());
-- it_;
return *this;
}
BOOST_UBLAS_INLINE
const_iterator &operator += (difference_type n) {
BOOST_UBLAS_CHECK (n >= 0 || it_ >= size_type(-n), bad_index ());
it_ += n;
return *this;
}
BOOST_UBLAS_INLINE
const_iterator &operator -= (difference_type n) {
BOOST_UBLAS_CHECK (n <= 0 || it_ >= size_type(n), bad_index ());
it_ -= n;
return *this;
}
BOOST_UBLAS_INLINE
difference_type operator - (const const_iterator &it) const {
return it_ - it.it_;
}
// Dereference
BOOST_UBLAS_INLINE
const_reference operator * () const {
BOOST_UBLAS_CHECK ((*this) ().start () <= it_, bad_index ());
BOOST_UBLAS_CHECK (it_ < (*this) ().start () + (*this) ().size (), bad_index ());
return it_;
}
BOOST_UBLAS_INLINE
const_reference operator [] (difference_type n) const {
return *(*this + n);
}
// Index
BOOST_UBLAS_INLINE
size_type index () const {
BOOST_UBLAS_CHECK ((*this) ().start () <= it_, bad_index ());
BOOST_UBLAS_CHECK (it_ < (*this) ().start () + (*this) ().size (), bad_index ());
return it_ - (*this) ().start ();
}
// Assignment
BOOST_UBLAS_INLINE
const_iterator &operator = (const const_iterator &it) {
// Comeau recommends...
this->assign (&it ());
it_ = it.it_;
return *this;
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const const_iterator &it) const {
BOOST_UBLAS_CHECK ((*this) () == it (), external_logic ());
return it_ == it.it_;
}
BOOST_UBLAS_INLINE
bool operator < (const const_iterator &it) const {
BOOST_UBLAS_CHECK ((*this) () == it (), external_logic ());
return it_ < it.it_;
}
private:
const_subiterator_type it_;
};
#endif
BOOST_UBLAS_INLINE
const_iterator begin () const {
return const_iterator (*this, start_);
}
BOOST_UBLAS_INLINE
const_iterator end () const {
return const_iterator (*this, start_ + size_);
}
// Reverse iterator
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
BOOST_UBLAS_INLINE
const_reverse_iterator rbegin () const {
return const_reverse_iterator (end ());
}
BOOST_UBLAS_INLINE
const_reverse_iterator rend () const {
return const_reverse_iterator (begin ());
}
BOOST_UBLAS_INLINE
basic_range preprocess (size_type size) const {
if (this != &all_)
return *this;
return basic_range (0, size);
}
static
BOOST_UBLAS_INLINE
const basic_range &all () {
return all_;
}
private:
size_type start_;
size_type size_;
static const basic_range all_;
};
template <class Z, class D>
const basic_range<Z,D> basic_range<Z,D>::all_ (0, size_type (-1));
// Slice class
template <class Z, class D>
class basic_slice {
typedef basic_slice<Z, D> self_type;
public:
typedef Z size_type;
typedef D difference_type;
typedef size_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
typedef const value_type *const_pointer;
typedef value_type *pointer;
// Construction and destruction
BOOST_UBLAS_INLINE
basic_slice ():
start_ (0), stride_ (0), size_ (0) {}
BOOST_UBLAS_INLINE
basic_slice (size_type start, difference_type stride, size_type size):
start_ (start), stride_ (stride), size_ (size) {}
BOOST_UBLAS_INLINE
size_type start () const {
return start_;
}
BOOST_UBLAS_INLINE
difference_type stride () const {
return stride_;
}
BOOST_UBLAS_INLINE
size_type size () const {
return size_;
}
// Random Access Container
BOOST_UBLAS_INLINE
size_type max_size () const {
return size_;
}
BOOST_UBLAS_INLINE
bool empty () const {
return size_ == 0;
}
// Element access
BOOST_UBLAS_INLINE
const_reference operator () (size_type i) const {
BOOST_UBLAS_CHECK (i < size_, bad_index ());
BOOST_UBLAS_CHECK (stride_ >= 0 || start_ >= i * -stride_, bad_index ());
return start_ + i * stride_;
}
// Composition
BOOST_UBLAS_INLINE
basic_slice compose (const basic_range<size_type, difference_type> &r) const {
BOOST_UBLAS_CHECK (stride_ >=0 || start_ >= -stride_ * r.start(), bad_index ());
return basic_slice (start_ + stride_ * r.start (), stride_, r.size ());
}
BOOST_UBLAS_INLINE
basic_slice compose (const basic_slice &s) const {
BOOST_UBLAS_CHECK (stride_ >=0 || start_ >= -stride_ * s.start_, bad_index ());
return basic_slice (start_ + stride_ * s.start_, stride_ * s.stride_, s.size_);
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const basic_slice &s) const {
return start_ == s.start_ && stride_ == s.stride_ && size_ == s.size_;
}
BOOST_UBLAS_INLINE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -