From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-06-29 08:59:15
On Friday 28 June 2002 01:50 pm, Itay Maman wrote:
> I think that variant_cast<> should be the only way for an application
> code to reach the T* pointer. Consequently, get_ptr() should be made
> private, although I must add an #ifdef-ed workaround for MSVC.
I'm happy with that. Personally, I would strongly discourage the use of
variant_cast anyway because it is the only mechanism to access a variant that
is not guaranteed to succeed at run-time. Visitors are typesafe as would be a
> > 1) Great Stack_Holder::swap :)
> I am wondering if there's a more efficient way for implementing an
> exception-safe swap() ?
For the general case, I don't think there is. There are tons of optimization
opportunities for special cases:
1) Same type: cast and swap
2) Both incomplete types: swap pointers
3) Both POD types: swap the bytes
> > 4) Is there any benefit to the use of copy/destroy function pointers
> > instead of a cascading 'if' built with a metarecursive function? The
> > function pointers impose an extra 8-byte overhead in the variant -- is
> > this overhead justified by an efficiency boost? The same question applies
> > to the visitor table.
> Well, we can use a single pointer for *both* clone/destroy. So the space
> overhead we should weigh here, is just 4 byte.
> As for Accept_table, it is a static local variable inside
> Variant::operator() so its cost is minimal.
I'll just try it :). My hunch is that it would be faster to use a cascading
'if' than to perform a call through a function pointer, but only
experimentation will tell for sure.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk