Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofResolved status.

1129.istream(buf)_iterator should support literal sentinel value

Section: 24.6.2.2[istream.iterator.cons], 24.6.4[istreambuf.iterator]Status:ResolvedSubmitter: Alisdair MeredithOpened: 2009-05-30Last modified: 2016-01-28

Priority:Not Prioritized

View all otherissues in [istream.iterator.cons].

View all issues withResolved status.

Discussion:

istream_iterator andistreambuf_iterator should support literal sentinelvalues. The default constructor is frequently used to terminate ranges, andcould easily be a literal value foristreambuf_iterator, andistream_iterator when iterating value types. A little more work using asuitably sized/aligned char-array for storage (or an updated component likeboost::optional proposed for TR2) would allowistream_iterator to supportconstexpr default constructor in all cases, although we might leave thistweak as a QoI issue. Note that requiringconstexpr be supported alsoallows us to place no-throw guarantees on this constructor too.

[2009-06-02 Daniel adds:]

I agree with the usefulness of the issue suggestion, but we needto ensure thatistream_iteratorcan satisfy be literal if needed.Currently this is not clear, because 24.6.2[istream.iterator]/3 declaresa copy constructor and a destructor and explains their semantic in24.6.2.2[istream.iterator.cons]/3+4.

The prototype semantic specification is ok (although it seemssomewhat redundant to me, because the semantic doesn't sayanything interesting in both cases), but for support of trivial classtypes we also need a trivial copy constructor and destructor as of11[class]/6. The current non-informative specification of thesetwo special members suggests to remove their explicit declarationin the class and add explicit wording that says that ifT istrivial a default constructed iterator is also literal, alternatively itwould be possible to mark both as defaulted and add explicit(memberwise) wording that guarantees that they are trivial.

Btw.: I'm quite sure that theistreambuf_iterator additions toensure triviality are not sufficient as suggested, because thelibrary does not yet give general guarantees that a defaultedspecial member declaration makes this member also trivial.Note that e.g. the atomic types do give a general statement!

Finally there is a wording issue: There does not exist somethinglike a "literal constructor". The core language uses the term"constexpr constructor" for this.

Suggestion:

  1. Change 24.6.2[istream.iterator]/3 as indicated:

    constexpr istream_iterator();istream_iterator(istream_type& s);istream_iterator(const istream_iterator<T,charT,traits,Distance>& x) = default;~istream_iterator() = default;
  2. Change 24.6.2.2[istream.iterator.cons]/1 as indicated:

    constexpr istream_iterator();

    -1-Effects: Constructs the end-of-stream iterator.IfT is a literal type,then this constructor shall be a constexpr constructor.

  3. Change 24.6.2.2[istream.iterator.cons]/3 as indicated:

    istream_iterator(const istream_iterator<T,charT,traits,Distance>& x) = default;

    -3-Effects: Constructs a copy ofx.IfT is a literal type, thenthis constructor shall be a trivial copy constructor.

  4. Change 24.6.2.2[istream.iterator.cons]/4 as indicated:

    ~istream_iterator() = default;

    -4-Effects: The iterator is destroyed.IfT is a literal type, thenthis destructor shall be a trivialdestructor.

  5. Change 24.6.4[istreambuf.iterator] before p. 1 as indicated:

    constexpr istreambuf_iterator() throw();istreambuf_iterator(const istreambuf_iterator&)  throw() = default;~istreambuf_iterator()  throw() = default;
  6. Change 24.6.4[istreambuf.iterator]/1 as indicated:

    [..] The default constructoristreambuf_iterator() and the constructoristreambuf_iterator(0) both construct an end of stream iterator object suitable for use as an end-of-range.All specializations ofistreambuf_iterator shall have a trivial copy constructor, a constexpr default constructor and a trivial destructor.

[2009-10 Santa Cruz:]

NAD EditorialResolved. Addressed byN2994.

Proposed resolution:

24.6.2[istream.iterator] para 3

constexpr istream_iterator();

24.6.2.2[istream.iterator.cons]

constexpr istream_iterator();

-1-Effects: Constructs the end-of-stream iterator.IfT is a literal type, then this constructor shallbe a literal constructor.

24.6.4[istreambuf.iterator]

constexpr istreambuf_iterator() throw();

[8]ページ先頭

©2009-2026 Movatter.jp