diff --git a/m-tuple.h b/m-tuple.h index 7b6be0e2..6ce32958 100644 --- a/m-tuple.h +++ b/m-tuple.h @@ -72,9 +72,31 @@ (TUPLEI_OPLIST(__VA_ARGS__, () ), \ TUPLEI_OPLIST(__VA_ARGS__ )) -/* Return an array suitable for the _cmp_order function */ +/* Return an array suitable for the _cmp_order function. + As compound literals are not supported in C++, + provide a separate definition for C++ using initializer_list + (shall be constexpr, but only supported in C++14). +*/ +#ifndef __cplusplus #define TUPLE_ORDER(name, ...) \ ( (const int[]) {M_MAP2_C(TUPLE_ORDER_CONVERT, name, __VA_ARGS__), 0}) +#else +#include +namespace m_tuple { + template + struct m_int_array { + int data[N]; + /*constexpr*/ inline m_int_array(std::initializer_list init){ + int j = 0; + for(auto i:init) { + data[j++] = i; + } + } + }; +} +#define TUPLE_ORDER(name, ...) \ + (m_tuple::m_int_array({M_MAP2_C(TUPLE_ORDER_CONVERT, name, __VA_ARGS__), 0}).data) +#endif /********************************** INTERNAL ************************************/