This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.
Section: 29.6.4 [class.slice] Status: CD1 Submitter: Howard Hinnant Opened: 2005-11-03 Last modified: 2016-01-28
Priority: Not Prioritized
View all issues with CD1 status.
Discussion:
If one explicitly constructs a slice or glice with the default constructor, does the standard require this slice to have any usable state? It says "creates a slice which specifies no elements", which could be interpreted two ways:
Here is a bit of code to illustrate:
#include <iostream> #include <valarray> int main() { std::valarray<int> v(10); std::valarray<int> v2 = v[std::slice()]; std::cout << "v[slice()].size() = " << v2.size() << '\n'; }
Is the behavior undefined? Or should the output be:
v[slice()].size() = 0
There is a similar question and wording for gslice at 26.3.6.1p1.
Proposed resolution:
[Martin suggests removing the second sentence in 29.6.4.2 [cons.slice] as well.]
Change 29.6.4.2 [cons.slice]:
1 -
The default constructor forThe default constructor is equivalent toslice
creates aslice
which specifies no elements.slice(0, 0, 0)
. A default constructor is provided only to permit the declaration of arrays of slices. The constructor with arguments for a slice takes a start, length, and stride parameter.
Change 29.6.6.2 [gslice.cons]:
1 -
The default constructor creates aThe default constructor is equivalent togslice
which specifies no elements.gslice(0, valarray<size_t>(), valarray<size_t>())
. The constructor with arguments builds agslice
based on a specification of start, lengths, and strides, as explained in the previous section.