Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-09-10 15:50:38


From: "Jonathan Turkanis" <technews_at_[hidden]>
> "Rob Stewart" <stewart_at_[hidden]> wrote in message
> news:200409101906.i8AJ6M921012_at_lawrencewelk.systems.susq.com...
> > From: "Jonathan Turkanis" <technews_at_[hidden]>
>
> > > enum {
> > > f_open = 1,
> > > f_input_closed = f_open << 1,
> > > f_output_closed = f_input_closed << 1,
> > > f_output_buffered = f_output_closed << 1
> > > };
> >
> > This is a pain to read and maintain. You should write them like
> > this:
> >
> > enum
> > {
> > f_open = 1<<0,
> > f_input_closed = 1<<1,
> > f_output_closed = 1<<2,
> > f_output_buffered = 1<<3
> > };
> >
> I stole this idiom from John Maddock: http://tinyurl.com/4no5s. It's supposed to
> make insertion in the middle easier. I think it's the vector vs. list tradeoff.

It fails to make insertion in the middle easy, at least
comparatively. Start with:

   Yours/John's Mine
enum
{
   name_a = 1, 1<<0,
   name_b = name_a << 1, 1<<1,
   name_c = name_b << 1 1<<2
};

Now add name_x after name_b:

enum
{
   name_a = 1, 1<<0,
   name_b = name_a << 1, 1<<1,
   name_x = name_b << 1, 1<<2,
   name_c = name_x << 1 1<<3
};

Your version requires a more extensive change due to the use of
the enumerator name and makes it harder to determine if the new
order is, in fact, sequential.

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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