Topic: Missing method in bitset
Author: hinnant@anti-spam_metrowerks.com (Howard Hinnant)
Date: 2000/09/24 Raw View
In article <1eh3zee.158fxcogv41w4N%dwalker07@snet.net.invalid>,
dwalker07@snet.net.invalid (Daryle Walker) wrote:
| I was attempting to use a bitset (from <bitset>) as part of another
| class and I needed to look at bits from a constant object. My function
| is set up so I know that the bit indices are correct. To my shock, I
| found out that operator[] for bitset objects is non-const only, there is
| no const version! (Josuttis' C++ Library book mistakenly believes that
| there is a const version.) For now, my workaround is to use the "test"
| method, even though I now have the overhead of that method's (unneeded)
| index check. (I could also pass a bitset object by value instead of
| constant reference.)
|
| Can this be fixed for the next standard (by defining a "template
| <std::size_t N> bool std::bitset<N>::operator[]( std::size_t pos )
| const")?
You might be interested in dr:
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#11
-Howard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Sergey Zacharov" <QWERTY_sergez@nival.com>
Date: 2000/09/25 Raw View
"Howard Hinnant" <hinnant@anti-spam_metrowerks.com> wrote in message
> In article <1eh3zee.158fxcogv41w4N%dwalker07@snet.net.invalid>,
> dwalker07@snet.net.invalid (Daryle Walker) wrote:
>
> | I was attempting to use a bitset (from <bitset>) as part of another
> | class and I needed to look at bits from a constant object. My function
> | is set up so I know that the bit indices are correct. To my shock, I
> | found out that operator[] for bitset objects is non-const only, there is
> | no const version! (Josuttis' C++ Library book mistakenly believes that
> | there is a const version.) For now, my workaround is to use the "test"
> | method, even though I now have the overhead of that method's (unneeded)
> | index check. (I could also pass a bitset object by value instead of
> | constant reference.)
> |
> | Can this be fixed for the next standard (by defining a "template
> | <std::size_t N> bool std::bitset<N>::operator[]( std::size_t pos )
> | const")?
>
> You might be interested in dr:
>
> http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#11
>
> -Howard
And what about similar operator in std::map? I understand, that operator []
can insert new values in map, but it is posible to forbid this (throw
exception or say that behavour is undefined if key can`t be found). I think
it is useful to make something like this:
const value_type &operator[] ( const key_type& x ) const;
Returns: find( x )->second;
Sergey
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: dwalker07@snet.net.invalid (Daryle Walker)
Date: 2000/09/23 Raw View
I was attempting to use a bitset (from <bitset>) as part of another
class and I needed to look at bits from a constant object. My function
is set up so I know that the bit indices are correct. To my shock, I
found out that operator[] for bitset objects is non-const only, there is
no const version! (Josuttis' C++ Library book mistakenly believes that
there is a const version.) For now, my workaround is to use the "test"
method, even though I now have the overhead of that method's (unneeded)
index check. (I could also pass a bitset object by value instead of
constant reference.)
Can this be fixed for the next standard (by defining a "template
<std::size_t N> bool std::bitset<N>::operator[]( std::size_t pos )
const")?
--
Daryle Walker
Mac, Internet, and Video Game Junkie
dwalker07 AT snet DOT net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]