1: #include <map>
2: #include <set>
3: #include <vector>
4:
5: template<class keyType, class valueType>
6: class MapInitializer {
7: public:
8: MapInitializer(const keyType& key, const valueType& val) {
9: m_map[key] = val;
10: }
11: MapInitializer<keyType, valueType>& operator()(const keyType& key, const valueType& val) {
12: m_map[key] = val;
13: return *this;
14: }
15: operator std::map<keyType, valueType>() {
16: return m_map;
17: }
18: private:
19: std::map<keyType, valueType> m_map;
20: };
21:
22: template<class valueType>
23: class SetInitializer {
24: public:
25: SetInitializer(const valueType& val) {
26: m_set.insert(val);
27: }
28: SetInitializer<valueType>& operator()(const valueType& val) {
29: m_set.insert(val);
30: return *this;
31: }
32: operator std::set<valueType>() {
33: return m_set;
34: }
35: private:
36: std::set<valueType> m_set;
37: };
38:
39: template<class valueType>
40: class VectorInitializer {
41: public:
42: VectorInitializer(const valueType& val) {
43: m_vec.push_back(val);
44: }
45: VectorInitializer<valueType>& operator()(const valueType& val) {
46: m_vec.push_back(val);
47: return *this;
48: }
49: operator std::set<valueType>() {
50: return m_vec;
51: }
52: private:
53: std::vector<valueType> m_vec;
54: };