Init
This commit is contained in:
643
cppdraft/template/bitset.md
Normal file
643
cppdraft/template/bitset.md
Normal file
@@ -0,0 +1,643 @@
|
||||
[template.bitset]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.9 Bitsets [[bitset]](bitset#template.bitset)
|
||||
|
||||
### 22.9.2 Class template bitset [template.bitset]
|
||||
|
||||
#### [22.9.2.1](#general) General [[template.bitset.general]](template.bitset.general)
|
||||
|
||||
[ð](#lib:bitset)
|
||||
|
||||
namespace std {template<size_t N> class bitset {public:// bit referenceclass reference {public:constexpr reference(const reference&) = default; constexpr ~reference(); constexpr reference& operator=(bool x) noexcept; // for b[i] = x;constexpr reference& operator=(const reference&) noexcept; // for b[i] = b[j];constexpr bool operator~() const noexcept; // flips the bitconstexpr operator bool() const noexcept; // for x = b[i];constexpr reference& flip() noexcept; // for b[i].flip();}; // [[bitset.cons]](#bitset.cons "22.9.2.2 Constructors"), constructorsconstexpr bitset() noexcept; constexpr bitset(unsigned long long val) noexcept; template<class charT, class traits, class Allocator>constexpr explicit bitset(const basic_string<charT, traits, Allocator>& str, typename basic_string<charT, traits, Allocator>::size_type pos = 0, typename basic_string<charT, traits, Allocator>::size_type n = basic_string<charT, traits, Allocator>::npos,
|
||||
charT zero = charT('0'),
|
||||
charT one = charT('1')); template<class charT, class traits>constexpr explicit bitset( basic_string_view<charT, traits> str, typename basic_string_view<charT, traits>::size_type pos = 0, typename basic_string_view<charT, traits>::size_type n = basic_string_view<charT, traits>::npos,
|
||||
charT zero = charT('0'),
|
||||
charT one = charT('1')); template<class charT>constexpr explicit bitset(const charT* str, typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos,
|
||||
charT zero = charT('0'),
|
||||
charT one = charT('1')); // [[bitset.members]](#bitset.members "22.9.2.3 Members"), bitset operationsconstexpr bitset& operator&=(const bitset& rhs) noexcept; constexpr bitset& operator|=(const bitset& rhs) noexcept; constexpr bitset& operator^=(const bitset& rhs) noexcept; constexpr bitset& operator<<=(size_t pos) noexcept; constexpr bitset& operator>>=(size_t pos) noexcept; constexpr bitset operator<<(size_t pos) const noexcept; constexpr bitset operator>>(size_t pos) const noexcept; constexpr bitset& set() noexcept; constexpr bitset& set(size_t pos, bool val = true); constexpr bitset& reset() noexcept; constexpr bitset& reset(size_t pos); constexpr bitset operator~() const noexcept; constexpr bitset& flip() noexcept; constexpr bitset& flip(size_t pos); // element accessconstexpr bool operator[](size_t pos) const; constexpr reference operator[](size_t pos); constexpr unsigned long to_ulong() const; constexpr unsigned long long to_ullong() const; template<class charT = char, class traits = char_traits<charT>, class Allocator = allocator<charT>>constexpr basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; // observersconstexpr size_t count() const noexcept; constexpr size_t size() const noexcept; constexpr bool operator==(const bitset& rhs) const noexcept; constexpr bool test(size_t pos) const; constexpr bool all() const noexcept; constexpr bool any() const noexcept; constexpr bool none() const noexcept; }; // [[bitset.hash]](bitset.hash "22.9.3 bitset hash support"), hash supporttemplate<class T> struct hash; template<size_t N> struct hash<bitset<N>>;}
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10478)
|
||||
|
||||
The class templatebitset<N> describes an object that can store a sequence consisting of a fixed number of
|
||||
bits, N[.](#general-1.sentence-1)
|
||||
|
||||
[2](#general-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10484)
|
||||
|
||||
Each bit represents either the value zero (reset) or one (set)[.](#general-2.sentence-1)
|
||||
|
||||
To[*toggle*](#def:toggle) a bit is to change the value zero to one, or the value one to
|
||||
zero[.](#general-2.sentence-2)
|
||||
|
||||
Each bit has a non-negative position pos[.](#general-2.sentence-3)
|
||||
|
||||
When converting
|
||||
between an object of classbitset<N> and a value of some
|
||||
integral type, bit position pos corresponds to the[*bit value*](#def:bit_value)1 << pos[.](#general-2.sentence-4)
|
||||
|
||||
The integral value corresponding to two
|
||||
or more bits is the sum of their bit values[.](#general-2.sentence-5)
|
||||
|
||||
[3](#general-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10501)
|
||||
|
||||
The functions described in [template.bitset] can report three kinds of
|
||||
errors, each associated with a distinct exception:
|
||||
|
||||
- [(3.1)](#general-3.1)
|
||||
|
||||
an[*invalid-argument*](#def:invalid-argument) error is associated with exceptions of typeinvalid_argument ([[invalid.argument]](invalid.argument "19.2.5 Class invalid_argument"));
|
||||
|
||||
- [(3.2)](#general-3.2)
|
||||
|
||||
an[*out-of-range*](#def:out-of-range) error is associated with exceptions of typeout_of_range ([[out.of.range]](out.of.range "19.2.7 Class out_of_range"));
|
||||
|
||||
- [(3.3)](#general-3.3)
|
||||
|
||||
an[*overflow*](#def:overflow) error is associated with exceptions of typeoverflow_error ([[overflow.error]](overflow.error "19.2.10 Class overflow_error"))[.](#general-3.sentence-1)
|
||||
|
||||
#### [22.9.2.2](#bitset.cons) Constructors [[bitset.cons]](bitset.cons)
|
||||
|
||||
[ð](#lib:bitset,constructor)
|
||||
|
||||
`constexpr bitset() noexcept;
|
||||
`
|
||||
|
||||
[1](#bitset.cons-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10533)
|
||||
|
||||
*Effects*: Initializes all bits in *this to zero[.](#bitset.cons-1.sentence-1)
|
||||
|
||||
[ð](#lib:bitset,constructor_)
|
||||
|
||||
`constexpr bitset(unsigned long long val) noexcept;
|
||||
`
|
||||
|
||||
[2](#bitset.cons-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10544)
|
||||
|
||||
*Effects*: Initializes the first M bit positions to the corresponding bit
|
||||
values in val[.](#bitset.cons-2.sentence-1)
|
||||
|
||||
M is the smaller of N and the number of bits in the value
|
||||
representation ([[basic.types.general]](basic.types.general#term.object.representation "6.9.1 General")) of unsigned long long[.](#bitset.cons-2.sentence-2)
|
||||
|
||||
If M < N, the remaining bit positions are initialized to zero[.](#bitset.cons-2.sentence-3)
|
||||
|
||||
[ð](#lib:bitset,constructor__)
|
||||
|
||||
`template<class charT, class traits, class Allocator>
|
||||
constexpr explicit bitset(
|
||||
const basic_string<charT, traits, Allocator>& str,
|
||||
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
|
||||
typename basic_string<charT, traits, Allocator>::size_type n
|
||||
= basic_string<charT, traits, Allocator>::npos,
|
||||
charT zero = charT('0'),
|
||||
charT one = charT('1'));
|
||||
template<class charT, class traits>
|
||||
constexpr explicit bitset(
|
||||
basic_string_view<charT, traits> str,
|
||||
typename basic_string_view<charT, traits>::size_type pos = 0,
|
||||
typename basic_string_view<charT, traits>::size_type n
|
||||
= basic_string_view<charT, traits>::npos,
|
||||
charT zero = charT('0'),
|
||||
charT one = charT('1'));
|
||||
`
|
||||
|
||||
[3](#bitset.cons-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10574)
|
||||
|
||||
*Effects*: Determines the effective lengthrlen of the initializing string as the smaller ofn andstr.size() - pos[.](#bitset.cons-3.sentence-1)
|
||||
|
||||
Initializes the first M bit
|
||||
positions to values determined from the corresponding characters in the stringstr[.](#bitset.cons-3.sentence-2)
|
||||
|
||||
M is the smaller of N and rlen[.](#bitset.cons-3.sentence-3)
|
||||
|
||||
[4](#bitset.cons-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10585)
|
||||
|
||||
An element of the constructed object has value zero if the
|
||||
corresponding character in str, beginning at positionpos, iszero[.](#bitset.cons-4.sentence-1)
|
||||
|
||||
Otherwise, the element has the value one[.](#bitset.cons-4.sentence-2)
|
||||
|
||||
Character position pos + M - 1 corresponds to bit position zero[.](#bitset.cons-4.sentence-3)
|
||||
|
||||
Subsequent decreasing character positions correspond to increasing bit positions[.](#bitset.cons-4.sentence-4)
|
||||
|
||||
[5](#bitset.cons-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10594)
|
||||
|
||||
If M < N, remaining bit positions are initialized to zero[.](#bitset.cons-5.sentence-1)
|
||||
|
||||
[6](#bitset.cons-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10597)
|
||||
|
||||
The function uses traits::eq to compare the character values[.](#bitset.cons-6.sentence-1)
|
||||
|
||||
[7](#bitset.cons-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10601)
|
||||
|
||||
*Throws*: out_of_range if pos > str.size() orinvalid_argument if any of
|
||||
the rlen characters in str beginning at position pos is other than zero or one[.](#bitset.cons-7.sentence-1)
|
||||
|
||||
[ð](#lib:bitset,constructor___)
|
||||
|
||||
`template<class charT>
|
||||
constexpr explicit bitset(
|
||||
const charT* str,
|
||||
typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos,
|
||||
charT zero = charT('0'),
|
||||
charT one = charT('1'));
|
||||
`
|
||||
|
||||
[8](#bitset.cons-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10623)
|
||||
|
||||
*Effects*: As if by:bitset(n == basic_string_view<charT>::npos ? basic_string_view<charT>(str): basic_string_view<charT>(str, n), 0, n, zero, one)
|
||||
|
||||
#### [22.9.2.3](#bitset.members) Members [[bitset.members]](bitset.members)
|
||||
|
||||
[ð](#lib:operator&=,bitset)
|
||||
|
||||
`constexpr bitset& operator&=(const bitset& rhs) noexcept;
|
||||
`
|
||||
|
||||
[1](#bitset.members-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10643)
|
||||
|
||||
*Effects*: Clears each bit in*this for which the corresponding bit in rhs is clear, and leaves all other bits unchanged[.](#bitset.members-1.sentence-1)
|
||||
|
||||
[2](#bitset.members-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10649)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-2.sentence-1)
|
||||
|
||||
[ð](#lib:operator%7c=,bitset)
|
||||
|
||||
`constexpr bitset& operator|=(const bitset& rhs) noexcept;
|
||||
`
|
||||
|
||||
[3](#bitset.members-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10660)
|
||||
|
||||
*Effects*: Sets each bit in*this for which the corresponding bit in rhs is set, and leaves all other bits unchanged[.](#bitset.members-3.sentence-1)
|
||||
|
||||
[4](#bitset.members-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10666)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-4.sentence-1)
|
||||
|
||||
[ð](#lib:operator%5e=,bitset)
|
||||
|
||||
`constexpr bitset& operator^=(const bitset& rhs) noexcept;
|
||||
`
|
||||
|
||||
[5](#bitset.members-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10677)
|
||||
|
||||
*Effects*: Toggles each bit in*this for which the corresponding bit in rhs is set, and leaves all other bits unchanged[.](#bitset.members-5.sentence-1)
|
||||
|
||||
[6](#bitset.members-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10683)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-6.sentence-1)
|
||||
|
||||
[ð](#lib:operator%3c%3c=,bitset)
|
||||
|
||||
`constexpr bitset& operator<<=(size_t pos) noexcept;
|
||||
`
|
||||
|
||||
[7](#bitset.members-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10694)
|
||||
|
||||
*Effects*: Replaces each bit at position I in*this with a value determined as follows:
|
||||
|
||||
- [(7.1)](#bitset.members-7.1)
|
||||
|
||||
If I < pos, the new value is zero;
|
||||
|
||||
- [(7.2)](#bitset.members-7.2)
|
||||
|
||||
If I >= pos, the new value is the previous
|
||||
value of the bit at position I - pos[.](#bitset.members-7.sentence-1)
|
||||
|
||||
[8](#bitset.members-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10707)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-8.sentence-1)
|
||||
|
||||
[ð](#lib:operator%3e%3e=,bitset)
|
||||
|
||||
`constexpr bitset& operator>>=(size_t pos) noexcept;
|
||||
`
|
||||
|
||||
[9](#bitset.members-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10718)
|
||||
|
||||
*Effects*: Replaces each bit at position I in*this with a value determined as follows:
|
||||
|
||||
- [(9.1)](#bitset.members-9.1)
|
||||
|
||||
If pos >= N - I, the new value is zero;
|
||||
|
||||
- [(9.2)](#bitset.members-9.2)
|
||||
|
||||
If pos < N - I, the new value is the previous value of the bit at position I + pos[.](#bitset.members-9.sentence-1)
|
||||
|
||||
[10](#bitset.members-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10730)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-10.sentence-1)
|
||||
|
||||
[ð](#lib:operator%3c%3c,bitset)
|
||||
|
||||
`constexpr bitset operator<<(size_t pos) const noexcept;
|
||||
`
|
||||
|
||||
[11](#bitset.members-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10741)
|
||||
|
||||
*Returns*: bitset(*this) <<= pos[.](#bitset.members-11.sentence-1)
|
||||
|
||||
[ð](#lib:operator%3e%3e,bitset)
|
||||
|
||||
`constexpr bitset operator>>(size_t pos) const noexcept;
|
||||
`
|
||||
|
||||
[12](#bitset.members-12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10752)
|
||||
|
||||
*Returns*: bitset(*this) >>= pos[.](#bitset.members-12.sentence-1)
|
||||
|
||||
[ð](#lib:set_(member),bitset)
|
||||
|
||||
`constexpr bitset& set() noexcept;
|
||||
`
|
||||
|
||||
[13](#bitset.members-13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10765)
|
||||
|
||||
*Effects*: Sets all bits in*this[.](#bitset.members-13.sentence-1)
|
||||
|
||||
[14](#bitset.members-14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10770)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-14.sentence-1)
|
||||
|
||||
[ð](#lib:set_(member),bitset_)
|
||||
|
||||
`constexpr bitset& set(size_t pos, bool val = true);
|
||||
`
|
||||
|
||||
[15](#bitset.members-15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10783)
|
||||
|
||||
*Effects*: Stores a new value in the bit at position pos in*this[.](#bitset.members-15.sentence-1)
|
||||
|
||||
If val is true, the stored value is one, otherwise it is zero[.](#bitset.members-15.sentence-2)
|
||||
|
||||
[16](#bitset.members-16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10789)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-16.sentence-1)
|
||||
|
||||
[17](#bitset.members-17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10793)
|
||||
|
||||
*Throws*: out_of_range if pos does not correspond to a valid bit position[.](#bitset.members-17.sentence-1)
|
||||
|
||||
[ð](#lib:reset,bitset)
|
||||
|
||||
`constexpr bitset& reset() noexcept;
|
||||
`
|
||||
|
||||
[18](#bitset.members-18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10805)
|
||||
|
||||
*Effects*: Resets all bits in*this[.](#bitset.members-18.sentence-1)
|
||||
|
||||
[19](#bitset.members-19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10810)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-19.sentence-1)
|
||||
|
||||
[ð](#lib:reset,bitset_)
|
||||
|
||||
`constexpr bitset& reset(size_t pos);
|
||||
`
|
||||
|
||||
[20](#bitset.members-20)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10821)
|
||||
|
||||
*Effects*: Resets the bit at position pos in*this[.](#bitset.members-20.sentence-1)
|
||||
|
||||
[21](#bitset.members-21)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10826)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-21.sentence-1)
|
||||
|
||||
[22](#bitset.members-22)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10830)
|
||||
|
||||
*Throws*: out_of_range if pos does not correspond to a valid bit position[.](#bitset.members-22.sentence-1)
|
||||
|
||||
[ð](#lib:operator~,bitset)
|
||||
|
||||
`constexpr bitset operator~() const noexcept;
|
||||
`
|
||||
|
||||
[23](#bitset.members-23)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10842)
|
||||
|
||||
*Effects*: Constructs an object x of classbitset and initializes it with*this[.](#bitset.members-23.sentence-1)
|
||||
|
||||
[24](#bitset.members-24)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10849)
|
||||
|
||||
*Returns*: x.flip()[.](#bitset.members-24.sentence-1)
|
||||
|
||||
[ð](#lib:flip,bitset)
|
||||
|
||||
`constexpr bitset& flip() noexcept;
|
||||
`
|
||||
|
||||
[25](#bitset.members-25)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10860)
|
||||
|
||||
*Effects*: Toggles all bits in*this[.](#bitset.members-25.sentence-1)
|
||||
|
||||
[26](#bitset.members-26)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10865)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-26.sentence-1)
|
||||
|
||||
[ð](#lib:flip,bitset_)
|
||||
|
||||
`constexpr bitset& flip(size_t pos);
|
||||
`
|
||||
|
||||
[27](#bitset.members-27)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10876)
|
||||
|
||||
*Effects*: Toggles the bit at position pos in*this[.](#bitset.members-27.sentence-1)
|
||||
|
||||
[28](#bitset.members-28)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10881)
|
||||
|
||||
*Returns*: *this[.](#bitset.members-28.sentence-1)
|
||||
|
||||
[29](#bitset.members-29)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10885)
|
||||
|
||||
*Throws*: out_of_range if pos does not correspond to a valid bit position[.](#bitset.members-29.sentence-1)
|
||||
|
||||
[ð](#lib:operator%5b%5d,bitset)
|
||||
|
||||
`constexpr bool operator[](size_t pos) const;
|
||||
`
|
||||
|
||||
[30](#bitset.members-30)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10897)
|
||||
|
||||
*Hardened preconditions*: pos < size() is true[.](#bitset.members-30.sentence-1)
|
||||
|
||||
[31](#bitset.members-31)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10901)
|
||||
|
||||
*Returns*: true if the bit at position pos in *this has the value
|
||||
one, otherwise false[.](#bitset.members-31.sentence-1)
|
||||
|
||||
[32](#bitset.members-32)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10906)
|
||||
|
||||
*Throws*: Nothing[.](#bitset.members-32.sentence-1)
|
||||
|
||||
[ð](#lib:operator%5b%5d,bitset_)
|
||||
|
||||
`constexpr bitset::reference operator[](size_t pos);
|
||||
`
|
||||
|
||||
[33](#bitset.members-33)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10917)
|
||||
|
||||
*Hardened preconditions*: pos < size() is true[.](#bitset.members-33.sentence-1)
|
||||
|
||||
[34](#bitset.members-34)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10921)
|
||||
|
||||
*Returns*: An object of typebitset::reference such that(*this)[pos] == this->test(pos),
|
||||
and such that(*this)[pos] = val is equivalent tothis->set(pos, val)[.](#bitset.members-34.sentence-1)
|
||||
|
||||
[35](#bitset.members-35)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10932)
|
||||
|
||||
*Throws*: Nothing[.](#bitset.members-35.sentence-1)
|
||||
|
||||
[36](#bitset.members-36)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10936)
|
||||
|
||||
*Remarks*: For the purpose of determining the presence of a data
|
||||
race ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races")), any access or update through the resulting
|
||||
reference potentially accesses or modifies, respectively, the entire
|
||||
underlying bitset[.](#bitset.members-36.sentence-1)
|
||||
|
||||
[ð](#lib:to_ulong,bitset)
|
||||
|
||||
`constexpr unsigned long to_ulong() const;
|
||||
`
|
||||
|
||||
[37](#bitset.members-37)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10950)
|
||||
|
||||
*Returns*: x[.](#bitset.members-37.sentence-1)
|
||||
|
||||
[38](#bitset.members-38)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10954)
|
||||
|
||||
*Throws*: overflow_error if the integral value x corresponding to the bits in *this cannot be represented as type unsigned long[.](#bitset.members-38.sentence-1)
|
||||
|
||||
[ð](#lib:to_ullong,bitset)
|
||||
|
||||
`constexpr unsigned long long to_ullong() const;
|
||||
`
|
||||
|
||||
[39](#bitset.members-39)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10968)
|
||||
|
||||
*Returns*: x[.](#bitset.members-39.sentence-1)
|
||||
|
||||
[40](#bitset.members-40)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10972)
|
||||
|
||||
*Throws*: overflow_error if the integral value x corresponding to the bits in *this cannot be represented as type unsigned long long[.](#bitset.members-40.sentence-1)
|
||||
|
||||
[ð](#lib:to_string,bitset)
|
||||
|
||||
`template<class charT = char,
|
||||
class traits = char_traits<charT>,
|
||||
class Allocator = allocator<charT>>
|
||||
constexpr basic_string<charT, traits, Allocator>
|
||||
to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
||||
`
|
||||
|
||||
[41](#bitset.members-41)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10990)
|
||||
|
||||
*Effects*: Constructs a string object of the appropriate type
|
||||
and initializes it to a string of length N characters[.](#bitset.members-41.sentence-1)
|
||||
|
||||
Each character is determined by the value of its corresponding bit position in*this[.](#bitset.members-41.sentence-2)
|
||||
|
||||
Character position N - 1 corresponds to bit position zero[.](#bitset.members-41.sentence-3)
|
||||
|
||||
Subsequent decreasing character positions correspond to increasing bit
|
||||
positions[.](#bitset.members-41.sentence-4)
|
||||
|
||||
Bit value zero becomes the character zero,
|
||||
bit value one becomes the characterone[.](#bitset.members-41.sentence-5)
|
||||
|
||||
[42](#bitset.members-42)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11003)
|
||||
|
||||
*Returns*: The created object[.](#bitset.members-42.sentence-1)
|
||||
|
||||
[ð](#lib:count,bitset)
|
||||
|
||||
`constexpr size_t count() const noexcept;
|
||||
`
|
||||
|
||||
[43](#bitset.members-43)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11014)
|
||||
|
||||
*Returns*: A count of the number of bits set in*this[.](#bitset.members-43.sentence-1)
|
||||
|
||||
[ð](#lib:size,bitset)
|
||||
|
||||
`constexpr size_t size() const noexcept;
|
||||
`
|
||||
|
||||
[44](#bitset.members-44)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11026)
|
||||
|
||||
*Returns*: N[.](#bitset.members-44.sentence-1)
|
||||
|
||||
[ð](#lib:operator==,bitset)
|
||||
|
||||
`constexpr bool operator==(const bitset& rhs) const noexcept;
|
||||
`
|
||||
|
||||
[45](#bitset.members-45)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11037)
|
||||
|
||||
*Returns*: true if the value of each bit in*this equals the value of the corresponding bit in rhs[.](#bitset.members-45.sentence-1)
|
||||
|
||||
[ð](#lib:test,bitset)
|
||||
|
||||
`constexpr bool test(size_t pos) const;
|
||||
`
|
||||
|
||||
[46](#bitset.members-46)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11050)
|
||||
|
||||
*Returns*: true if the bit at position pos in*this has the value one[.](#bitset.members-46.sentence-1)
|
||||
|
||||
[47](#bitset.members-47)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11058)
|
||||
|
||||
*Throws*: out_of_range if pos does not correspond to a valid bit position[.](#bitset.members-47.sentence-1)
|
||||
|
||||
[ð](#lib:all,bitset)
|
||||
|
||||
`constexpr bool all() const noexcept;
|
||||
`
|
||||
|
||||
[48](#bitset.members-48)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11070)
|
||||
|
||||
*Returns*: count() == size()[.](#bitset.members-48.sentence-1)
|
||||
|
||||
[ð](#lib:any_(member),bitset)
|
||||
|
||||
`constexpr bool any() const noexcept;
|
||||
`
|
||||
|
||||
[49](#bitset.members-49)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11083)
|
||||
|
||||
*Returns*: count() != 0[.](#bitset.members-49.sentence-1)
|
||||
|
||||
[ð](#lib:none,bitset)
|
||||
|
||||
`constexpr bool none() const noexcept;
|
||||
`
|
||||
|
||||
[50](#bitset.members-50)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11094)
|
||||
|
||||
*Returns*: count() == 0[.](#bitset.members-50.sentence-1)
|
||||
63
cppdraft/template/bitset/general.md
Normal file
63
cppdraft/template/bitset/general.md
Normal file
@@ -0,0 +1,63 @@
|
||||
[template.bitset.general]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.9 Bitsets [[bitset]](bitset#template.bitset.general)
|
||||
|
||||
### 22.9.2 Class template bitset [[template.bitset]](template.bitset#general)
|
||||
|
||||
#### 22.9.2.1 General [template.bitset.general]
|
||||
|
||||
[ð](#lib:bitset)
|
||||
|
||||
namespace std {template<size_t N> class bitset {public:// bit referenceclass reference {public:constexpr reference(const reference&) = default; constexpr ~reference(); constexpr reference& operator=(bool x) noexcept; // for b[i] = x;constexpr reference& operator=(const reference&) noexcept; // for b[i] = b[j];constexpr bool operator~() const noexcept; // flips the bitconstexpr operator bool() const noexcept; // for x = b[i];constexpr reference& flip() noexcept; // for b[i].flip();}; // [[bitset.cons]](bitset.cons "22.9.2.2 Constructors"), constructorsconstexpr bitset() noexcept; constexpr bitset(unsigned long long val) noexcept; template<class charT, class traits, class Allocator>constexpr explicit bitset(const basic_string<charT, traits, Allocator>& str, typename basic_string<charT, traits, Allocator>::size_type pos = 0, typename basic_string<charT, traits, Allocator>::size_type n = basic_string<charT, traits, Allocator>::npos,
|
||||
charT zero = charT('0'),
|
||||
charT one = charT('1')); template<class charT, class traits>constexpr explicit bitset( basic_string_view<charT, traits> str, typename basic_string_view<charT, traits>::size_type pos = 0, typename basic_string_view<charT, traits>::size_type n = basic_string_view<charT, traits>::npos,
|
||||
charT zero = charT('0'),
|
||||
charT one = charT('1')); template<class charT>constexpr explicit bitset(const charT* str, typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos,
|
||||
charT zero = charT('0'),
|
||||
charT one = charT('1')); // [[bitset.members]](bitset.members "22.9.2.3 Members"), bitset operationsconstexpr bitset& operator&=(const bitset& rhs) noexcept; constexpr bitset& operator|=(const bitset& rhs) noexcept; constexpr bitset& operator^=(const bitset& rhs) noexcept; constexpr bitset& operator<<=(size_t pos) noexcept; constexpr bitset& operator>>=(size_t pos) noexcept; constexpr bitset operator<<(size_t pos) const noexcept; constexpr bitset operator>>(size_t pos) const noexcept; constexpr bitset& set() noexcept; constexpr bitset& set(size_t pos, bool val = true); constexpr bitset& reset() noexcept; constexpr bitset& reset(size_t pos); constexpr bitset operator~() const noexcept; constexpr bitset& flip() noexcept; constexpr bitset& flip(size_t pos); // element accessconstexpr bool operator[](size_t pos) const; constexpr reference operator[](size_t pos); constexpr unsigned long to_ulong() const; constexpr unsigned long long to_ullong() const; template<class charT = char, class traits = char_traits<charT>, class Allocator = allocator<charT>>constexpr basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; // observersconstexpr size_t count() const noexcept; constexpr size_t size() const noexcept; constexpr bool operator==(const bitset& rhs) const noexcept; constexpr bool test(size_t pos) const; constexpr bool all() const noexcept; constexpr bool any() const noexcept; constexpr bool none() const noexcept; }; // [[bitset.hash]](bitset.hash "22.9.3 bitset hash support"), hash supporttemplate<class T> struct hash; template<size_t N> struct hash<bitset<N>>;}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10478)
|
||||
|
||||
The class templatebitset<N> describes an object that can store a sequence consisting of a fixed number of
|
||||
bits, N[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10484)
|
||||
|
||||
Each bit represents either the value zero (reset) or one (set)[.](#2.sentence-1)
|
||||
|
||||
To[*toggle*](#def:toggle) a bit is to change the value zero to one, or the value one to
|
||||
zero[.](#2.sentence-2)
|
||||
|
||||
Each bit has a non-negative position pos[.](#2.sentence-3)
|
||||
|
||||
When converting
|
||||
between an object of classbitset<N> and a value of some
|
||||
integral type, bit position pos corresponds to the[*bit value*](#def:bit_value)1 << pos[.](#2.sentence-4)
|
||||
|
||||
The integral value corresponding to two
|
||||
or more bits is the sum of their bit values[.](#2.sentence-5)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10501)
|
||||
|
||||
The functions described in [[template.bitset]](template.bitset "22.9.2 Class template bitset") can report three kinds of
|
||||
errors, each associated with a distinct exception:
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
an[*invalid-argument*](#def:invalid-argument) error is associated with exceptions of typeinvalid_argument ([[invalid.argument]](invalid.argument "19.2.5 Class invalid_argument"));
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
an[*out-of-range*](#def:out-of-range) error is associated with exceptions of typeout_of_range ([[out.of.range]](out.of.range "19.2.7 Class out_of_range"));
|
||||
|
||||
- [(3.3)](#3.3)
|
||||
|
||||
an[*overflow*](#def:overflow) error is associated with exceptions of typeoverflow_error ([[overflow.error]](overflow.error "19.2.10 Class overflow_error"))[.](#3.sentence-1)
|
||||
90
cppdraft/template/gslice/array.md
Normal file
90
cppdraft/template/gslice/array.md
Normal file
@@ -0,0 +1,90 @@
|
||||
[template.gslice.array]
|
||||
|
||||
# 29 Numerics library [[numerics]](./#numerics)
|
||||
|
||||
## 29.6 Numeric arrays [[numarray]](numarray#template.gslice.array)
|
||||
|
||||
### 29.6.7 Class template gslice_array [template.gslice.array]
|
||||
|
||||
#### [29.6.7.1](#overview) Overview [[template.gslice.array.overview]](template.gslice.array.overview)
|
||||
|
||||
[ð](#lib:gslice_array)
|
||||
|
||||
namespace std {template<class T> class gslice_array {public:using value_type = T; void operator= (const valarray<T>&) const; void operator*= (const valarray<T>&) const; void operator/= (const valarray<T>&) const; void operator%= (const valarray<T>&) const; void operator+= (const valarray<T>&) const; void operator-= (const valarray<T>&) const; void operator^= (const valarray<T>&) const; void operator&= (const valarray<T>&) const; void operator|= (const valarray<T>&) const; void operator<<=(const valarray<T>&) const; void operator>>=(const valarray<T>&) const;
|
||||
|
||||
gslice_array(const gslice_array&); ~gslice_array(); const gslice_array& operator=(const gslice_array&) const; void operator=(const T&) const;
|
||||
|
||||
gslice_array() = delete; // as implied by declaring copy constructor above};}
|
||||
|
||||
[1](#overview-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8786)
|
||||
|
||||
This template is a helper template used by thegslice subscript operator
|
||||
|
||||
[ð](#lib:gslice_array_)
|
||||
|
||||
`gslice_array<T> valarray<T>::operator[](const gslice&);
|
||||
`
|
||||
|
||||
[2](#overview-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8796)
|
||||
|
||||
It has reference semantics to a subset of an array specified by agslice object[.](#overview-2.sentence-1)
|
||||
|
||||
Thus, the expressiona[gslice(1, length, stride)] = b has the effect of assigning the elements ofb to a
|
||||
generalized slice of the elements ina[.](#overview-2.sentence-2)
|
||||
|
||||
#### [29.6.7.2](#gslice.array.assign) Assignment [[gslice.array.assign]](gslice.array.assign)
|
||||
|
||||
[ð](#lib:operator=,gslice_array)
|
||||
|
||||
`void operator=(const valarray<T>&) const;
|
||||
const gslice_array& operator=(const gslice_array&) const;
|
||||
`
|
||||
|
||||
[1](#gslice.array.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8817)
|
||||
|
||||
These assignment operators have reference semantics, assigning the values
|
||||
of the argument array elements to selected elements of thevalarray<T> object to which thegslice_array refers[.](#gslice.array.assign-1.sentence-1)
|
||||
|
||||
#### [29.6.7.3](#gslice.array.comp.assign) Compound assignment [[gslice.array.comp.assign]](gslice.array.comp.assign)
|
||||
|
||||
[ð](#lib:operator*=,gslice_array)
|
||||
|
||||
`void operator*= (const valarray<T>&) const;
|
||||
void operator/= (const valarray<T>&) const;
|
||||
void operator%= (const valarray<T>&) const;
|
||||
void operator+= (const valarray<T>&) const;
|
||||
void operator-= (const valarray<T>&) const;
|
||||
void operator^= (const valarray<T>&) const;
|
||||
void operator&= (const valarray<T>&) const;
|
||||
void operator|= (const valarray<T>&) const;
|
||||
void operator<<=(const valarray<T>&) const;
|
||||
void operator>>=(const valarray<T>&) const;
|
||||
`
|
||||
|
||||
[1](#gslice.array.comp.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8852)
|
||||
|
||||
These compound assignments have reference semantics, applying the
|
||||
indicated operation to the elements of the argument array and selected
|
||||
elements of thevalarray<T> object to which thegslice_array object refers[.](#gslice.array.comp.assign-1.sentence-1)
|
||||
|
||||
#### [29.6.7.4](#gslice.array.fill) Fill function [[gslice.array.fill]](gslice.array.fill)
|
||||
|
||||
[ð](#lib:operator=,gslice_array_)
|
||||
|
||||
`void operator=(const T&) const;
|
||||
`
|
||||
|
||||
[1](#gslice.array.fill-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8870)
|
||||
|
||||
This function has reference semantics, assigning the value of its argument
|
||||
to the elements of thevalarray<T> object to which thegslice_array object refers[.](#gslice.array.fill-1.sentence-1)
|
||||
37
cppdraft/template/gslice/array/overview.md
Normal file
37
cppdraft/template/gslice/array/overview.md
Normal file
@@ -0,0 +1,37 @@
|
||||
[template.gslice.array.overview]
|
||||
|
||||
# 29 Numerics library [[numerics]](./#numerics)
|
||||
|
||||
## 29.6 Numeric arrays [[numarray]](numarray#template.gslice.array.overview)
|
||||
|
||||
### 29.6.7 Class template gslice_array [[template.gslice.array]](template.gslice.array#overview)
|
||||
|
||||
#### 29.6.7.1 Overview [template.gslice.array.overview]
|
||||
|
||||
[ð](#lib:gslice_array)
|
||||
|
||||
namespace std {template<class T> class gslice_array {public:using value_type = T; void operator= (const valarray<T>&) const; void operator*= (const valarray<T>&) const; void operator/= (const valarray<T>&) const; void operator%= (const valarray<T>&) const; void operator+= (const valarray<T>&) const; void operator-= (const valarray<T>&) const; void operator^= (const valarray<T>&) const; void operator&= (const valarray<T>&) const; void operator|= (const valarray<T>&) const; void operator<<=(const valarray<T>&) const; void operator>>=(const valarray<T>&) const;
|
||||
|
||||
gslice_array(const gslice_array&); ~gslice_array(); const gslice_array& operator=(const gslice_array&) const; void operator=(const T&) const;
|
||||
|
||||
gslice_array() = delete; // as implied by declaring copy constructor above};}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8786)
|
||||
|
||||
This template is a helper template used by thegslice subscript operator
|
||||
|
||||
[ð](#lib:gslice_array_)
|
||||
|
||||
`gslice_array<T> valarray<T>::operator[](const gslice&);
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8796)
|
||||
|
||||
It has reference semantics to a subset of an array specified by agslice object[.](#2.sentence-1)
|
||||
|
||||
Thus, the expressiona[gslice(1, length, stride)] = b has the effect of assigning the elements ofb to a
|
||||
generalized slice of the elements ina[.](#2.sentence-2)
|
||||
115
cppdraft/template/indirect/array.md
Normal file
115
cppdraft/template/indirect/array.md
Normal file
@@ -0,0 +1,115 @@
|
||||
[template.indirect.array]
|
||||
|
||||
# 29 Numerics library [[numerics]](./#numerics)
|
||||
|
||||
## 29.6 Numeric arrays [[numarray]](numarray#template.indirect.array)
|
||||
|
||||
### 29.6.9 Class template indirect_array [template.indirect.array]
|
||||
|
||||
#### [29.6.9.1](#overview) Overview [[template.indirect.array.overview]](template.indirect.array.overview)
|
||||
|
||||
[ð](#lib:indirect_array)
|
||||
|
||||
namespace std {template<class T> class indirect_array {public:using value_type = T; void operator= (const valarray<T>&) const; void operator*= (const valarray<T>&) const; void operator/= (const valarray<T>&) const; void operator%= (const valarray<T>&) const; void operator+= (const valarray<T>&) const; void operator-= (const valarray<T>&) const; void operator^= (const valarray<T>&) const; void operator&= (const valarray<T>&) const; void operator|= (const valarray<T>&) const; void operator<<=(const valarray<T>&) const; void operator>>=(const valarray<T>&) const;
|
||||
|
||||
indirect_array(const indirect_array&); ~indirect_array(); const indirect_array& operator=(const indirect_array&) const; void operator=(const T&) const;
|
||||
|
||||
indirect_array() = delete; // as implied by declaring copy constructor above};}
|
||||
|
||||
[1](#overview-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9029)
|
||||
|
||||
This template is a helper template used by the indirect subscript operator
|
||||
|
||||
[ð](#lib:operator%5b%5d,indirect_array)
|
||||
|
||||
`indirect_array<T> valarray<T>::operator[](const valarray<size_t>&);
|
||||
`
|
||||
|
||||
[2](#overview-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9036)
|
||||
|
||||
It has reference semantics to a subset of an array specified by anindirect_array[.](#overview-2.sentence-1)
|
||||
|
||||
Thus, the expressiona[indirect] = b; has the effect of assigning the elements ofb to the elements ina whose indices appear inindirect[.](#overview-2.sentence-2)
|
||||
|
||||
#### [29.6.9.2](#indirect.array.assign) Assignment [[indirect.array.assign]](indirect.array.assign)
|
||||
|
||||
[ð](#lib:operator=,indirect_array)
|
||||
|
||||
`void operator=(const valarray<T>&) const;
|
||||
const indirect_array& operator=(const indirect_array&) const;
|
||||
`
|
||||
|
||||
[1](#indirect.array.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9057)
|
||||
|
||||
These assignment operators have reference semantics, assigning the values
|
||||
of the argument array elements to selected elements of thevalarray<T> object to which it refers[.](#indirect.array.assign-1.sentence-1)
|
||||
|
||||
[2](#indirect.array.assign-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9063)
|
||||
|
||||
If theindirect_array specifies an element in thevalarray<T> object to which it refers more than once, the behavior is undefined[.](#indirect.array.assign-2.sentence-1)
|
||||
|
||||
[3](#indirect.array.assign-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9071)
|
||||
|
||||
[*Example [1](#indirect.array.assign-example-1)*:
|
||||
|
||||
int addr[] = {2, 3, 1, 4, 4};
|
||||
valarray<size_t> indirect(addr, 5);
|
||||
valarray<double> a(0., 10), b(1., 5);
|
||||
a[indirect] = b; results in undefined behavior since element 4 is specified twice in the
|
||||
indirection[.](#indirect.array.assign-3.sentence-1)
|
||||
|
||||
â *end example*]
|
||||
|
||||
#### [29.6.9.3](#indirect.array.comp.assign) Compound assignment [[indirect.array.comp.assign]](indirect.array.comp.assign)
|
||||
|
||||
[ð](#lib:operator*=,indirect_array)
|
||||
|
||||
`void operator*= (const valarray<T>&) const;
|
||||
void operator/= (const valarray<T>&) const;
|
||||
void operator%= (const valarray<T>&) const;
|
||||
void operator+= (const valarray<T>&) const;
|
||||
void operator-= (const valarray<T>&) const;
|
||||
void operator^= (const valarray<T>&) const;
|
||||
void operator&= (const valarray<T>&) const;
|
||||
void operator|= (const valarray<T>&) const;
|
||||
void operator<<=(const valarray<T>&) const;
|
||||
void operator>>=(const valarray<T>&) const;
|
||||
`
|
||||
|
||||
[1](#indirect.array.comp.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9110)
|
||||
|
||||
These compound assignments have reference semantics, applying the indicated
|
||||
operation to the elements of the argument array and selected elements of thevalarray<T> object to which theindirect_array object refers[.](#indirect.array.comp.assign-1.sentence-1)
|
||||
|
||||
[2](#indirect.array.comp.assign-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9118)
|
||||
|
||||
If theindirect_array specifies an element in thevalarray<T> object to which it refers more than once,
|
||||
the behavior is undefined[.](#indirect.array.comp.assign-2.sentence-1)
|
||||
|
||||
#### [29.6.9.4](#indirect.array.fill) Fill function [[indirect.array.fill]](indirect.array.fill)
|
||||
|
||||
[ð](#lib:operator=,indirect_array_)
|
||||
|
||||
`void operator=(const T&) const;
|
||||
`
|
||||
|
||||
[1](#indirect.array.fill-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9136)
|
||||
|
||||
This function has reference semantics, assigning the value of its argument
|
||||
to the elements of thevalarray<T> object to which theindirect_array object refers[.](#indirect.array.fill-1.sentence-1)
|
||||
36
cppdraft/template/indirect/array/overview.md
Normal file
36
cppdraft/template/indirect/array/overview.md
Normal file
@@ -0,0 +1,36 @@
|
||||
[template.indirect.array.overview]
|
||||
|
||||
# 29 Numerics library [[numerics]](./#numerics)
|
||||
|
||||
## 29.6 Numeric arrays [[numarray]](numarray#template.indirect.array.overview)
|
||||
|
||||
### 29.6.9 Class template indirect_array [[template.indirect.array]](template.indirect.array#overview)
|
||||
|
||||
#### 29.6.9.1 Overview [template.indirect.array.overview]
|
||||
|
||||
[ð](#lib:indirect_array)
|
||||
|
||||
namespace std {template<class T> class indirect_array {public:using value_type = T; void operator= (const valarray<T>&) const; void operator*= (const valarray<T>&) const; void operator/= (const valarray<T>&) const; void operator%= (const valarray<T>&) const; void operator+= (const valarray<T>&) const; void operator-= (const valarray<T>&) const; void operator^= (const valarray<T>&) const; void operator&= (const valarray<T>&) const; void operator|= (const valarray<T>&) const; void operator<<=(const valarray<T>&) const; void operator>>=(const valarray<T>&) const;
|
||||
|
||||
indirect_array(const indirect_array&); ~indirect_array(); const indirect_array& operator=(const indirect_array&) const; void operator=(const T&) const;
|
||||
|
||||
indirect_array() = delete; // as implied by declaring copy constructor above};}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9029)
|
||||
|
||||
This template is a helper template used by the indirect subscript operator
|
||||
|
||||
[ð](#lib:operator%5b%5d,indirect_array)
|
||||
|
||||
`indirect_array<T> valarray<T>::operator[](const valarray<size_t>&);
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9036)
|
||||
|
||||
It has reference semantics to a subset of an array specified by anindirect_array[.](#2.sentence-1)
|
||||
|
||||
Thus, the expressiona[indirect] = b; has the effect of assigning the elements ofb to the elements ina whose indices appear inindirect[.](#2.sentence-2)
|
||||
89
cppdraft/template/mask/array.md
Normal file
89
cppdraft/template/mask/array.md
Normal file
@@ -0,0 +1,89 @@
|
||||
[template.mask.array]
|
||||
|
||||
# 29 Numerics library [[numerics]](./#numerics)
|
||||
|
||||
## 29.6 Numeric arrays [[numarray]](numarray#template.mask.array)
|
||||
|
||||
### 29.6.8 Class template mask_array [template.mask.array]
|
||||
|
||||
#### [29.6.8.1](#overview) Overview [[template.mask.array.overview]](template.mask.array.overview)
|
||||
|
||||
[ð](#lib:mask_array)
|
||||
|
||||
namespace std {template<class T> class mask_array {public:using value_type = T; void operator= (const valarray<T>&) const; void operator*= (const valarray<T>&) const; void operator/= (const valarray<T>&) const; void operator%= (const valarray<T>&) const; void operator+= (const valarray<T>&) const; void operator-= (const valarray<T>&) const; void operator^= (const valarray<T>&) const; void operator&= (const valarray<T>&) const; void operator|= (const valarray<T>&) const; void operator<<=(const valarray<T>&) const; void operator>>=(const valarray<T>&) const;
|
||||
|
||||
mask_array(const mask_array&); ~mask_array(); const mask_array& operator=(const mask_array&) const; void operator=(const T&) const;
|
||||
|
||||
mask_array() = delete; // as implied by declaring copy constructor above};}
|
||||
|
||||
[1](#overview-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8913)
|
||||
|
||||
This template is a helper template used by the mask subscript operator:
|
||||
|
||||
[ð](#lib:operator%5b%5d,mask_array)
|
||||
|
||||
`mask_array<T> valarray<T>::operator[](const valarray<bool>&);
|
||||
`
|
||||
|
||||
[2](#overview-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8920)
|
||||
|
||||
It has reference semantics to a subset of an array specified by a boolean mask[.](#overview-2.sentence-1)
|
||||
|
||||
Thus, the expression a[mask] = b; has the effect of assigning the elements ofb to the masked elements in a (those for which the corresponding element inmask is true)[.](#overview-2.sentence-2)
|
||||
|
||||
#### [29.6.8.2](#mask.array.assign) Assignment [[mask.array.assign]](mask.array.assign)
|
||||
|
||||
[ð](#lib:operator=,mask_array)
|
||||
|
||||
`void operator=(const valarray<T>&) const;
|
||||
const mask_array& operator=(const mask_array&) const;
|
||||
`
|
||||
|
||||
[1](#mask.array.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8937)
|
||||
|
||||
These assignment operators have reference semantics, assigning the values
|
||||
of the argument array elements to selected elements of thevalarray<T> object to which the mask_array object refers[.](#mask.array.assign-1.sentence-1)
|
||||
|
||||
#### [29.6.8.3](#mask.array.comp.assign) Compound assignment [[mask.array.comp.assign]](mask.array.comp.assign)
|
||||
|
||||
[ð](#lib:operator*=,mask_array)
|
||||
|
||||
`void operator*= (const valarray<T>&) const;
|
||||
void operator/= (const valarray<T>&) const;
|
||||
void operator%= (const valarray<T>&) const;
|
||||
void operator+= (const valarray<T>&) const;
|
||||
void operator-= (const valarray<T>&) const;
|
||||
void operator^= (const valarray<T>&) const;
|
||||
void operator&= (const valarray<T>&) const;
|
||||
void operator|= (const valarray<T>&) const;
|
||||
void operator<<=(const valarray<T>&) const;
|
||||
void operator>>=(const valarray<T>&) const;
|
||||
`
|
||||
|
||||
[1](#mask.array.comp.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8970)
|
||||
|
||||
These compound assignments have reference semantics, applying the
|
||||
indicated operation to the elements of the argument array and selected elements
|
||||
of thevalarray<T> object to which the mask_array object refers[.](#mask.array.comp.assign-1.sentence-1)
|
||||
|
||||
#### [29.6.8.4](#mask.array.fill) Fill function [[mask.array.fill]](mask.array.fill)
|
||||
|
||||
[ð](#lib:operator=,mask_array_)
|
||||
|
||||
`void operator=(const T&) const;
|
||||
`
|
||||
|
||||
[1](#mask.array.fill-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8986)
|
||||
|
||||
This function has reference semantics, assigning the value of its
|
||||
argument to the elements of thevalarray<T> object to which themask_array object refers[.](#mask.array.fill-1.sentence-1)
|
||||
36
cppdraft/template/mask/array/overview.md
Normal file
36
cppdraft/template/mask/array/overview.md
Normal file
@@ -0,0 +1,36 @@
|
||||
[template.mask.array.overview]
|
||||
|
||||
# 29 Numerics library [[numerics]](./#numerics)
|
||||
|
||||
## 29.6 Numeric arrays [[numarray]](numarray#template.mask.array.overview)
|
||||
|
||||
### 29.6.8 Class template mask_array [[template.mask.array]](template.mask.array#overview)
|
||||
|
||||
#### 29.6.8.1 Overview [template.mask.array.overview]
|
||||
|
||||
[ð](#lib:mask_array)
|
||||
|
||||
namespace std {template<class T> class mask_array {public:using value_type = T; void operator= (const valarray<T>&) const; void operator*= (const valarray<T>&) const; void operator/= (const valarray<T>&) const; void operator%= (const valarray<T>&) const; void operator+= (const valarray<T>&) const; void operator-= (const valarray<T>&) const; void operator^= (const valarray<T>&) const; void operator&= (const valarray<T>&) const; void operator|= (const valarray<T>&) const; void operator<<=(const valarray<T>&) const; void operator>>=(const valarray<T>&) const;
|
||||
|
||||
mask_array(const mask_array&); ~mask_array(); const mask_array& operator=(const mask_array&) const; void operator=(const T&) const;
|
||||
|
||||
mask_array() = delete; // as implied by declaring copy constructor above};}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8913)
|
||||
|
||||
This template is a helper template used by the mask subscript operator:
|
||||
|
||||
[ð](#lib:operator%5b%5d,mask_array)
|
||||
|
||||
`mask_array<T> valarray<T>::operator[](const valarray<bool>&);
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8920)
|
||||
|
||||
It has reference semantics to a subset of an array specified by a boolean mask[.](#2.sentence-1)
|
||||
|
||||
Thus, the expression a[mask] = b; has the effect of assigning the elements ofb to the masked elements in a (those for which the corresponding element inmask is true)[.](#2.sentence-2)
|
||||
92
cppdraft/template/slice/array.md
Normal file
92
cppdraft/template/slice/array.md
Normal file
@@ -0,0 +1,92 @@
|
||||
[template.slice.array]
|
||||
|
||||
# 29 Numerics library [[numerics]](./#numerics)
|
||||
|
||||
## 29.6 Numeric arrays [[numarray]](numarray#template.slice.array)
|
||||
|
||||
### 29.6.5 Class template slice_array [template.slice.array]
|
||||
|
||||
#### [29.6.5.1](#overview) Overview [[template.slice.array.overview]](template.slice.array.overview)
|
||||
|
||||
[ð](#lib:slice_array)
|
||||
|
||||
namespace std {template<class T> class slice_array {public:using value_type = T; void operator= (const valarray<T>&) const; void operator*= (const valarray<T>&) const; void operator/= (const valarray<T>&) const; void operator%= (const valarray<T>&) const; void operator+= (const valarray<T>&) const; void operator-= (const valarray<T>&) const; void operator^= (const valarray<T>&) const; void operator&= (const valarray<T>&) const; void operator|= (const valarray<T>&) const; void operator<<=(const valarray<T>&) const; void operator>>=(const valarray<T>&) const;
|
||||
|
||||
slice_array(const slice_array&); ~slice_array(); const slice_array& operator=(const slice_array&) const; void operator=(const T&) const;
|
||||
|
||||
slice_array() = delete; // as implied by declaring copy constructor above};}
|
||||
|
||||
[1](#overview-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8504)
|
||||
|
||||
This template is a helper template used by theslice subscript operatorslice_array<T> valarray<T>::operator[](slice);
|
||||
|
||||
[2](#overview-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8511)
|
||||
|
||||
It has reference semantics to a subset of an array specified by aslice object[.](#overview-2.sentence-1)
|
||||
|
||||
[*Example [1](#overview-example-1)*:
|
||||
|
||||
The expressiona[slice(1, 5, 3)] = b; has the effect of assigning the elements ofb to a slice of the elements ina[.](#overview-2.sentence-2)
|
||||
|
||||
For the slice shown, the elements
|
||||
selected froma are 1,4,â¦,13[.](#overview-2.sentence-3)
|
||||
|
||||
â *end example*]
|
||||
|
||||
#### [29.6.5.2](#slice.arr.assign) Assignment [[slice.arr.assign]](slice.arr.assign)
|
||||
|
||||
[ð](#lib:operator=,slice_array)
|
||||
|
||||
`void operator=(const valarray<T>&) const;
|
||||
const slice_array& operator=(const slice_array&) const;
|
||||
`
|
||||
|
||||
[1](#slice.arr.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8537)
|
||||
|
||||
These assignment operators have reference semantics,
|
||||
assigning the values of the argument array elements to selected
|
||||
elements of thevalarray<T> object to which theslice_array object refers[.](#slice.arr.assign-1.sentence-1)
|
||||
|
||||
#### [29.6.5.3](#slice.arr.comp.assign) Compound assignment [[slice.arr.comp.assign]](slice.arr.comp.assign)
|
||||
|
||||
[ð](#lib:operator*=,slice_array)
|
||||
|
||||
`void operator*= (const valarray<T>&) const;
|
||||
void operator/= (const valarray<T>&) const;
|
||||
void operator%= (const valarray<T>&) const;
|
||||
void operator+= (const valarray<T>&) const;
|
||||
void operator-= (const valarray<T>&) const;
|
||||
void operator^= (const valarray<T>&) const;
|
||||
void operator&= (const valarray<T>&) const;
|
||||
void operator|= (const valarray<T>&) const;
|
||||
void operator<<=(const valarray<T>&) const;
|
||||
void operator>>=(const valarray<T>&) const;
|
||||
`
|
||||
|
||||
[1](#slice.arr.comp.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8573)
|
||||
|
||||
These compound assignments have reference semantics, applying the
|
||||
indicated operation to the elements of the argument array
|
||||
and selected elements of thevalarray<T> object to which theslice_array object refers[.](#slice.arr.comp.assign-1.sentence-1)
|
||||
|
||||
#### [29.6.5.4](#slice.arr.fill) Fill function [[slice.arr.fill]](slice.arr.fill)
|
||||
|
||||
[ð](#lib:operator=,slice_array_)
|
||||
|
||||
`void operator=(const T&) const;
|
||||
`
|
||||
|
||||
[1](#slice.arr.fill-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8591)
|
||||
|
||||
This function has reference semantics, assigning the value of its argument
|
||||
to the elements of thevalarray<T> object to which theslice_array object refers[.](#slice.arr.fill-1.sentence-1)
|
||||
38
cppdraft/template/slice/array/overview.md
Normal file
38
cppdraft/template/slice/array/overview.md
Normal file
@@ -0,0 +1,38 @@
|
||||
[template.slice.array.overview]
|
||||
|
||||
# 29 Numerics library [[numerics]](./#numerics)
|
||||
|
||||
## 29.6 Numeric arrays [[numarray]](numarray#template.slice.array.overview)
|
||||
|
||||
### 29.6.5 Class template slice_array [[template.slice.array]](template.slice.array#overview)
|
||||
|
||||
#### 29.6.5.1 Overview [template.slice.array.overview]
|
||||
|
||||
[ð](#lib:slice_array)
|
||||
|
||||
namespace std {template<class T> class slice_array {public:using value_type = T; void operator= (const valarray<T>&) const; void operator*= (const valarray<T>&) const; void operator/= (const valarray<T>&) const; void operator%= (const valarray<T>&) const; void operator+= (const valarray<T>&) const; void operator-= (const valarray<T>&) const; void operator^= (const valarray<T>&) const; void operator&= (const valarray<T>&) const; void operator|= (const valarray<T>&) const; void operator<<=(const valarray<T>&) const; void operator>>=(const valarray<T>&) const;
|
||||
|
||||
slice_array(const slice_array&); ~slice_array(); const slice_array& operator=(const slice_array&) const; void operator=(const T&) const;
|
||||
|
||||
slice_array() = delete; // as implied by declaring copy constructor above};}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8504)
|
||||
|
||||
This template is a helper template used by theslice subscript operatorslice_array<T> valarray<T>::operator[](slice);
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8511)
|
||||
|
||||
It has reference semantics to a subset of an array specified by aslice object[.](#2.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
The expressiona[slice(1, 5, 3)] = b; has the effect of assigning the elements ofb to a slice of the elements ina[.](#2.sentence-2)
|
||||
|
||||
For the slice shown, the elements
|
||||
selected froma are 1,4,â¦,13[.](#2.sentence-3)
|
||||
|
||||
â *end example*]
|
||||
865
cppdraft/template/valarray.md
Normal file
865
cppdraft/template/valarray.md
Normal file
@@ -0,0 +1,865 @@
|
||||
[template.valarray]
|
||||
|
||||
# 29 Numerics library [[numerics]](./#numerics)
|
||||
|
||||
## 29.6 Numeric arrays [[numarray]](numarray#template.valarray)
|
||||
|
||||
### 29.6.2 Class template valarray [template.valarray]
|
||||
|
||||
#### [29.6.2.1](#overview) Overview [[template.valarray.overview]](template.valarray.overview)
|
||||
|
||||
[ð](#lib:valarray)
|
||||
|
||||
namespace std {template<class T> class valarray {public:using value_type = T; // [[valarray.cons]](#valarray.cons "29.6.2.2 Constructors"), construct/destroy valarray(); explicit valarray(size_t);
|
||||
valarray(const T&, size_t);
|
||||
valarray(const T*, size_t);
|
||||
valarray(const valarray&);
|
||||
valarray(valarray&&) noexcept;
|
||||
valarray(const slice_array<T>&);
|
||||
valarray(const gslice_array<T>&);
|
||||
valarray(const mask_array<T>&);
|
||||
valarray(const indirect_array<T>&);
|
||||
valarray(initializer_list<T>); ~valarray(); // [[valarray.assign]](#valarray.assign "29.6.2.3 Assignment"), assignment valarray& operator=(const valarray&);
|
||||
valarray& operator=(valarray&&) noexcept;
|
||||
valarray& operator=(initializer_list<T>);
|
||||
valarray& operator=(const T&);
|
||||
valarray& operator=(const slice_array<T>&);
|
||||
valarray& operator=(const gslice_array<T>&);
|
||||
valarray& operator=(const mask_array<T>&);
|
||||
valarray& operator=(const indirect_array<T>&); // [[valarray.access]](#valarray.access "29.6.2.4 Element access"), element accessconst T& operator[](size_t) const;
|
||||
T& operator[](size_t); // [[valarray.sub]](#valarray.sub "29.6.2.5 Subset operations"), subset operations valarray operator[](slice) const;
|
||||
slice_array<T> operator[](slice);
|
||||
valarray operator[](const gslice&) const;
|
||||
gslice_array<T> operator[](const gslice&);
|
||||
valarray operator[](const valarray<bool>&) const;
|
||||
mask_array<T> operator[](const valarray<bool>&);
|
||||
valarray operator[](const valarray<size_t>&) const;
|
||||
indirect_array<T> operator[](const valarray<size_t>&); // [[valarray.unary]](#valarray.unary "29.6.2.6 Unary operators"), unary operators valarray operator+() const;
|
||||
valarray operator-() const;
|
||||
valarray operator~() const;
|
||||
valarray<bool> operator!() const; // [[valarray.cassign]](#valarray.cassign "29.6.2.7 Compound assignment"), compound assignment valarray& operator*= (const T&);
|
||||
valarray& operator/= (const T&);
|
||||
valarray& operator%= (const T&);
|
||||
valarray& operator+= (const T&);
|
||||
valarray& operator-= (const T&);
|
||||
valarray& operator^= (const T&);
|
||||
valarray& operator&= (const T&);
|
||||
valarray& operator|= (const T&);
|
||||
valarray& operator<<=(const T&);
|
||||
valarray& operator>>=(const T&);
|
||||
|
||||
valarray& operator*= (const valarray&);
|
||||
valarray& operator/= (const valarray&);
|
||||
valarray& operator%= (const valarray&);
|
||||
valarray& operator+= (const valarray&);
|
||||
valarray& operator-= (const valarray&);
|
||||
valarray& operator^= (const valarray&);
|
||||
valarray& operator|= (const valarray&);
|
||||
valarray& operator&= (const valarray&);
|
||||
valarray& operator<<=(const valarray&);
|
||||
valarray& operator>>=(const valarray&); // [[valarray.members]](#valarray.members "29.6.2.8 Member functions"), member functionsvoid swap(valarray&) noexcept;
|
||||
|
||||
size_t size() const;
|
||||
|
||||
T sum() const;
|
||||
T min() const;
|
||||
T max() const;
|
||||
|
||||
valarray shift (int) const;
|
||||
valarray cshift(int) const;
|
||||
valarray apply(T func(T)) const;
|
||||
valarray apply(T func(const T&)) const; void resize(size_t sz, T c = T()); }; template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;}
|
||||
|
||||
[1](#overview-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7299)
|
||||
|
||||
The
|
||||
class templatevalarray<T> is a
|
||||
one-dimensional smart array, with elements numbered sequentially from zero[.](#overview-1.sentence-1)
|
||||
|
||||
It is a representation of the mathematical concept
|
||||
of an ordered set of values[.](#overview-1.sentence-2)
|
||||
|
||||
For convenience, an object of type valarray<T> is referred
|
||||
to as an âarrayâ throughout the remainder of [[numarray]](numarray "29.6 Numeric arrays")[.](#overview-1.sentence-3)
|
||||
|
||||
The illusion of higher dimensionality
|
||||
may be produced by the familiar idiom of computed indices, together
|
||||
with the powerful subsetting capabilities provided
|
||||
by the generalized subscript operators[.](#overview-1.sentence-4)[248](#footnote-248 "The intent is to specify an array template that has the minimum functionality necessary to address aliasing ambiguities and the proliferation of temporary objects. Thus, the valarray template is neither a matrix class nor a field class. However, it is a very useful building block for designing such classes.")
|
||||
|
||||
[248)](#footnote-248)[248)](#footnoteref-248)
|
||||
|
||||
The intent is to specify
|
||||
an array template that has the minimum functionality
|
||||
necessary to address aliasing ambiguities and the proliferation of
|
||||
temporary objects[.](#footnote-248.sentence-1)
|
||||
|
||||
Thus, thevalarray template is neither a
|
||||
matrix class nor a field class[.](#footnote-248.sentence-2)
|
||||
|
||||
However, it is a very useful building block for designing such classes[.](#footnote-248.sentence-3)
|
||||
|
||||
#### [29.6.2.2](#valarray.cons) Constructors [[valarray.cons]](valarray.cons)
|
||||
|
||||
[ð](#lib:valarray,constructor)
|
||||
|
||||
`valarray();
|
||||
`
|
||||
|
||||
[1](#valarray.cons-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7333)
|
||||
|
||||
*Effects*: Constructs a valarray that has zero length[.](#valarray.cons-1.sentence-1)[249](#footnote-249 "This default constructor is essential, since arrays of valarray can be useful. After initialization, the length of an empty array can be increased with the resize member function.")
|
||||
|
||||
[ð](#lib:valarray,constructor_)
|
||||
|
||||
`explicit valarray(size_t n);
|
||||
`
|
||||
|
||||
[2](#valarray.cons-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7354)
|
||||
|
||||
*Effects*: Constructs a valarray that has length n[.](#valarray.cons-2.sentence-1)
|
||||
|
||||
Each element of the array is [value-initialized](dcl.init#def:value-initialization "9.5 Initializers [dcl.init]")[.](#valarray.cons-2.sentence-2)
|
||||
|
||||
[ð](#lib:valarray,constructor__)
|
||||
|
||||
`valarray(const T& v, size_t n);
|
||||
`
|
||||
|
||||
[3](#valarray.cons-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7366)
|
||||
|
||||
*Effects*: Constructs a valarray that has length n[.](#valarray.cons-3.sentence-1)
|
||||
|
||||
Each element of the array is initialized with v[.](#valarray.cons-3.sentence-2)
|
||||
|
||||
[ð](#lib:valarray,constructor___)
|
||||
|
||||
`valarray(const T* p, size_t n);
|
||||
`
|
||||
|
||||
[4](#valarray.cons-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7379)
|
||||
|
||||
*Preconditions*: [p, p + n) is a valid range[.](#valarray.cons-4.sentence-1)
|
||||
|
||||
[5](#valarray.cons-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7383)
|
||||
|
||||
*Effects*: Constructs a valarray that has length n[.](#valarray.cons-5.sentence-1)
|
||||
|
||||
The values of the elements of the array are initialized with the
|
||||
firstn values pointed to by the first argument[.](#valarray.cons-5.sentence-2)[250](#footnote-250 "This constructor is the preferred method for converting a C array to a valarray object.")
|
||||
|
||||
[ð](#lib:valarray,constructor____)
|
||||
|
||||
`valarray(const valarray& v);
|
||||
`
|
||||
|
||||
[6](#valarray.cons-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7404)
|
||||
|
||||
*Effects*: Constructs a valarray that has the same length as v[.](#valarray.cons-6.sentence-1)
|
||||
|
||||
The elements are initialized with the values of the corresponding
|
||||
elements of v[.](#valarray.cons-6.sentence-2)[251](#footnote-251 "This copy constructor creates a distinct array rather than an alias. Implementations in which arrays share storage are permitted, but they would need to implement a copy-on-reference mechanism to ensure that arrays are conceptually distinct.")
|
||||
|
||||
[ð](#lib:valarray,constructor_____)
|
||||
|
||||
`valarray(valarray&& v) noexcept;
|
||||
`
|
||||
|
||||
[7](#valarray.cons-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7424)
|
||||
|
||||
*Effects*: Constructs a valarray that has the same length as v[.](#valarray.cons-7.sentence-1)
|
||||
|
||||
The elements are initialized with the values of the corresponding
|
||||
elements of v[.](#valarray.cons-7.sentence-2)
|
||||
|
||||
[8](#valarray.cons-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7430)
|
||||
|
||||
*Complexity*: Constant[.](#valarray.cons-8.sentence-1)
|
||||
|
||||
[ð](#lib:valarray,constructor______)
|
||||
|
||||
`valarray(initializer_list<T> il);
|
||||
`
|
||||
|
||||
[9](#valarray.cons-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7441)
|
||||
|
||||
*Effects*: Equivalent to valarray(il.begin(), il.size())[.](#valarray.cons-9.sentence-1)
|
||||
|
||||
[ð](#lib:valarray,constructor_______)
|
||||
|
||||
`valarray(const slice_array<T>&);
|
||||
valarray(const gslice_array<T>&);
|
||||
valarray(const mask_array<T>&);
|
||||
valarray(const indirect_array<T>&);
|
||||
`
|
||||
|
||||
[10](#valarray.cons-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7455)
|
||||
|
||||
These conversion constructors convert one of the four reference templates
|
||||
to avalarray[.](#valarray.cons-10.sentence-1)
|
||||
|
||||
[ð](#lib:valarray,destructor)
|
||||
|
||||
`~valarray();
|
||||
`
|
||||
|
||||
[11](#valarray.cons-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7467)
|
||||
|
||||
*Effects*: The destructor is applied to every element of*this;
|
||||
an implementation may return all allocated memory[.](#valarray.cons-11.sentence-1)
|
||||
|
||||
[249)](#footnote-249)[249)](#footnoteref-249)
|
||||
|
||||
This default constructor is essential,
|
||||
since arrays ofvalarray can be useful[.](#footnote-249.sentence-1)
|
||||
|
||||
After initialization, the length of an empty array can be increased with theresize member function[.](#footnote-249.sentence-2)
|
||||
|
||||
[250)](#footnote-250)[250)](#footnoteref-250)
|
||||
|
||||
This constructor is the
|
||||
preferred method for converting a C array to avalarray object[.](#footnote-250.sentence-1)
|
||||
|
||||
[251)](#footnote-251)[251)](#footnoteref-251)
|
||||
|
||||
This copy constructor creates
|
||||
a distinct array rather than an alias[.](#footnote-251.sentence-1)
|
||||
|
||||
Implementations in which arrays share storage are permitted, but they
|
||||
would need to implement a copy-on-reference mechanism to ensure that arrays are
|
||||
conceptually distinct[.](#footnote-251.sentence-2)
|
||||
|
||||
#### [29.6.2.3](#valarray.assign) Assignment [[valarray.assign]](valarray.assign)
|
||||
|
||||
[ð](#lib:operator=,valarray)
|
||||
|
||||
`valarray& operator=(const valarray& v);
|
||||
`
|
||||
|
||||
[1](#valarray.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7482)
|
||||
|
||||
*Effects*: Each element of the*this array is assigned the value of the corresponding element of v[.](#valarray.assign-1.sentence-1)
|
||||
|
||||
If the length of v is not equal to the length of *this,
|
||||
resizes *this to make the two arrays the same length,
|
||||
as if by calling resize(v.size()), before performing the assignment[.](#valarray.assign-1.sentence-2)
|
||||
|
||||
[2](#valarray.assign-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7491)
|
||||
|
||||
*Postconditions*: size() == v.size()[.](#valarray.assign-2.sentence-1)
|
||||
|
||||
[3](#valarray.assign-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7495)
|
||||
|
||||
*Returns*: *this[.](#valarray.assign-3.sentence-1)
|
||||
|
||||
[ð](#lib:operator=,valarray_)
|
||||
|
||||
`valarray& operator=(valarray&& v) noexcept;
|
||||
`
|
||||
|
||||
[4](#valarray.assign-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7506)
|
||||
|
||||
*Effects*: *this obtains the value of v[.](#valarray.assign-4.sentence-1)
|
||||
|
||||
The value of v after the assignment is not specified[.](#valarray.assign-4.sentence-2)
|
||||
|
||||
[5](#valarray.assign-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7511)
|
||||
|
||||
*Returns*: *this[.](#valarray.assign-5.sentence-1)
|
||||
|
||||
[6](#valarray.assign-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7515)
|
||||
|
||||
*Complexity*: Linear[.](#valarray.assign-6.sentence-1)
|
||||
|
||||
[ð](#lib:operator=,valarray__)
|
||||
|
||||
`valarray& operator=(initializer_list<T> il);
|
||||
`
|
||||
|
||||
[7](#valarray.assign-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7526)
|
||||
|
||||
*Effects*: Equivalent to: return *this = valarray(il);
|
||||
|
||||
[ð](#lib:operator=,valarray___)
|
||||
|
||||
`valarray& operator=(const T& v);
|
||||
`
|
||||
|
||||
[8](#valarray.assign-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7538)
|
||||
|
||||
*Effects*: Assigns v to each element of *this[.](#valarray.assign-8.sentence-1)
|
||||
|
||||
[9](#valarray.assign-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7542)
|
||||
|
||||
*Returns*: *this[.](#valarray.assign-9.sentence-1)
|
||||
|
||||
[ð](#lib:operator=,valarray____)
|
||||
|
||||
`valarray& operator=(const slice_array<T>&);
|
||||
valarray& operator=(const gslice_array<T>&);
|
||||
valarray& operator=(const mask_array<T>&);
|
||||
valarray& operator=(const indirect_array<T>&);
|
||||
`
|
||||
|
||||
[10](#valarray.assign-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7556)
|
||||
|
||||
*Preconditions*: The length of the array to which the argument refers equals size()[.](#valarray.assign-10.sentence-1)
|
||||
|
||||
The value of an element in the left-hand side of a valarray assignment
|
||||
operator does not depend on the value of another element in that left-hand side[.](#valarray.assign-10.sentence-2)
|
||||
|
||||
[11](#valarray.assign-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7562)
|
||||
|
||||
These operators allow the results of a generalized subscripting operation
|
||||
to be assigned directly to avalarray[.](#valarray.assign-11.sentence-1)
|
||||
|
||||
#### [29.6.2.4](#valarray.access) Element access [[valarray.access]](valarray.access)
|
||||
|
||||
[ð](#lib:operator%5b%5d,valarray)
|
||||
|
||||
`const T& operator[](size_t n) const;
|
||||
T& operator[](size_t n);
|
||||
`
|
||||
|
||||
[1](#valarray.access-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7577)
|
||||
|
||||
*Hardened preconditions*: n < size() is true[.](#valarray.access-1.sentence-1)
|
||||
|
||||
[2](#valarray.access-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7581)
|
||||
|
||||
*Returns*: A reference to the corresponding element of the array[.](#valarray.access-2.sentence-1)
|
||||
|
||||
[*Note [1](#valarray.access-note-1)*:
|
||||
|
||||
The expression (a[i] = q, a[i]) == q evaluates to true for any non-constant valarray<T> a,
|
||||
any T q, and for any size_t i such that the value of i is less than the length of a[.](#valarray.access-2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#valarray.access-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7591)
|
||||
|
||||
*Remarks*: The expression addressof(a[i + j]) == addressof(a[i]) + j evaluates to true for all size_t i and size_t j such that i + j < a.size()[.](#valarray.access-3.sentence-1)
|
||||
|
||||
[4](#valarray.access-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7597)
|
||||
|
||||
The expression addressof(a[i]) != addressof(b[j]) evaluates to true for any two arraysa and b and for anysize_t i and size_t j such that i < a.size() and j < b.size()[.](#valarray.access-4.sentence-1)
|
||||
|
||||
[*Note [2](#valarray.access-note-2)*:
|
||||
|
||||
This property indicates an absence of aliasing and can be used to
|
||||
advantage by optimizing compilers[.](#valarray.access-4.sentence-2)
|
||||
|
||||
Compilers can take advantage
|
||||
of inlining, constant propagation, loop fusion,
|
||||
tracking of pointers obtained fromoperator new,
|
||||
and other techniques to generate efficientvalarrays[.](#valarray.access-4.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[5](#valarray.access-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7614)
|
||||
|
||||
The reference returned by the subscript operator for an array shall
|
||||
be valid until the member function[resize(size_t, T)](#lib:valarray,resize "29.6.2.8 Member functions [valarray.members]") is called for that array or until the lifetime of
|
||||
that array ends, whichever happens first[.](#valarray.access-5.sentence-1)
|
||||
|
||||
#### [29.6.2.5](#valarray.sub) Subset operations [[valarray.sub]](valarray.sub)
|
||||
|
||||
[1](#valarray.sub-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7624)
|
||||
|
||||
The member operator[] is overloaded to provide several ways to select
|
||||
sequences of elements from among those controlled by *this[.](#valarray.sub-1.sentence-1)
|
||||
|
||||
Each of these
|
||||
operations returns a subset of the array[.](#valarray.sub-1.sentence-2)
|
||||
|
||||
The const-qualified versions return this
|
||||
subset as a new valarray object[.](#valarray.sub-1.sentence-3)
|
||||
|
||||
The non-const versions return a class
|
||||
template object which has reference semantics to the original array, working in
|
||||
conjunction with various overloads of operator= and other assigning
|
||||
operators to allow selective replacement (slicing) of the controlled sequence[.](#valarray.sub-1.sentence-4)
|
||||
|
||||
In each case the selected element(s) shall exist[.](#valarray.sub-1.sentence-5)
|
||||
|
||||
[ð](#lib:operator%5b%5d,valarray__)
|
||||
|
||||
`valarray operator[](slice slicearr) const;
|
||||
`
|
||||
|
||||
[2](#valarray.sub-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7640)
|
||||
|
||||
*Returns*: A valarray containing those
|
||||
elements of the controlled sequence designated by slicearr[.](#valarray.sub-2.sentence-1)
|
||||
|
||||
[*Example [1](#valarray.sub-example-1)*: const valarray<char> v0("abcdefghijklmnop", 16);// v0[slice(2, 5, 3)] returns valarray<char>("cfilo", 5) â *end example*]
|
||||
|
||||
[ð](#lib:operator%5b%5d,valarray___)
|
||||
|
||||
`slice_array<T> operator[](slice slicearr);
|
||||
`
|
||||
|
||||
[3](#valarray.sub-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7658)
|
||||
|
||||
*Returns*: An object that holds references to elements of the controlled
|
||||
sequence selected by slicearr[.](#valarray.sub-3.sentence-1)
|
||||
|
||||
[*Example [2](#valarray.sub-example-2)*: valarray<char> v0("abcdefghijklmnop", 16);
|
||||
valarray<char> v1("ABCDE", 5);
|
||||
v0[slice(2, 5, 3)] = v1;// v0 == valarray<char>("abAdeBghCjkDmnEp", 16); â *end example*]
|
||||
|
||||
[ð](#lib:operator%5b%5d,valarray____)
|
||||
|
||||
`valarray operator[](const gslice& gslicearr) const;
|
||||
`
|
||||
|
||||
[4](#valarray.sub-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7678)
|
||||
|
||||
*Returns*: A valarray containing those
|
||||
elements of the controlled sequence designated by gslicearr[.](#valarray.sub-4.sentence-1)
|
||||
|
||||
[*Example [3](#valarray.sub-example-3)*: const valarray<char> v0("abcdefghijklmnop", 16);const size_t lv[] = { 2, 3 };const size_t dv[] = { 7, 2 };const valarray<size_t> len(lv, 2), str(dv, 2);// v0[gslice(3, len, str)] returns// valarray<char>("dfhkmo", 6) â *end example*]
|
||||
|
||||
[ð](#lib:operator%5b%5d,valarray_____)
|
||||
|
||||
`gslice_array<T> operator[](const gslice& gslicearr);
|
||||
`
|
||||
|
||||
[5](#valarray.sub-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7700)
|
||||
|
||||
*Returns*: An object that holds references to elements of the controlled
|
||||
sequence selected by gslicearr[.](#valarray.sub-5.sentence-1)
|
||||
|
||||
[*Example [4](#valarray.sub-example-4)*: valarray<char> v0("abcdefghijklmnop", 16);
|
||||
valarray<char> v1("ABCDEF", 6);const size_t lv[] = { 2, 3 };const size_t dv[] = { 7, 2 };const valarray<size_t> len(lv, 2), str(dv, 2);
|
||||
v0[gslice(3, len, str)] = v1;// v0 == valarray<char>("abcAeBgCijDlEnFp", 16) â *end example*]
|
||||
|
||||
[ð](#lib:operator%5b%5d,valarray______)
|
||||
|
||||
`valarray operator[](const valarray<bool>& boolarr) const;
|
||||
`
|
||||
|
||||
[6](#valarray.sub-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7723)
|
||||
|
||||
*Returns*: A valarray containing those
|
||||
elements of the controlled sequence designated by boolarr[.](#valarray.sub-6.sentence-1)
|
||||
|
||||
[*Example [5](#valarray.sub-example-5)*: const valarray<char> v0("abcdefghijklmnop", 16);const bool vb[] = { false, false, true, true, false, true };// v0[valarray<bool>(vb, 6)] returns// valarray<char>("cdf", 3) â *end example*]
|
||||
|
||||
[ð](#lib:operator%5b%5d,valarray_______)
|
||||
|
||||
`mask_array<T> operator[](const valarray<bool>& boolarr);
|
||||
`
|
||||
|
||||
[7](#valarray.sub-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7743)
|
||||
|
||||
*Returns*: An object that holds references to elements of the controlled
|
||||
sequence selected by boolarr[.](#valarray.sub-7.sentence-1)
|
||||
|
||||
[*Example [6](#valarray.sub-example-6)*: valarray<char> v0("abcdefghijklmnop", 16);
|
||||
valarray<char> v1("ABC", 3);const bool vb[] = { false, false, true, true, false, true };
|
||||
v0[valarray<bool>(vb, 6)] = v1;// v0 == valarray<char>("abABeCghijklmnop", 16) â *end example*]
|
||||
|
||||
[ð](#lib:operator%5b%5d,valarray________)
|
||||
|
||||
`valarray operator[](const valarray<size_t>& indarr) const;
|
||||
`
|
||||
|
||||
[8](#valarray.sub-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7764)
|
||||
|
||||
*Returns*: A valarray containing those
|
||||
elements of the controlled sequence designated by indarr[.](#valarray.sub-8.sentence-1)
|
||||
|
||||
[*Example [7](#valarray.sub-example-7)*: const valarray<char> v0("abcdefghijklmnop", 16);const size_t vi[] = { 7, 5, 2, 3, 8 };// v0[valarray<size_t>(vi, 5)] returns// valarray<char>("hfcdi", 5) â *end example*]
|
||||
|
||||
[ð](#lib:operator%5b%5d,valarray_________)
|
||||
|
||||
`indirect_array<T> operator[](const valarray<size_t>& indarr);
|
||||
`
|
||||
|
||||
[9](#valarray.sub-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7784)
|
||||
|
||||
*Returns*: An object that holds references to elements of the controlled
|
||||
sequence selected by indarr[.](#valarray.sub-9.sentence-1)
|
||||
|
||||
[*Example [8](#valarray.sub-example-8)*: valarray<char> v0("abcdefghijklmnop", 16);
|
||||
valarray<char> v1("ABCDE", 5);const size_t vi[] = { 7, 5, 2, 3, 8 };
|
||||
v0[valarray<size_t>(vi, 5)] = v1;// v0 == valarray<char>("abCDeBgAEjklmnop", 16) â *end example*]
|
||||
|
||||
#### [29.6.2.6](#valarray.unary) Unary operators [[valarray.unary]](valarray.unary)
|
||||
|
||||
[ð](#lib:operator+,valarray)
|
||||
|
||||
`valarray operator+() const;
|
||||
valarray operator-() const;
|
||||
valarray operator~() const;
|
||||
valarray<bool> operator!() const;
|
||||
`
|
||||
|
||||
[1](#valarray.unary-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7813)
|
||||
|
||||
*Mandates*: The indicated operator can be applied to operands of type T and returns a value of type T (bool foroperator!) or which may be unambiguously implicitly converted to typeT (bool for operator!)[.](#valarray.unary-1.sentence-1)
|
||||
|
||||
[2](#valarray.unary-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7820)
|
||||
|
||||
*Returns*: A valarray whose length is size()[.](#valarray.unary-2.sentence-1)
|
||||
|
||||
Each element of the returned array is initialized with the result of
|
||||
applying the indicated operator to the corresponding element of the array[.](#valarray.unary-2.sentence-2)
|
||||
|
||||
#### [29.6.2.7](#valarray.cassign) Compound assignment [[valarray.cassign]](valarray.cassign)
|
||||
|
||||
[ð](#lib:operator*=,valarray)
|
||||
|
||||
`valarray& operator*= (const valarray& v);
|
||||
valarray& operator/= (const valarray& v);
|
||||
valarray& operator%= (const valarray& v);
|
||||
valarray& operator+= (const valarray& v);
|
||||
valarray& operator-= (const valarray& v);
|
||||
valarray& operator^= (const valarray& v);
|
||||
valarray& operator&= (const valarray& v);
|
||||
valarray& operator|= (const valarray& v);
|
||||
valarray& operator<<=(const valarray& v);
|
||||
valarray& operator>>=(const valarray& v);
|
||||
`
|
||||
|
||||
[1](#valarray.cassign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7853)
|
||||
|
||||
*Mandates*: The indicated operator can be applied to two operands of type T[.](#valarray.cassign-1.sentence-1)
|
||||
|
||||
[2](#valarray.cassign-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7857)
|
||||
|
||||
*Preconditions*: size() == v.size() is true[.](#valarray.cassign-2.sentence-1)
|
||||
|
||||
The value of an element in the left-hand side of a valarray compound
|
||||
assignment operator does not depend on the value of another element in that left
|
||||
hand side[.](#valarray.cassign-2.sentence-2)
|
||||
|
||||
[3](#valarray.cassign-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7865)
|
||||
|
||||
*Effects*: Each of these operators
|
||||
performs the indicated operation on each of the elements of *this and the
|
||||
corresponding element of v[.](#valarray.cassign-3.sentence-1)
|
||||
|
||||
[4](#valarray.cassign-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7871)
|
||||
|
||||
*Returns*: *this[.](#valarray.cassign-4.sentence-1)
|
||||
|
||||
[5](#valarray.cassign-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7875)
|
||||
|
||||
*Remarks*: The appearance of an array on the left-hand side of a compound assignment
|
||||
does not invalidate references or pointers[.](#valarray.cassign-5.sentence-1)
|
||||
|
||||
[ð](#lib:operator*=,valarray_)
|
||||
|
||||
`valarray& operator*= (const T& v);
|
||||
valarray& operator/= (const T& v);
|
||||
valarray& operator%= (const T& v);
|
||||
valarray& operator+= (const T& v);
|
||||
valarray& operator-= (const T& v);
|
||||
valarray& operator^= (const T& v);
|
||||
valarray& operator&= (const T& v);
|
||||
valarray& operator|= (const T& v);
|
||||
valarray& operator<<=(const T& v);
|
||||
valarray& operator>>=(const T& v);
|
||||
`
|
||||
|
||||
[6](#valarray.cassign-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7905)
|
||||
|
||||
*Mandates*: The indicated operator can be applied to two operands of type T[.](#valarray.cassign-6.sentence-1)
|
||||
|
||||
[7](#valarray.cassign-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7909)
|
||||
|
||||
*Effects*: Each of these operators applies the indicated operation to each element
|
||||
of *this and v[.](#valarray.cassign-7.sentence-1)
|
||||
|
||||
[8](#valarray.cassign-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7914)
|
||||
|
||||
*Returns*: *this[.](#valarray.cassign-8.sentence-1)
|
||||
|
||||
[9](#valarray.cassign-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7918)
|
||||
|
||||
*Remarks*: The appearance of an array on the left-hand side of a compound assignment
|
||||
does not
|
||||
invalidate references or pointers to the elements of the array[.](#valarray.cassign-9.sentence-1)
|
||||
|
||||
#### [29.6.2.8](#valarray.members) Member functions [[valarray.members]](valarray.members)
|
||||
|
||||
[ð](#lib:swap,valarray)
|
||||
|
||||
`void swap(valarray& v) noexcept;
|
||||
`
|
||||
|
||||
[1](#valarray.members-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7933)
|
||||
|
||||
*Effects*: *this obtains the value ofv[.](#valarray.members-1.sentence-1)
|
||||
|
||||
v obtains the value of *this[.](#valarray.members-1.sentence-2)
|
||||
|
||||
[2](#valarray.members-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7938)
|
||||
|
||||
*Complexity*: Constant[.](#valarray.members-2.sentence-1)
|
||||
|
||||
[ð](#lib:size,valarray)
|
||||
|
||||
`size_t size() const;
|
||||
`
|
||||
|
||||
[3](#valarray.members-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7949)
|
||||
|
||||
*Returns*: The number of elements in the array[.](#valarray.members-3.sentence-1)
|
||||
|
||||
[4](#valarray.members-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7953)
|
||||
|
||||
*Complexity*: Constant time[.](#valarray.members-4.sentence-1)
|
||||
|
||||
[ð](#lib:sum,valarray)
|
||||
|
||||
`T sum() const;
|
||||
`
|
||||
|
||||
[5](#valarray.members-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7964)
|
||||
|
||||
*Mandates*: operator+= can be applied to operands of type T[.](#valarray.members-5.sentence-1)
|
||||
|
||||
[6](#valarray.members-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7968)
|
||||
|
||||
*Preconditions*: size() > 0 is true[.](#valarray.members-6.sentence-1)
|
||||
|
||||
[7](#valarray.members-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7972)
|
||||
|
||||
*Returns*: The sum of all the elements of the array[.](#valarray.members-7.sentence-1)
|
||||
|
||||
If the array has length 1, returns the value of element 0[.](#valarray.members-7.sentence-2)
|
||||
|
||||
Otherwise, the returned value is calculated by applyingoperator+= to a copy of an element of the array and
|
||||
all other elements of the array in an unspecified order[.](#valarray.members-7.sentence-3)
|
||||
|
||||
[ð](#lib:min,valarray)
|
||||
|
||||
`T min() const;
|
||||
`
|
||||
|
||||
[8](#valarray.members-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7988)
|
||||
|
||||
*Preconditions*: size() > 0 is true[.](#valarray.members-8.sentence-1)
|
||||
|
||||
[9](#valarray.members-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7992)
|
||||
|
||||
*Returns*: The minimum value contained in *this[.](#valarray.members-9.sentence-1)
|
||||
|
||||
For an array of length 1, the value of element 0 is returned[.](#valarray.members-9.sentence-2)
|
||||
|
||||
For all other array
|
||||
lengths, the determination is made usingoperator<[.](#valarray.members-9.sentence-3)
|
||||
|
||||
[ð](#lib:max,valarray)
|
||||
|
||||
`T max() const;
|
||||
`
|
||||
|
||||
[10](#valarray.members-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8007)
|
||||
|
||||
*Preconditions*: size() > 0 is true[.](#valarray.members-10.sentence-1)
|
||||
|
||||
[11](#valarray.members-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8011)
|
||||
|
||||
*Returns*: The maximum value contained in *this[.](#valarray.members-11.sentence-1)
|
||||
|
||||
For an array of length 1, the value of element 0 is returned[.](#valarray.members-11.sentence-2)
|
||||
|
||||
For all other array
|
||||
lengths, the determination is made usingoperator<[.](#valarray.members-11.sentence-3)
|
||||
|
||||
[ð](#lib:shift,valarray)
|
||||
|
||||
`valarray shift(int n) const;
|
||||
`
|
||||
|
||||
[12](#valarray.members-12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8026)
|
||||
|
||||
*Returns*: A valarray of length size(), each of whose elements*I* is(*this)[*I* + n] if *I* + n is non-negative and less thansize(), otherwise T()[.](#valarray.members-12.sentence-1)
|
||||
|
||||
[*Note [1](#valarray.members-note-1)*:
|
||||
|
||||
If element zero is taken as the leftmost element,
|
||||
a positive value of n shifts the elements left n places, with zero fill[.](#valarray.members-12.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[13](#valarray.members-13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8040)
|
||||
|
||||
[*Example [1](#valarray.members-example-1)*:
|
||||
|
||||
If the argument has the value â2,
|
||||
the first two elements of the result will be [value-initialized](dcl.init#def:value-initialization "9.5 Initializers [dcl.init]"); the third element of the result will be assigned the value
|
||||
of the first element of *this; etc[.](#valarray.members-13.sentence-1)
|
||||
|
||||
â *end example*]
|
||||
|
||||
[ð](#lib:cshift,valarray)
|
||||
|
||||
`valarray cshift(int n) const;
|
||||
`
|
||||
|
||||
[14](#valarray.members-14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8054)
|
||||
|
||||
*Returns*: A valarray of length size() that is a circular shift of *this[.](#valarray.members-14.sentence-1)
|
||||
|
||||
If element zero is taken as
|
||||
the leftmost element, a non-negative value of n shifts
|
||||
the elements circularly left n places and a negative
|
||||
value of n shifts the elements circularly right ân places[.](#valarray.members-14.sentence-2)
|
||||
|
||||
[ð](#lib:apply,valarray)
|
||||
|
||||
`valarray apply(T func(T)) const;
|
||||
valarray apply(T func(const T&)) const;
|
||||
`
|
||||
|
||||
[15](#valarray.members-15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8070)
|
||||
|
||||
*Returns*: A valarray whose length is size()[.](#valarray.members-15.sentence-1)
|
||||
|
||||
Each element of the returned array is assigned
|
||||
the value returned by applying the argument function to the
|
||||
corresponding element of *this[.](#valarray.members-15.sentence-2)
|
||||
|
||||
[ð](#lib:resize,valarray)
|
||||
|
||||
`void resize(size_t sz, T c = T());
|
||||
`
|
||||
|
||||
[16](#valarray.members-16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L8084)
|
||||
|
||||
*Effects*: Changes the length of the *this array to sz and then assigns to each element the value of the second argument[.](#valarray.members-16.sentence-1)
|
||||
|
||||
Resizing invalidates all pointers and references to elements in the array[.](#valarray.members-16.sentence-2)
|
||||
102
cppdraft/template/valarray/overview.md
Normal file
102
cppdraft/template/valarray/overview.md
Normal file
@@ -0,0 +1,102 @@
|
||||
[template.valarray.overview]
|
||||
|
||||
# 29 Numerics library [[numerics]](./#numerics)
|
||||
|
||||
## 29.6 Numeric arrays [[numarray]](numarray#template.valarray.overview)
|
||||
|
||||
### 29.6.2 Class template valarray [[template.valarray]](template.valarray#overview)
|
||||
|
||||
#### 29.6.2.1 Overview [template.valarray.overview]
|
||||
|
||||
[ð](#lib:valarray)
|
||||
|
||||
namespace std {template<class T> class valarray {public:using value_type = T; // [[valarray.cons]](valarray.cons "29.6.2.2 Constructors"), construct/destroy valarray(); explicit valarray(size_t);
|
||||
valarray(const T&, size_t);
|
||||
valarray(const T*, size_t);
|
||||
valarray(const valarray&);
|
||||
valarray(valarray&&) noexcept;
|
||||
valarray(const slice_array<T>&);
|
||||
valarray(const gslice_array<T>&);
|
||||
valarray(const mask_array<T>&);
|
||||
valarray(const indirect_array<T>&);
|
||||
valarray(initializer_list<T>); ~valarray(); // [[valarray.assign]](valarray.assign "29.6.2.3 Assignment"), assignment valarray& operator=(const valarray&);
|
||||
valarray& operator=(valarray&&) noexcept;
|
||||
valarray& operator=(initializer_list<T>);
|
||||
valarray& operator=(const T&);
|
||||
valarray& operator=(const slice_array<T>&);
|
||||
valarray& operator=(const gslice_array<T>&);
|
||||
valarray& operator=(const mask_array<T>&);
|
||||
valarray& operator=(const indirect_array<T>&); // [[valarray.access]](valarray.access "29.6.2.4 Element access"), element accessconst T& operator[](size_t) const;
|
||||
T& operator[](size_t); // [[valarray.sub]](valarray.sub "29.6.2.5 Subset operations"), subset operations valarray operator[](slice) const;
|
||||
slice_array<T> operator[](slice);
|
||||
valarray operator[](const gslice&) const;
|
||||
gslice_array<T> operator[](const gslice&);
|
||||
valarray operator[](const valarray<bool>&) const;
|
||||
mask_array<T> operator[](const valarray<bool>&);
|
||||
valarray operator[](const valarray<size_t>&) const;
|
||||
indirect_array<T> operator[](const valarray<size_t>&); // [[valarray.unary]](valarray.unary "29.6.2.6 Unary operators"), unary operators valarray operator+() const;
|
||||
valarray operator-() const;
|
||||
valarray operator~() const;
|
||||
valarray<bool> operator!() const; // [[valarray.cassign]](valarray.cassign "29.6.2.7 Compound assignment"), compound assignment valarray& operator*= (const T&);
|
||||
valarray& operator/= (const T&);
|
||||
valarray& operator%= (const T&);
|
||||
valarray& operator+= (const T&);
|
||||
valarray& operator-= (const T&);
|
||||
valarray& operator^= (const T&);
|
||||
valarray& operator&= (const T&);
|
||||
valarray& operator|= (const T&);
|
||||
valarray& operator<<=(const T&);
|
||||
valarray& operator>>=(const T&);
|
||||
|
||||
valarray& operator*= (const valarray&);
|
||||
valarray& operator/= (const valarray&);
|
||||
valarray& operator%= (const valarray&);
|
||||
valarray& operator+= (const valarray&);
|
||||
valarray& operator-= (const valarray&);
|
||||
valarray& operator^= (const valarray&);
|
||||
valarray& operator|= (const valarray&);
|
||||
valarray& operator&= (const valarray&);
|
||||
valarray& operator<<=(const valarray&);
|
||||
valarray& operator>>=(const valarray&); // [[valarray.members]](valarray.members "29.6.2.8 Member functions"), member functionsvoid swap(valarray&) noexcept;
|
||||
|
||||
size_t size() const;
|
||||
|
||||
T sum() const;
|
||||
T min() const;
|
||||
T max() const;
|
||||
|
||||
valarray shift (int) const;
|
||||
valarray cshift(int) const;
|
||||
valarray apply(T func(T)) const;
|
||||
valarray apply(T func(const T&)) const; void resize(size_t sz, T c = T()); }; template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7299)
|
||||
|
||||
The
|
||||
class templatevalarray<T> is a
|
||||
one-dimensional smart array, with elements numbered sequentially from zero[.](#1.sentence-1)
|
||||
|
||||
It is a representation of the mathematical concept
|
||||
of an ordered set of values[.](#1.sentence-2)
|
||||
|
||||
For convenience, an object of type valarray<T> is referred
|
||||
to as an âarrayâ throughout the remainder of [[numarray]](numarray "29.6 Numeric arrays")[.](#1.sentence-3)
|
||||
|
||||
The illusion of higher dimensionality
|
||||
may be produced by the familiar idiom of computed indices, together
|
||||
with the powerful subsetting capabilities provided
|
||||
by the generalized subscript operators[.](#1.sentence-4)[248](#footnote-248 "The intent is to specify an array template that has the minimum functionality necessary to address aliasing ambiguities and the proliferation of temporary objects. Thus, the valarray template is neither a matrix class nor a field class. However, it is a very useful building block for designing such classes.")
|
||||
|
||||
[248)](#footnote-248)[248)](#footnoteref-248)
|
||||
|
||||
The intent is to specify
|
||||
an array template that has the minimum functionality
|
||||
necessary to address aliasing ambiguities and the proliferation of
|
||||
temporary objects[.](#footnote-248.sentence-1)
|
||||
|
||||
Thus, thevalarray template is neither a
|
||||
matrix class nor a field class[.](#footnote-248.sentence-2)
|
||||
|
||||
However, it is a very useful building block for designing such classes[.](#footnote-248.sentence-3)
|
||||
Reference in New Issue
Block a user