POV-Ray : Newsgroups : povray.off-topic : C++: Seriously? : Re: C++: Seriously? Server Time
28 Jul 2024 16:23:11 EDT (-0400)
  Re: C++: Seriously?  
From: Warp
Date: 22 Nov 2013 16:30:13
Message: <528fcce5@news.povray.org>
Orchid Win7 v1 <voi### [at] devnull> wrote:
> (One helpful commenter pointed out that std::vector<bool> is allowed to 
> behave differently, though.)

std::vector<bool> is special in that each element takes one bit.
You can't have a pointer pointing to a single bit. (std::vector<bool>
iterators are also special.)

> I did enjoy the guy who claimed that because you're guaranteed O(1) 
> access time, it must be a continuous array. O RLY? Because I'm pretty 
> sure I can come up with an O(1) implementation that isn't contiguous...

std::deque has O(1) random access and O(1) insertion and deletion from
the beginning and the end, and it doesn't use contiguous memory for the
entire data structure. (Iterators also remain valid even if you add
elements.)

On the other hand, the O(1) random access is slightly slower than with
std::vector.

-- 
                                                          - Warp


Post a reply to this message

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