プログラム1:
#include <iostream>
#include <cstdlib>
#include <vector>
int main(){
//compiles successfully
std::vector<int> vec{1,2,3,4,5};
return EXIT_SUCCESS;
}
プログラム2:
#include <iostream>
#include <cstdlib>
#include <queue>
int main(){
//compiler error
std::queue<int> que{1,2,3,4,5};
return EXIT_SUCCESS;
}
エラーメッセージ:
main.cpp: In function ‘int main()’:
main.cpp:7:31: error: no matching function for call to ‘std::queue<int>::queue(<brace-enclosed initializer list>)’
main.cpp:7:31: note: candidates are:
/usr/include/c++/4.6/bits/stl_queue.h:141:7: note: std::queue<_Tp, _Sequence>::queue(_Sequence&&) [with _Tp = int, _Sequence = std::deque<int, std::allocator<int> >]
/usr/include/c++/4.6/bits/stl_queue.h:141:7: note: candidate expects 1 argument, 5 provided
/usr/include/c++/4.6/bits/stl_queue.h:137:7: note: std::queue<_Tp, _Sequence>::queue(const _Sequence&) [with _Tp = int, _Sequence = std::deque<int, std::allocator<int> >]
/usr/include/c++/4.6/bits/stl_queue.h:137:7: note: candidate expects 1 argument, 5 provided
/usr/include/c++/4.6/bits/stl_queue.h:92:11: note: std::queue<int>::queue(const std::queue<int>&)
/usr/include/c++/4.6/bits/stl_queue.h:92:11: note: candidate expects 1 argument, 5 provided
/usr/include/c++/4.6/bits/stl_queue.h:92:11: note: std::queue<int>::queue(std::queue<int>&&)
/usr/include/c++/4.6/bits/stl_queue.h:92:11: note: candidate expects 1 argument, 5 provided
質問:
キューをベクトルのように初期化できないのはなぜですか?
それらはシーケンスコンテナではないと思いますが、なぜそれが重要なのでしょうか。
正当な理由があると思いますが、説明が見つかりません。
gcc(Ubuntu / Linaro 4.6.1-9ubuntu3)4.6.1