POV-Ray : Newsgroups : povray.off-topic : Microsoft may have done something right... : Re: Microsoft may have done something right... Server Time
11 Oct 2024 01:21:49 EDT (-0400)
  Re: Microsoft may have done something right...  
From: Warp
Date: 25 Mar 2008 19:04:21
Message: <47e99304@news.povray.org>
Fredrik Eriksson <fe79}--at--{yahoo}--dot--{com> wrote:
> On Tue, 25 Mar 2008 17:34:14 +0100, Nicolas Alvarez  
> <nic### [at] gmailisthebestcom> wrote:
> > C++ STL vector template class has a specialization for 'bool' that uses  
> > 1 bit per element too. That is, a vector<bool> takes 1 bit per element.

> Yes, but that specialisation is largely considered a mistake

  The alternative would be that there's no specialization, in which
case each element could take even 4 bytes (from which only 1 bit is
actually used).

  I don't see any problem in having an efficient boolean vector.
If it doesn't work with some STL algorithms, then it doesn't. In
the vast majority of cases there isn't any logical use for STL
algorithms for a bool vector anyways (why would you, for example,
try to sort a bool vector? It doesn't make any sense).

  Of course std::bitset should be used whenever possible. However,
it's not always possible. In that case std::vector<bool> is the
next best thing.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.