Преглед на файлове

meta: Change complexity of typelist<>::times<> from O(N) to O(logN)

doc
Christos Houtouridis преди 5 години
родител
ревизия
899efcc2d6
променени са 1 файла, в които са добавени 27 реда и са изтрити 15 реда
  1. +27
    -15
      include/utl/meta/typelist.h

+ 27
- 15
include/utl/meta/typelist.h Целия файл

@@ -76,17 +76,29 @@ namespace meta {
}
// ======= times utility =======
private:
template<size_t N, typename L, typename ...T>
struct times_ { };
template<size_t N, typename ...L>
struct times_<N, typelist<L...>, Ts...> {
// append one and recurse
using type = type_<
if_c <N != 0,
times_<N-1, typelist<L..., Ts...>, Ts...>,
typelist<L...>
>>;
template <typename... > struct cat_ { };
template <typename... L1, typename... L2>
struct cat_<typelist<L1...>, typelist<L2...>> {
using type = typelist<L1..., L2...>;
};
template <size_t N, typename ...T>
struct times_ {
//static_assert( N >= 0, "Cannot make typelist of negative length" );
using type = eval<
cat_<
eval<times_<N/2, T...>>,
eval<times_<N - N/2, T...>>
>
>;
};
template <typename ...T>
struct times_<1, T...> {
using type = typelist<T...>;
};
template <typename ...T>
struct times_<0, T...> {
using type = typelist<>;
};
public:
/*!
@@ -98,11 +110,11 @@ namespace meta {
* typelist<int, char, int, char>
* >, "" );
* \endcode
* complexity \f$ O(N) \f$
* complexity \f$ O(logN) \f$
*/
template<size_t N>
using times = type_<
times_<N, typelist<>, Ts...>
using times = eval<
times_<N, Ts...>
>;
};
@@ -226,7 +238,7 @@ namespace meta {
/*!
* Return the \p N th element in the \c meta::typelist \p List.
*
* Complexity \f$ O(N) \f$.
* Complexity \f$ O(logN) \f$.
*/
template <typename List, index_t N>
using at_c = eval<


Loading…
Отказ
Запис