From 899efcc2d690fc03cb0fa2c38b8eee9b8bcc3900 Mon Sep 17 00:00:00 2001 From: Christos Houtouridis Date: Sun, 13 Oct 2019 19:54:08 +0300 Subject: [PATCH] meta: Change complexity of typelist<>::times<> from O(N) to O(logN) --- include/utl/meta/typelist.h | 42 ++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/include/utl/meta/typelist.h b/include/utl/meta/typelist.h index 23d39b4..713d32b 100644 --- a/include/utl/meta/typelist.h +++ b/include/utl/meta/typelist.h @@ -76,17 +76,29 @@ namespace meta { } // ======= times utility ======= private: - template - struct times_ { }; - - template - struct times_, Ts...> { - // append one and recurse - using type = type_< - if_c , Ts...>, - typelist - >>; + template struct cat_ { }; + template + struct cat_, typelist> { + using type = typelist; + }; + + template + struct times_ { + //static_assert( N >= 0, "Cannot make typelist of negative length" ); + using type = eval< + cat_< + eval>, + eval> + > + >; + }; + template + struct times_<1, T...> { + using type = typelist; + }; + template + struct times_<0, T...> { + using type = typelist<>; }; public: /*! @@ -98,11 +110,11 @@ namespace meta { * typelist * >, "" ); * \endcode - * complexity \f$ O(N) \f$ + * complexity \f$ O(logN) \f$ */ template - using times = type_< - times_, Ts...> + using times = eval< + times_ >; }; @@ -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 using at_c = eval<