1 |
#pragma once |
2 |
|
3 |
#include <boost/lexical_cast.hpp> |
4 |
|
5 |
#include <cassert> |
6 |
#include <typeinfo> |
7 |
|
8 |
#include "adt/make/forward.h" |
9 |
|
10 |
namespace make |
11 |
{ |
12 |
namespace detail |
13 |
{ |
14 |
#include "adt/make/array.h" |
15 |
#include "adt/make/map.h" |
16 |
#include "adt/make/value.h" |
17 |
|
18 |
template<typename T> |
19 |
struct any_value_t |
20 |
: value_t |
21 |
{ |
22 |
any_value_t (T const &v); |
23 |
|
24 |
static std::string str (void const *data) |
25 |
{ |
26 |
return boost::lexical_cast<std::string> (*(T const *)data); |
27 |
} |
28 |
}; |
29 |
|
30 |
template<typename T> |
31 |
any_value_t<T>::any_value_t (T const &v) |
32 |
: value_t (&v, str, typeid (v)) |
33 |
{ |
34 |
} |
35 |
|
36 |
template<> |
37 |
inline any_value_t<array_t>::any_value_t (array_t const &v) |
38 |
: value_t (&v, NULL, typeid (v)) |
39 |
{ |
40 |
} |
41 |
|
42 |
template<> |
43 |
inline any_value_t<map_t>::any_value_t (map_t const &v) |
44 |
: value_t (&v, NULL, typeid (v)) |
45 |
{ |
46 |
} |
47 |
|
48 |
|
49 |
template<typename T> |
50 |
value_t |
51 |
make_value (T const &v) |
52 |
{ |
53 |
return any_value_t<T> (v); |
54 |
} |
55 |
|
56 |
|
57 |
static inline void |
58 |
fill_map (value_map &map) |
59 |
{ |
60 |
} |
61 |
|
62 |
template<typename T1, typename T2, typename... Args> |
63 |
void |
64 |
fill_map (value_map &map, T1 const &v1, T2 const &v2, Args const &...args) |
65 |
{ |
66 |
map.emplace_back (make_value (v1), make_value (v2)); |
67 |
fill_map (map, args...); |
68 |
} |
69 |
|
70 |
template<typename... Args> |
71 |
value_map |
72 |
make_map (Args const &...args) |
73 |
{ |
74 |
value_map map; |
75 |
fill_map (map, args...); |
76 |
return std::move (map); |
77 |
} |
78 |
} |
79 |
|
80 |
typedef detail::value_t value; |
81 |
typedef detail::array_t array; |
82 |
typedef detail::value_pair value_pair; |
83 |
typedef detail::map_t map; |
84 |
} |