From: Eric Friedman (ebf_at_[hidden])
Date: 2003-10-06 22:11:40
E. Gladyshev wrote:
> Eric Friedman wrote:
> > Note, too, that this code will never execute for any T that is nothrow
> > copyable or if the first bounded type of the variant is nothrow
> > default-constructible (e.g., variant<int, ...> or variant<boost::empty,
> > ...>, etc.).
> Is there any way to use 'variant' in a policy based library
> with a wide set of types?
> I'd like to have a memory policy in my library.
> How can I meet these constraints if my types
> are not very well predefined?
Do you mean you need to ensure allocation of some user-provided type occurs
only via some user-provided allocator? If so, variant unfortunately does not
support such functionality at this time.
However, as I noted in previous messages, allocation on the heap can be
avoided entirely for any type Ti in variant<T1, ..., TN> if T1 is nothrow
default-constructible. I would suggest then that, if none of your types are
guaranteed to have a nothrow default constructor, you work with
variant<boost::empty, T1, ..., TN>. Even if you never make direct use of
boost::empty, this will ensure all allocation will be via placement new and
never on the heap.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk