|
Boost : |
From: Eric Friedman (ebf_at_[hidden])
Date: 2003-10-07 20:59:50
E. Gladyshev wrote:
> --- Eric Friedman <ebf_at_[hidden]> wrote:
>>In the context of my_class, Variant is an "unknown" variant type.
>>Nonetheless, objects of Variant (e.g., var_) operate according to rules
>>that remain the same regardless of the types bounded by the variant. In
>>the context of my_class, objects of Variant behave as any other
>>variant<...> might. In short, I don't see any unpredictability here.
>
>
> See my previous post on why it is unpredictable.
>
> Another requirement is that I'd like to make sure that
> template <typename Variant>
> class my_class
> {
> Variant var_;
> };
>
> OR
>
> template <typename Variant, typename A = std::allocator<Variant> >
> class my_class
> {
> std::vector<Variant, A> var_;
> };
>
> never touches the heap.
>
> Eugene
In general it is impossible to avoid the heap, unless we go back to
double-storage. (I suppose a policy might be workable here, but I'd like
to stay away from that option for the time being.)
Eric
P.S. You might try this workaround (sorta hackish):
template <typename Variant>
class my_class
{
typedef typename mpl::push_front<
typename Variant::types
, boost::empty
>::type var_t;
var_t var_;
};
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk