생성 된 요소 목록을 임의로 만들려고합니다. 코드는 다음과 같습니다.std :: shuffle이 std :: list와 함께 컴파일되지 않습니다.
std::default_random_engine generator (10);
std::list<int> list(10);
int n = 0;
std::generate(list.begin(), list.end(), [&]{ return n++; });
std::shuffle(list.begin(), list.end(), generator);
컴파일되지 않습니다. 다음은 오류입니다.
/include/c++/v1/algorithm:3059:34: Invalid operands to binary expression ('std::__1::__list_iterator<int, void *>' and 'std::__1::__list_iterator<int, void *>')
main.cpp:1:10: In file included from main.cpp:1:
/include/c++/v1/random:1641:10: In file included from /bin/../include/c++/v1/random:1641:
main.cpp:37:10: In instantiation of function template specialization 'std::__1::shuffle<std::__1::__list_iterator<int, void *>, std::__1::linear_congruential_engine<unsigned int, 48271, 0, 2147483647> &>' requested here
/include/c++/v1/iterator:622:1: Candidate template ignored: could not match 'reverse_iterator' against '__list_iterator'
/include/c++/v1/iterator:1017:1: Candidate template ignored: could not match 'move_iterator' against '__list_iterator'
/include/c++/v1/iterator:1369:1: Candidate template ignored: could not match '__wrap_iter' against '__list_iterator'
/include/c++/v1/string:486:11: Candidate template ignored: could not match 'fpos' against '__list_iterator'
아무도 아이디어가 있습니까?
'iota' 호출은 ADL을 통해'std :: iota'를 가져 오는 것이 보장되지 않습니다. –
@ T.C .: 맞습니다. 벡터 반복자는 포인터 일 수 있습니다. 나는 그 전화를 자격을 얻는 편이 낫다. –