diff --git a/triqs/utility/c14.hpp b/triqs/utility/c14.hpp index c9faa602..c9165cf9 100644 --- a/triqs/utility/c14.hpp +++ b/triqs/utility/c14.hpp @@ -23,7 +23,8 @@ #include #include "./macros.hpp" -// a few that will be C++14, use in advance.... +// backward compat. C++11 compilers. +// new stuff in namespace std { namespace c14 { @@ -60,6 +61,69 @@ namespace std { template std::unique_ptr make_unique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } + //------------------------------------------------------------------------------------------ + // + // sequence from C++14 : from gcc lib 4.9 + /// Class template integer_sequence + // Stores a tuple of indices. Used by tuple and pair, and by bind() to + // extract the elements in a tuple. + template + struct _Index_tuple + { + typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next; + }; + + // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>. + template + struct _Build_index_tuple + { + typedef typename _Build_index_tuple<_Num - 1>::__type::__next __type; + }; + + template<> + struct _Build_index_tuple<0> + { + typedef _Index_tuple<> __type; + }; + + template + struct integer_sequence + { + typedef _Tp value_type; + static constexpr size_t size() { return sizeof...(_Idx); } + }; + + template::__type> + struct _Make_integer_sequence; + + template + struct _Make_integer_sequence<_Tp, _Num, _Index_tuple<_Idx...>> + { + static_assert( _Num >= 0, + "Cannot make integer sequence of negative length" ); + + typedef integer_sequence<_Tp, static_cast<_Tp>(_Idx)...> __type; + }; + + /// Alias template make_integer_sequence + template + using make_integer_sequence + = typename _Make_integer_sequence<_Tp, _Num>::__type; + + /// Alias template index_sequence + template + using index_sequence = integer_sequence; + + /// Alias template make_index_sequence + template + using make_index_sequence = make_integer_sequence; + + /// Alias template index_sequence_for + template + using index_sequence_for = make_index_sequence; +//-------------------------------------------------- + } }