Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2004-03-06 15:40:58


At 09:04 AM 3/5/2004, Thorsten Ottosen wrote:
>One last thing:
>
>> > 8. maybe you should add const_pointer data() const
>> ?
>> It is not possible. data() is mutating operation.
>> See
>> the source code.
>> ---------------
>> ok. then maybe one should get more hints about this
>> mutation (I did not have
>> a clue), maybe like
>> c.prepare_array();
>> foo( &*c.begin() );
>There are some words regarding iterator invalidation
>in the method documentation.
>---------
>ok, I'm not super religious about it, but my line of thought goes like
>this:
>
>if a programmer sees this kind of code:
>
>circular_buffer<T> cb;
>...
>foo( cb.data() );
>
>he would have to look at documentation to know what's going on (he could
be
>a maintenance programmer who have no
>earlier knowlegde of circular buffer). data() is a very
>innocent word and I doubt that people in general would think all iterator
>were invalidated. I also doubt that they would think
>it was a linear time operation. Now, that's why I think it might be
>possible
>to give programmer just a little more hint about
>what might be going on by using a *verb* in the functions name, eg.
>
>compute_data();
>prepare_data();
>prepare_array();
>linearize_data();
>
>It's probably good to get other's oppinion about this too.

FWIW, I agree. Particularly since data() in std::string is const. Verbs do
a better job of indicating meaning.

--Beman


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