boost中的range与slice函数简介

来源:互联网 发布:培育发展新动力优化 编辑:程序博客网 时间:2024/06/04 19:47

1 Range<SizeType,DistanceType>

1.1 Description

The class range specifies a range of indicies. The range is a sequence of indices from a start value to stop value. The indices increase by one and exlude the stop value.range can therefore be used to specify ranges of elements from vectors and matrices.

1.2 Example

#include <boost/numeric/ublas/storage.hpp> //range可以确定一组下标的范围,其步长为1,没有办法人为改变。int main () {    using namespace boost::numeric::ublas;    range r (0, 3);    for (unsigned i = 0; i < r.size (); ++ i) {        std::cout << r (i) << std::endl;    }}

1.3 Definition

Defined in the header storage.hpp.

1.4 Model of

Reversible Container.

1.5 Type requirements

None, except for those imposed by the requirements of ReversibleContainer.

1.6 Public base classes

None.

1.7 Members

MemberDescriptionrange (size_type start, size_type stop)Constructs a range of indicies from start to stop (excluded).size_type start () constReturns the beginning of the range.size_type size () constReturns the size of the range.const_reference operator [] (size_type i)constReturns the value start + i of the i-th element.range compose (const range &r) constReturns the composite range from start + r.start() to start + r.start () + r.size ().bool operator == (const range &r) constTests two ranges for equality.bool operator != (const range &r) constTests two ranges for inequality.const_iterator begin () constReturns a const_iterator pointing to the beginningof the range.const_iterator end () constReturns a const_iterator pointing to the end ofthe range.const_reverse_iterator rbegin () constReturns a const_reverse_iterator pointing to thebeginning of the reversedrange.const_reverse_iterator rend () constReturns a const_reverse_iterator pointing to theend of the reversedrange.

1.8 Preconditions

  • start () <= stop ()

2 Slice<SizeType,DistanceType>

2.1 Description

The class slice specifies a 'slice' of indicies. Slices are more generalthen ranges, the stride allows the sequence of indicies to increase and decrease by the specified amount between element.slice can therefore be used to specify slices of element from vectors and matrices.

2.2 Example

#include <boost/numeric/ublas/storage.hpp> //slice的用途和range几乎相同,但是比range更加的通用,其可以指定步长,以及包含的元素个数。int main () {    using namespace boost::numeric::ublas;    slice s (0, 1, 3);    for (unsigned i = 0; i < s.size (); ++ i) {        std::cout << s (i) << std::endl;    }}

2.3 Definition

Defined in the header storage.hpp.

2.4 Model of

Reversible Container.

2.5 Type requirements

None, except for those imposed by the requirements of ReversibleContainer.

2.6 Public base classes

None.

2.7 Members

MemberDescriptionslice (size_type start, size_type stride, size_typesize)Constructs a slice start,start+stride,start+2*stride... withsize elements.size_type start () constReturns the beginning of the slice.size_type stride () constReturns the stride of the slice.size_type size () constReturns the size of the slice.const_reference operator [] (size_type i)constReturns the value start + i * stride of thei-th element.slice compose (const range &r) constReturns the composite slice from start + stride * r.start() to start + stride * (r.start () + r.size ())with stride stride.slice compose (const slice &s) constReturns the composite slice from start + stride * s.start() to start + stride * s.stride () * (s.start () +s.size ()) with stride stride * s.stride ().bool operator == (const slice &s) constTests two slices for equality.bool operator != (const slice &s) constTests two slices for inequality.const_iterator begin () constReturns a const_iterator pointing to the beginningof the slice.const_iterator end () constReturns a const_iterator pointing to the end ofthe slice.const_reverse_iterator rbegin () constReturns a const_reverse_iterator pointing to thebeginning of the reversedslice.const_reverse_iterator rend () constReturns a const_reverse_iterator pointing to theend of the reversedslice.
原创粉丝点击