I am trying below python code in c++. So that I can create a wrapper for my this python code to speed up the execution of the code (the original code is different. Right now I am trying on small piece of code which includes deque and dictionary).
Python:
from collections import deque
d=deque()
d.append({'a':1,'b':2})
d.append({'c':3,'d':4})
print(d)
output: deque([{'a': 1, 'b': 2}, {'c': 3, 'd': 4}])
C++ 14:
#include <deque>
#include <iostream>
using namespace std;
#include <map>
std::map<char, int> my_map = {
{ 'a', 1 },
{ 'b', 2 }
};
int main()
{
deque<int> mydeque;
mydeque.push_back(my_map);
return 0;
}
This gives me an error which is obvious. I don't know how to put a dictionary element to the deque?
prog.cpp: In function 'int main()': prog.cpp:16:29: error: no matching function for call to 'std::deque::push_back(std::map&)' mydeque.push_back(my_map); ^ In file included from /usr/include/c++/5/deque:64:0, from prog.cpp:1: /usr/include/c++/5/bits/stl_deque.h:1516:7: note: candidate: void std::deque<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator; std::deque<_Tp, _Alloc>::value_type = int] push_back(const value_type& __x) ^ /usr/include/c++/5/bits/stl_deque.h:1516:7: note: no known conversion for argument 1 from 'std::map' to 'const value_type& {aka const int&}' /usr/include/c++/5/bits/stl_deque.h:1531:7: note: candidate: void std::deque<_Tp, _Alloc>::push_back(std::deque<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator; std::deque<_Tp, _Alloc>::value_type = int] push_back(value_type&& __x) ^ /usr/include/c++/5/bits/stl_deque.h:1531:7: note: no known conversion for argument 1 from 'std::map' to 'std::deque::value_type&& {aka int&&}'
int
items. – user7860670std::deque<std::map<char, int>>
– Jean-François Fabre♦