From: David Abrahams (dave_at_[hidden])
Date: 2003-10-08 13:18:19
Daniel Wallin <dalwan01_at_[hidden]> writes:
>>At that point, it might not contain any of the types you wanted. It almost
>>becomes equivalent to a design Eric rejected, where the variant can be empty.
> I don't yet buy that this is a problem for generic programming;
> If variant is part of the program interface, the type shouldn't be changed
> anyway, so "wanting the benefit of the optimization" becomes the users
> If the variant is part of the implementation, where the type
> sequence is part of the interface, the invariant type is just an
> implementation detail, or part of the program documentation.
Let me try again:
- the variant design has a nice invariant that it contains one of the
types that were passed as template arguments
- if a library takes a user's list at face value, the library
designer gets the benefit of that invariant.
- if a library designer wants the optimization in the cases where
it's possible, she either has to:
- prepend empty_type to the list in order to ensure it, and give up
on the nice invariant
- implement a moderately-complex type sequence reordering algorithm,
which surely costs far more in compilation resources than the
simple search that would be implemented by the library to provide
the optimization whenver possible.
IOW, we make the library designer choose between safety and efficiency
at compile-time just to get runtime efficiency.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk