Boost logo

Boost :

From: jsiek_at_[hidden]
Date: 2000-07-25 19:22:08

> From: Beman Dawes <beman_at_[hidden]>
> > It really isn't so bad once you get used to it. A lot easier than trying
> > to use partial specialization, for example. And it seems to be less
> > sensitive to compiler quirks than might be expected.

One thing to be careful with in using IF instead of partial spec. is
that all expressions (both the consequence and the alternative
statement) get evaluated, and any templates therein get instantiated.

  typedef typename IF<condition, foo<T>, bar<T> >::RET foo_bar;

is equivalent to

  typedef foo<T> Foo;
  typedef bar<T> Bar;
  typedef typename IF<condition, Foo, Bar >::RET foo_bar;

where foo<T> and bar<T> get instantiated regardless of the
value of "condition".

Instead, if you specialize some class on "condition" which
creates a typedef for foo_bar, then only one of the classes
will get instantiated.

template <bool condition> struct fooey { }

struct fooey<true> {
  typedef foo<T> foo_bar;
struct fooey<false> {
  typedef bar<T> foo_bar;



Boost list run by bdawes at, gregod at, cpdaniel at, john at