Files
2025-10-25 03:02:53 +03:00

106 lines
3.4 KiB
Markdown

[class.slice]
# 29 Numerics library [[numerics]](./#numerics)
## 29.6 Numeric arrays [[numarray]](numarray#class.slice)
### 29.6.4 Class slice [class.slice]
#### [29.6.4.1](#overview) Overview [[class.slice.overview]](class.slice.overview)
[🔗](#lib:slice)
namespace std {class slice {public: slice();
slice(size_t, size_t, size_t);
slice(const slice&);
size_t start() const;
size_t size() const;
size_t stride() const; friend bool operator==(const slice& x, const slice& y); };}
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8393)
The slice class represents a BLAS-like slice from an array[.](#overview-1.sentence-1)
Such a slice is specified by a starting index, a length, and a
stride[.](#overview-1.sentence-2)[252](#footnote-252 "BLAS stands for Basic Linear Algebra Subprograms. C++ programs can instantiate this class. See, for example, Dongarra, Du Croz, Duff, and Hammerling: A set of Level 3 Basic Linear Algebra Subprograms; Technical Report MCS-P1-0888, Argonne National Laboratory (USA), Mathematics and Computer Science Division, August, 1988.")
[252)](#footnote-252)[252)](#footnoteref-252)
BLAS stands for*Basic Linear Algebra Subprograms*[.](#footnote-252.sentence-1)
C++ programs can instantiate this class[.](#footnote-252.sentence-2)
See, for example,
Dongarra, Du Croz, Duff, and Hammerling:*A set of Level 3 Basic Linear Algebra Subprograms*;
Technical Report MCS-P1-0888,
Argonne National Laboratory (USA),
Mathematics and Computer Science Division,
August, 1988[.](#footnote-252.sentence-3)
#### [29.6.4.2](#cons.slice) Constructors [[cons.slice]](cons.slice)
[🔗](#lib:slice,constructor)
`slice();
slice(size_t start, size_t length, size_t stride);
`
[1](#cons.slice-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8420)
The default constructor is equivalent to slice(0, 0, 0)[.](#cons.slice-1.sentence-1)
A default constructor is provided only to permit the declaration of arrays of slices[.](#cons.slice-1.sentence-2)
The constructor with arguments for a slice takes a start, length, and stride
parameter[.](#cons.slice-1.sentence-3)
[2](#cons.slice-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8426)
[*Example [1](#cons.slice-example-1)*:
slice(3, 8, 2) constructs a slice which selects elements 3,5,7,…,17 from an array[.](#cons.slice-2.sentence-1)
— *end example*]
#### [29.6.4.3](#slice.access) Access functions [[slice.access]](slice.access)
[🔗](#lib:start,slice)
`size_t start() const;
size_t size() const;
size_t stride() const;
`
[1](#slice.access-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8444)
*Returns*: The start, length, or stride specified
by a slice object[.](#slice.access-1.sentence-1)
[2](#slice.access-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8449)
*Complexity*: Constant time[.](#slice.access-2.sentence-1)
#### [29.6.4.4](#slice.ops) Operators [[slice.ops]](slice.ops)
[🔗](#lib:stride,slice_)
`friend bool operator==(const slice& x, const slice& y);
`
[1](#slice.ops-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8462)
*Effects*: Equivalent to:return x.start() == y.start() && x.size() == y.size() && x.stride() == y.stride();