public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "TonyELewis at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/96731] New: uniform_int_distribution requirement that its type is_integral is too strict
Date: Fri, 21 Aug 2020 06:19:22 +0000	[thread overview]
Message-ID: <bug-96731-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96731

            Bug ID: 96731
           Summary: uniform_int_distribution requirement that its type
                    is_integral is too strict
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: TonyELewis at hotmail dot com
  Target Milestone: ---

Following on from https://github.com/ericniebler/range-v3/issues/1532 ...

I think the static_assert requirement in libstdc++'s uniform_int_distribution
code that its template argument type is_integral may be too strict.

I can't see any obvious mention of constraints on uniform_­int_­distribution's
IntType in http://eel.is/c++draft/rand.dist.uni.int

The motivating case is attempting to sample from a range-v3 view::indices. The
range-v3 clever tricks lead to uniform_int_distribution being invoked with a
range-v3 type.

This all works OK under libc++ because it doesn't impose any requirements on
the type. But the aforementioned static_assert in libstdc++ won't allow it.

The problem can be seen with the first error under GCC or Clang with -std=c++17
on this code:


#include <algorithm>
#include <iterator>
#include <random>
#include <vector>

#include <range/v3/view/indices.hpp>

void fill_vec_with_random_sample_of_first_n_ints( const size_t         
&prm_num_possible_vals,
                                                  std::vector<size_t>
&prm_result,
                                                  std::mt19937        &prm_rng
                                                  ) {
        auto some_indices = ranges::views::indices( prm_num_possible_vals );
        std::sample(
                std::begin( some_indices ),
                std::end  ( some_indices ),
                std::begin( prm_result ),
                static_cast<ptrdiff_t>( prm_result.size() ),
                prm_rng
        );
}


Compiler Explorer : https://godbolt.org/z/MxrazP


One option is that libstdc++ could use std::numeric_limits<T>::is_integer
instead of std::is_integral, so that range-v3 could then specialise accordingly
for its type.

             reply	other threads:[~2020-08-21  6:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21  6:19 TonyELewis at hotmail dot com [this message]
2020-08-21  8:52 ` [Bug libstdc++/96731] " redi at gcc dot gnu.org
2020-08-21  8:55 ` redi at gcc dot gnu.org
2020-08-24  6:44 ` TonyELewis at hotmail dot com
2020-08-26 19:15 ` redi at gcc dot gnu.org
2020-09-04 10:39 ` TonyELewis at hotmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-96731-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).