Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2003-10-06 18:00:52


Eugene,

[Sorry if this message appears twice.]

E. Gladyshev wrote:
>
> Eric Friedman wrote:
> > In general, storage is on the stack.
>
> Sorry it is not completely clear to me.

Sorry, I guess "on the stack" isn't the exactly correct response. The point
is though that in general variant does *not* allocate on the heap.

A good conceptual way to think about the internals of a variant<T1,...,TN>
is as follows:

  template <typename T1, ..., typename TN>
  class variant
  {
    int which_;
    union {
      void* backup;
      T1 t1;
      ...
      TN tn;
    } storage_;
  ...
  };

Of course, the actual implementation is necessarily far more complicated.
However, the above *does* convey the basic storage allocation scheme.

HTH,
Eric


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk