Warum kann ich nicht bauen eine queue/stack mit brace-enclosed-Initialisierer-Listen? (C++11)

Programm 1:

#include <iostream>
#include <cstdlib>
#include <vector>

int main(){

    //compiles successfully 
    std::vector<int> vec{1,2,3,4,5};

    return EXIT_SUCCESS;
}

Programm 2:

#include <iostream>
#include <cstdlib>
#include <queue>

int main(){

    //compiler error
    std::queue<int> que{1,2,3,4,5};

    return EXIT_SUCCESS;
}

Fehlermeldung:

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

Frage:

warum kann nicht-queues initialisiert werden wie Vektoren?

Ich nehme an, Sie sind nicht-Sequenz-Container, aber warum wäre das wichtig?

Ich bin sicher, es gibt einen guten Grund, aber ich kann nicht finden eine Erklärung.

gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1

  • Sie können die Referenz auf den Container hier. Sie können sich auch ein Blick auf die boost::assign-Bibliothek hier.
Schreibe einen Kommentar