Skip to content

Instantly share code, notes, and snippets.

@shepik
Created November 26, 2011 18:11
Show Gist options
  • Save shepik/1396066 to your computer and use it in GitHub Desktop.
Save shepik/1396066 to your computer and use it in GitHub Desktop.
#include <vector>
#include <list>
#include <map>
#include <string>
using namespace std;
template <typename K, typename V>
struct mapper {
typedef typename K::value_type key_type;
typedef typename V::value_type value_type;
typedef std::map<key_type,value_type> map_type;
static void make_map(K &k, V &v, map_type &m) {
typename K::iterator ik;
typename V::iterator iv;
for (
ik = k.begin(),iv = v.begin();
ik!=k.end() && iv!=v.end();
ik++,iv++
) {
m[*ik] = *iv;
}
}
};
template<typename K, typename V, typename R>
void make_map(K &k, V &v, R &m) {
mapper<K,V>::make_map(k,v,m);
}
int main() {
std::vector<int> a;
std::list<std::string> b;
//.......
// std::map<int,std::string> res;
// make_map(a,b,res);
typename mapper< std::vector<int>, std::list<std::string> >::map_type res;
make_map(a,b,res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment