Re: vector and bool

From: Richard Herring (junk_at_[127.0.0.1)
Date: 10/13/04


Date: Wed, 13 Oct 2004 10:12:50 +0100

In message <1097606565.479989@athnrd02>, Ioannis Vranos
<ivr@guesswh.at.grad.com> writes
>Richard Herring wrote:
>
>> For a weak enough meaning of "should", I agree that that's the
>>intention. But I don't think anything in the Standard rules out a
>>naive implementation that makes no attempt to optimise, and simply
>>implements vector<bool> in terms of an underlying vector<some_int_type>.
>
>
>There is not an explicit prohibition on this, however explicit
>prohibitions are rare in the standard.

Just so. The standard specifies an interface and complexity (speed)
requirements, not the mechanism used to implement them. But it says
nothing prescriptive about the memory requirements for containers.
>
>Also the implementer has to implement this particular reference:
>
>
>// bit reference:
>class reference {
>friend class vector;
>reference();
>public:
>˜reference();
>operator bool() const;
>reference& operator=(const bool x);
>reference& operator=(const reference& x);
>void flip(); // flips the bit
>};
>
Yes, and the fact that this is what operator[] is mandated to return is
what makes it *possible* for the implementor to provide access to data
packed into something smaller than an addressable unit.
>
>with the note:
>
>reference is a class that simulates the behavior of references of a
>single bit in vector<bool>.

Yes; note the word "simulates".
>
>and this particular member function:
>
>void flip(); // flips all bits
>
>Also vector<bool> is mentioned as a separate case in the standard, and
>thus I think the legislator intended this to be implemented only with
>bits.

I'd say "intended it to be _possible_ to implement with bits".

>:-)

-- 
Richard Herring


Relevant Pages

  • Re: defvar affecting captured closure variables ?
    ... by a SRFI-like process than a revisiting of the ANSI process. ... and doesn't conform to the ANSI standard, there are ways you can open ... collectively referred to as "libel" although it is sometimes broken ... reference document, that makes it easier to correlate it with yours ...
    (comp.lang.lisp)
  • Re: Buffer overflows and asctime()
    ... reference implementation is IMO a defect in the Standard. ... The behavior of asctime() should be well defined when all relevant ... "normal ranges" by means of side effects in a reference implementation ...
    (comp.std.c)
  • Re: goofy frequencies
    ... And I'd like to have the option of phase locking it to some standard ... reference, ... Back in Germany I've used another outfit that had better pricing. ... For super top notch crystals where price was not an objective we used KVG. ...
    (sci.electronics.design)
  • Re: segfault w/ block, but not file scope
    ... > Keith Thompson wrote: ... the C language has rules that permit implementations to ... - From the C 9989-1999 proposed standard (and, IIRC, from previous C standards, ... by reference" anywhere in it. ...
    (comp.lang.c)
  • Re: need help deriving from the std::list class
    ... If you want your class to be used by standard algorithms for searching, ... a pointer or a reference to std::list, and have that other function call ... expect std::list (private inheritance disables implicit conversion to ...
    (comp.lang.cpp)