[ create a new paste ] login | about

Link: http://codepad.org/aw6yyNH0    [ raw code | output | fork | 1 comment ]

RogerPate - C++, pasted on Apr 14:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
template<class K, class V>
struct map_list_of_type {
  typedef std::map<K, V> Map;
  Map data;
  map_list_of_type(K k, V v) { data[k] = v; }
  map_list_of_type& operator()(K k, V v) { data[k] = v; return *this; }
  operator Map const&() const { return data; }
};
template<class K, class V>
map_list_of_type<K, V> my_map_list_of(K k, V v) {
  return map_list_of_type<K, V>(k, v);
}

int main() {
  std::map<int, char> example = 
    my_map_list_of(1, 'a') (2, 'b') (3, 'c');
  cout << example << '\n';
}


Output:
1
[(1, a), (2, b), (3, c)]


Create a new paste based on this one


Comments:
posted by RogerPate on Apr 14
reply