Idea for more delegations in <algorithm>

Chris Jefferson caj@cs.york.ac.uk
Wed Mar 23 17:17:00 GMT 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Paolo Carlini wrote:
| Hi everyone, hi Chris,
|
| today I got an idea, or better I *read* an idea: do you know N1758?
| Basically, Siek et al., explain at pag. 37 how to to do dispatching
| without tag types. Nothing very exoteric, actually, if you know
| enable_if, but this strikes me as potentially solving at the root the
| optimization problems with empty classes! Because we do *not* have
| additional parameters in the function calls!
|
| For instance, they implement "do the right thing" for vector as:
|
|    template<typename InputIterator>
|       vector<InputIterator first, InputIterator last,
|                   typename
| enable_if<(!is_integral<InputIterator>::value), void*>::type = 0);
|
| Or, for some reason, we have troubles with this too? :(

Unless I'm going mad (possible), default parameters are inserted and
passed by the compiler (at least on x86), so this will in fact be worse,
because that "0" will always be created and passed by the compiler
(because it might be needed for all it knows) whereas the empty classes
might eventually be optimised away with compiler improvements.

My simple attempts to fix this were defeated by the non-existance of
partial function specialisations, so I tried wrapping the functions in
structs, and got something much like:

template<int i>
struct __find
{ template<..>
~  static It
~  find(..) {..}
};

template<>
struct __find<1>
{ template<..>
~    static It
~    find(..) {..}
};

template<..>
It find(..)
{ __find<__is_forward_iterator<It>::val>::find(...); }

Where __is_forward_iterator<It> returns 1 if It is a forward,
bidirectional or random access iterator.

The main problem with this is that it so much longer than the original
code, espically once you have de-inlined the implementation of
__find::find. I was hoping to find a way of reducing code length somewhat.

Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFCQaPK3FpDzErifpIRAv/2AJ9h549kwsIWcpxE+k5/JOPGHddH1ACfZ2/L
97Ly2tHzsrTcDsEgzlaaP14=
=fDLH
-----END PGP SIGNATURE-----



More information about the Libstdc++ mailing list