Title
Issues of seed_seq's constructors
Status
c++23
Section
[rand.util.seedseq]
Submitter
Jiang An

Created on 2020-03-25.00:00:00 last changed 13 months ago

Messages

Date: 2021-10-14.09:56:08

Proposed resolution:

This wording is relative to N4861.

  1. Modify [rand.util.seedseq] as indicated:

    class seed_seq {
    public:
      // types
      using result_type = uint_least32_t;
    
      // constructors
      seed_seq() noexcept;
      […]
    };
    
    seed_seq() noexcept;
    

    -1- Postconditions: v.empty() is true.

    -2- Throws: Nothing.

    template<class T>
      seed_seq(initializer_list<T> il);
    

    -3- ConstraintsMandates: T is an integer type.

    -4- Effects: Same as seed_seq(il.begin(), il.end()).

Date: 2021-10-14.00:00:00

[ 2021-10-14 Approved at October 2021 virtual plenary. Status changed: Voting → WP. ]

Date: 2021-06-15.00:00:00

[ 2021-06-23; Reflector poll ]

Set status to Tentatively Ready after five votes in favour during reflector poll.

Date: 2020-04-18.00:00:00

[ 2020-04-18 Issue Prioritization ]

Priority to 3 after reflector discussion.

Date: 2020-03-25.00:00:00

[rand.util.seedseq] says that std::seed_seq has following 3 constructors:

  1. #1: seed_seq()

  2. #2: template<class T> seed_seq(initializer_list<T> il)

  3. #3: template<class InputIterator> seed_seq(InputIterator begin, InputIterator end)

The default constructor (#1) has no precondition and does not throw, and vector<result_type>'s default constructor is already noexcept since C++17, so #1 should also be noexcept.

Despite that the vector<result_type> member is exposition-only, current implementations (at least libc++, libstdc++ and MSVC STL) all hold it as the only data member of seed_seq, even with different names. And #1 is already noexcept in libc++ and libstdc++.

These constructors are not constrained, so #3 would never be matched in list-initialization. Consider following code:

#include <random>
#include <vector>

int main()
{
  std::vector<int> v(32);
  std::seed_seq{std::begin(v), std::end(v)}; // error: #2 matched and T is not an integer type
  std::seed_seq(std::begin(v), std::end(v)); // OK
}

#3 should be made available in list-initialization by changing Mandates in [rand.util.seedseq]/3 to Constraints IMO.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2021-10-14 09:56:08adminsetmessages: + msg12118
2021-10-14 09:56:08adminsetstatus: voting -> wp
2021-09-29 12:57:28adminsetstatus: ready -> voting
2021-06-23 14:16:45adminsetmessages: + msg11955
2021-06-23 14:16:45adminsetstatus: new -> ready
2020-04-18 12:05:14adminsetmessages: + msg11219
2020-04-04 19:55:09adminsetmessages: + msg11194
2020-03-25 00:00:00admincreate