Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2002-06-17 14:57:25


On Sun, 16 Jun 2002, Ed Brey wrote:
brey> - There should be a constant reference. This is useful for reading
brey> a given bit multiple times in a type-safe (ie. const) manner. For
brey> example:
brey>
brey> void fn() {
brey> dyn_bitset<> bits;
brey> Init(bits);
brey> dyn_bitset<>::const_reference const r = bits[5];
brey> while (r)
brey> Do_something(bits); // Updates the bitset.
brey> }
brey>
brey> The current reference class doesn't cut it, since it requires that
brey> the reference and the bitset be non-constant. Given a good
brey> optimizing compiler, this gives you everything that returning bool
brey> does, and doesn't leave a hole in the interface. I realize that
brey> std::bitset chose to return bool, but I'm not sure that applies
brey> today. Are their a signficant number of modern compilers remaining
brey> that won't optimize away the proxy object? This may be a case where
brey> a compromise due to pre-standardization compiler technology can now
brey> be removed.

To make sure I understand the motivation for this... you're saying that
the above is better then the following

while (bits[5])
  Do_something(bits);

because... it could be more efficient? It is more convenient? Do you have
another reason?

brey> - to_string should be a member function. The rationale explains an
brey> advantage of passing the string by reference rather than returning
brey> it; however, there isn't any reason the reference can't be passed to
brey> a member function instead of a free function.

Ahh, that reminds me... there was one other reason. As a non-member
function, one could also add an overload of the function for std::bitset,
thus making the two classes interchangeable (which was a goal of mine).

Cheers,
Jeremy

----------------------------------------------------------------------
 Jeremy Siek http://php.indiana.edu/~jsiek/
 Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
 C++ Booster (http://www.boost.org) office phone: (812) 855-3608
----------------------------------------------------------------------


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