mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 05:43:40 +01:00
C14 : add sequence.
correct seq gcc code inclusion
This commit is contained in:
parent
6e987f4563
commit
8cf7465114
@ -23,7 +23,8 @@
|
||||
#include <functional>
|
||||
#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<typename T, typename... Args>
|
||||
std::unique_ptr<T> make_unique(Args&&... args) { return std::unique_ptr<T>(new T(std::forward<Args>(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<size_t... _Indexes>
|
||||
struct _Index_tuple
|
||||
{
|
||||
typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
|
||||
};
|
||||
|
||||
// Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
|
||||
template<size_t _Num>
|
||||
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<typename _Tp, _Tp... _Idx>
|
||||
struct integer_sequence
|
||||
{
|
||||
typedef _Tp value_type;
|
||||
static constexpr size_t size() { return sizeof...(_Idx); }
|
||||
};
|
||||
|
||||
template<typename _Tp, _Tp _Num,
|
||||
typename _ISeq = typename _Build_index_tuple<_Num>::__type>
|
||||
struct _Make_integer_sequence;
|
||||
|
||||
template<typename _Tp, _Tp _Num, size_t... _Idx>
|
||||
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<typename _Tp, _Tp _Num>
|
||||
using make_integer_sequence
|
||||
= typename _Make_integer_sequence<_Tp, _Num>::__type;
|
||||
|
||||
/// Alias template index_sequence
|
||||
template<size_t... _Idx>
|
||||
using index_sequence = integer_sequence<size_t, _Idx...>;
|
||||
|
||||
/// Alias template make_index_sequence
|
||||
template<size_t _Num>
|
||||
using make_index_sequence = make_integer_sequence<size_t, _Num>;
|
||||
|
||||
/// Alias template index_sequence_for
|
||||
template<typename... _Types>
|
||||
using index_sequence_for = make_index_sequence<sizeof...(_Types)>;
|
||||
//--------------------------------------------------
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user