Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
4.1.3
-
None
-
all
Description
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 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
};
DiffConvertible operator() (DiffConvertible n) const
{ return DiffConvertible (IntT (n)); }private:
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 t.cpp
/build/sebor/dev/stdlib/include/algorithm.cc: 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/algorithm.cc:594: error: within this context
t.cpp:26: instantiated from here
/build/sebor/dev/stdlib/include/algorithm.cc:594: error: void value not ignored as it ought to be
make: *** [t.o] Error 1