[Boost-users] mpl and fusion containers: numbered vs variadic

13 views
Skip to first unread message

MM

unread,
May 27, 2012, 2:11:23 AM5/27/12
to boost...@lists.boost.org
Hello,
Is it true that as a general rule, using the numbered version instead of the
variadic version yields faster compile times?
Or is it just about compilers supporting variadic templates?

MM

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Christopher Schmidt

unread,
May 27, 2012, 3:49:38 PM5/27/12
to boost...@lists.boost.org
"MM" <finju...@gmail.com> writes:

> Is it true that as a general rule, using the numbered version instead
> of the variadic version yields faster compile times? Or is it just
> about compilers supporting variadic templates?

IIRC Fusion currently implements the variadic vector in terms of the
fixed numeric ones. (And all other container on top of the vector.)
This is, the use of a numeric vector should be slightly faster than the
use of the variadic one.

If C++11's variadic templates are used, it will be easiest to implement
the numbered ones using an unnumbered, variadic implementation in
combination with template aliases, though.

Christopher

Larry Evans

unread,
May 27, 2012, 4:40:34 PM5/27/12
to boost...@lists.boost.org
On 05/27/12 14:49, Christopher Schmidt wrote:
> "MM"<finju...@gmail.com> writes:
>
>> Is it true that as a general rule, using the numbered version instead
>> of the variadic version yields faster compile times? Or is it just
>> about compilers supporting variadic templates?
>
> IIRC Fusion currently implements the variadic vector in terms of the
> fixed numeric ones. (And all other container on top of the vector.)
> This is, the use of a numeric vector should be slightly faster than the
> use of the variadic one.
>
> If C++11's variadic templates are used, it will be easiest to implement
> the numbered ones using an unnumbered, variadic implementation in
> combination with template aliases, though.
>
> Christopher
Hi Christopher,

Could you please provide an example implementation of this C++11
implementation? I've no idea how template aliases could be used :(

TIA.

-regards,
Larry

Christopher Schmidt

unread,
May 27, 2012, 6:44:11 PM5/27/12
to boost...@lists.boost.org
Larry Evans <cpplj...@suddenlink.net> writes:

> Could you please provide an example implementation of this C++11
> implementation? I've no idea how template aliases could be used :(

Actually it is the other way round, the language feature is called alias
template. (N3337, 14.5.7)

template <typename...> class container;

template <typename A>
using container1 = container<A>;

This is pretty cool because AFAIK from a typization point of view there
is no difference between container<A> and container1<A>. This is
incredibly useful when one uses specialisations instead of explicit
template metaprogramming to optimise in regard to compile-time as it is
being done, for example, in Boost.Spirit. Other than that, the numeric
aliases can easily be generated using the preprocessor and there is no
real overhead imposed to the compilation session.

Even better, one can use template aliases to define the front-end Fusion
container types in terms of a single, shared backend implementation.
This is useful because that way there are way less heavy template
instantiations as the containers now do not built up-on each other any
more.

Christopher
Reply all
Reply to author
Forward
0 new messages