Boost logo

Boost :

From: Phil Garofalo (pfg23_at_[hidden])
Date: 2002-06-13 12:57:21


I guess dynamic_bitset is the alternative I'm looking
for. As Rosanne Rosanna Danna said, "...Never mind!"

Confidential to moderator: if you would be so kind as
to not post these this message and my previous one
(see below)? Please! :-)

Thanks,

Phil

--- Phil Garofalo <pfg23_at_[hidden]> wrote:
> Date: Thu, 13 Jun 2002 10:39:18 -0700 (PDT)
> From: Phil Garofalo <pfg23_at_[hidden]>
> Subject: Re: [boost] Removing vector<bool>
> To: boost_at_[hidden]
>
> At 09:23 AM 6/13/2002 +1000, Matthew Wilson wrote:
>
> >It seems like a good idea to just remove it from
> the
> next version of
> the
> >standard if there are no significant (or vocal)
> users
> of it
>
> I know vector<bool> doesn't adhere to the canonical
> container interface and I've read Scott Meyer's
> critique of it in _Effective STL_, but I for one
> would
> like to see it stay. I believe there is a need for a
> space efficient, variably sized array of bit flags.
> bitset's size must be defined at runtime, as are the
> bit field structures, and Meyer's suggested
> deque<bool> seems grievously space inefficient. A
> simple case where vector<bool> seems perfectly
> suited
> is in an implementation of Eratosthene's Sieve.
> E.g.,
>
>
> main (int argc,char** argv)
> {
> if (argc < 2)
> {
> cerr << "Usage: " << argv[0] << " number" <<
> endl;
> return EXIT_FAILURE;
> }
> vector<bool> flags(strtoul(argv[1], NULL, 10) + 1,
> true); // set all flags true
>
> // Only need to go up to the square root.
> for(unsigned long i = 2; i < sqrt(flags.size());
> i++)
> if (flags[i]) // found a prime
> for (unsigned long k = i + i; k <
> flags.size();
> k += i)
> flags[k] = false; // cancel its multiples
>
> for (/*unsigned long*/ i = 2; i < flags.size();
> i++)
> if (flags[i])
> cout << setw(11) << i;
>
> return EXIT_SUCCESS;
>
> }
>
> If there's a better alternative to vector<bool> for
> cases like these, where you might need a very large
> number of flags dynamically allocated at run time,
> I'm
> all for it. I haven't seen one yet. So until then, I
> vote to keep vector<bool>.
>
> Phil Garofalo
> Chicago, IL
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com


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