|
Boost : |
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-01-15 10:21:14
Vesa Karvonen wrote:
> Hi,
Hi Vesa,
>
> The following is an example of using "superlinear unrolling".
> It compiles with
>
> gcc version 2.95.4 20011002 (Debian prerelease)
>
> using the default settings (max template recursion depth should be
> 17). The example code essentially applies the inc template 262 times.
> The example code uses partial specialization, but it should not be
> extremely difficult to remove, if necessary.
Very interesting! The price for unrolling doesn't seem to be big either, for
VC 7.1, at least - ten compilation runs of "naive" 'until' implementation
are only by 2.5% faster than ten compilation runs of the unrolled version.
> I think that superlinear unrolling could be useful for avoiding
> template recursion depth limitations, but the technique needs further
> studying.
Thanks for sharing it!
[...]
> struct inc {
> template<class T>
> struct apply {
> typedef typename T::next type;
> };
> };
FYI, you can turn any MPL metafunction into a metafunction class by simply
not providing its template arguments; e.g. to get equivalent of the above
you just write 'mpl::next<>'.
>
> struct always {
> template<class T>
> struct apply {
> typedef typename mpl::bool_c<false> type;
> };
> };
"boost/mpl/always.hpp", FYI.
> template<int X>
> struct is {
> template<class T>
> struct apply : mpl::bool_c<(T::value == X)> {
> };
> };
MPL has this one too; it's called 'eq', see
"boost/mpl/comparison/equal_to.hpp".
Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk