1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
void push_back( std::map< std::string, std::vector<int> >& map, std::string key, std::initializer_list<int> il )
{
auto& values = map[key] ;
values.insert( values.end(), il ) ;
}
template < typename ITERATOR >
void push_back( std::map< std::string, std::vector<int> >& map, std::string key, ITERATOR begin, ITERATOR end )
{
auto& values = map[key] ;
values.insert( values.end(), begin, end ) ;
}
int main()
{
std::map< std::string, std::vector<int> > map ;
push_back( map, "abcd", { 0, 1, 2, 3, 4 } ) ;
const int values[] = { 5, 6, 7, 8 } ;
push_back( map, "abcd", std::begin(values), std::end(values) ) ;
for( int v : map["abcd"] ) std::cout << v << ' ' ;
std::cout << '\n' ;
}
|