How should I declare std::list(1) with iterators to std::map, which maps std::string to iterators of std::list (1) ? Is it possible?
std::list<std::map<std::string, (1) ???>::iterator>;
std::map<std::string, (1) ???::iterator>;
The reason I want this - FIFO queue with ability to fast remove by key.
One possible solution:
struct decl_t {
typedef std::map< std::string, decl_t > map_t;
typedef std::list< std::pair< int, typename map_t::iterator > > list_t;
list_t::iterator it;
};
Here is ugly, but complete example
#include <cassert>
#include <iostream>
#include <list>
#include <map>
#include <string>
struct decl_t {
typedef std::map<std::string, decl_t> map_t;
typedef std::list<std::pair<int, typename map_t::iterator>> list_t;
list_t::iterator it;
};
int main(int argc, const char* argv[])
{
decl_t::map_t map;
decl_t::list_t list;
auto list_it = list.emplace(list.end(), 42, decl_t::map_t::iterator());
const auto pair = std::make_pair(std::string("key"), decl_t{list_it});
auto result = map.insert(pair);
assert(result.second);
auto map_it = result.first;
list_it->second = map_it;
std::cout << list_it->second->first << std::endl;
std::cout << map_it->second.it->first << std::endl;
}
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras