stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Sebor (JIRA)" <>
Subject [jira] Created: (STDCXX-126) std::random_shuffle ambiguity with RandomNumberGenerator
Date Thu, 26 Jan 2006 00:34:10 GMT
std::random_shuffle ambiguity with RandomNumberGenerator

         Key: STDCXX-126
     Project: STDCXX
        Type: Bug
  Components: 25. Algorithms  
    Versions: 4.1.3    
 Environment: all
    Reporter: Martin Sebor
    Priority: Minor
     Fix For: 4.1.4

>From 25.2.11, p3 [lib.alg.random.shuffle]:

-3- Note random_shuffle() can take a particular random number generating function object rand
such that if n is an argument for rand, with a positive value, that has type iterator_traits<RandomAccessIterator>::difference_type,
then rand(n) returns a randomly chosen value, which lies in the interval [0, n), and which
has a type that is convertible to iterator_traits<RandomAccessIterator>::difference_type.

The program below conforms to the requirement above yet  fails to compile:

$ cat t.cpp && make t
#include <algorithm>
#include <iterator>
#include <cstddef>

template <class IntT>
struct Generator
    struct DiffConvertible {
        DiffConvertible (IntT) { }
        operator IntT () const { return IntT (); }

    DiffConvertible operator() (DiffConvertible n) const {
        return DiffConvertible (IntT (n));

    void operator() (unsigned) { }
    void operator() (unsigned long) { }

int main ()
    Generator<std::iterator_traits<int*>::difference_type> gen;

    std::random_shuffle<int*>(0, 0, gen);
gcc -c -I/build/sebor/dev/stdlib/include/ansi -D_RWSTDDEBUG   -pthreads -D_RWSTD_USE_CONFIG
-I/build/sebor/gcc-4.0.2-15s/include -I/build/sebor/dev/stdlib/include -I/build/sebor/dev/stdlib/../rwtest
-I/build/sebor/dev/stdlib/../rwtest/include -I/build/sebor/dev/stdlib/tests/include  -pedantic
-nostdinc++ -g  -W -Wall -Wextra -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long
/build/sebor/dev/stdlib/include/ In function 'void std::random_shuffle(_RandomAccessIter,
_RandomAccessIter, _RandomNumberGenerator&) [with _RandomAccessIter = int*, _RandomNumberGenerator
= Generator<int>]':
t.cpp:26:   instantiated from here
t.cpp:18: error: 'void Generator<IntT>::operator()(unsigned int) [with IntT = int]'
is private
/build/sebor/dev/stdlib/include/ error: within this context
t.cpp:26:   instantiated from here
/build/sebor/dev/stdlib/include/ error: void value not ignored as it ought
to be
make: *** [t.o] Error 1

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:

View raw message