45 #define DFE_NAMEDTUPLE(name, ...) \
46 using Tuple = decltype(::std::make_tuple(__VA_ARGS__)); \
47 static ::std::array<::std::string, ::std::tuple_size<Tuple>::value> \
49 return ::dfe::namedtuple_impl::unstringify< \
50 ::std::tuple_size<Tuple>::value>((#__VA_ARGS__)); \
52 template<typename... U> \
53 name& operator=(const ::std::tuple<U...>& other) { \
54 ::std::tie(__VA_ARGS__) = other; \
57 template<typename... U> \
58 name& operator=(::std::tuple<U...>&& other) { \
59 ::std::tie(__VA_ARGS__) = ::std::forward<std::tuple<U...>>(other); \
62 operator Tuple() const { return ::std::make_tuple(__VA_ARGS__); } \
63 Tuple tuple() const { return ::std::make_tuple(__VA_ARGS__); } \
64 template<std::size_t I> \
65 constexpr ::std::tuple_element_t<I, Tuple>& get() { \
66 return ::std::get<I>(std::tie(__VA_ARGS__)); \
68 template<::std::size_t I> \
69 constexpr const ::std::tuple_element_t<I, Tuple>& get() const { \
70 return ::std::get<I>(std::tie(__VA_ARGS__)); \
72 template<::std::size_t I> \
73 friend constexpr ::std::tuple_element_t<I, Tuple>& get(name& nt) { \
74 return nt.template get<I>(); \
76 template<::std::size_t I> \
77 friend constexpr const ::std::tuple_element_t<I, Tuple>& get( \
79 return nt.template get<I>(); \
81 friend inline ::std::ostream& operator<<(::std::ostream& os, const name& nt) \
82 __attribute__((unused)) { \
83 return ::dfe::namedtuple_impl::print_tuple( \
84 os, nt.names(), nt.tuple(), \
85 ::std::make_index_sequence<::std::tuple_size<Tuple>::value>{}); \
90 namespace namedtuple_impl {
95 template<std::
size_t N>
96 constexpr std::array<std::string, N>
98 assert(str and
"Input string must be non-null");
100 std::array<std::string, N> out;
104 while ((*str !=
'\0') and (*str ==
' ')) {
108 const char* sep = str;
109 while ((*sep !=
'\0') and (*sep !=
',')) {
113 out[
idx].assign(str, sep - str);
126 template<
typename Names,
typename Values, std::size_t...
I>
129 std::ostream& os,
const Names&
n,
const Values&
v,
130 std::index_sequence<I...>) {
162 using Vacuum =
int[];
164 (os << ((0 <
I) ?
" " :
"") << get<I>(
n) <<
"=" << get<I>(v), 0)...};