1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <deque>
template< typename CONTAINER >
void insert_data( typename CONTAINER::value_type&& value, CONTAINER& container )
//{ container.insert( container.end(), value ) ; } // this is a push_back for sequence containers
{ container.insert( container.end(), std::forward< typename CONTAINER::value_type >(value) ) ; } // *** EDIT
int main()
{
std::set<int> a ; insert_data( 100, a ) ; insert_data( 100, a ) ;
std::unordered_multiset <std::string> b ; insert_data( "hello", b ) ; insert_data( "hello", b ) ;
std::unordered_map<int,std::string> c ; insert_data( { 100, "hello" }, c ) ;
std::multimap<std::string,int> d ; insert_data( { "hello", 100 }, d ) ; insert_data( { "hello", 200 }, d ) ;
std::deque<std::string> e ; insert_data( "hello", e ) ; insert_data( "hello again", e ) ;
}
|