I’m working a bit with typelists defined in Alexandrescu’s Modern C++ Design.
In his books, he talks about Appending a type to a typelist, but he doesn’t talk about splicing two typelists…
I guess it is possible to splice two typelists using the Append functionnality, but wouldn’t it result in a linear-time splicing (whereas std::list::splice is O(1) ). ?
Well, i know that this computation time can be considered as “free” as it is compile-time, but I am curious 🙂
Thanks !
The typelist concept is usually* closer to the Computer Science notion of a list than the (doubly) linked list that
std::listis. The two ideas share a name but have crucial differences.Since metaprograms are purely functional you can’t modify in-place an input typelist the way
std::list::splicedoes: you have to ‘generate’ the output typelist(s), which would be linear. (Laziness can be used to defer and reduce that cost however; the exact cost paid would then depend on the final algorithm.)*: I said usually because the Boost.MPL supports things like iterators and views which blurs the line, at least from the user point-of-view.
(For the sake of the argument assume that by “CS” list here I meant the cons cell + the empty list.)