From: Roland Richter (roland_at_[hidden])
Date: 2004-02-12 08:48:00
Matt Verona wrote:
> I'm looking for a type of View that provides read-only access to an STL
> map, with only const iterators, but also provides limited insertion and
> removal access as well (as shown below):
> This new limited View-like map will only allow clients to iterate using
> const iterators, and also provides only one public insert(const key&) and
> one erase(const key&) method.
is there any reason why you want to provide only insert(const key&)
and erase(const key&)? Why not insert(InputIterator, InputIterator)
or clear() or any other method?
When I designed the view library (which you can find in Boost.Sandbox),
I decided to make views read-only for two reasons:
+ Performance: as long as a view is read-only, it usually suffices that
it owns the underlying container by reference, i.e. no copy is needed.
Write access means that each view must contain its own copy of the container.
Could be solved with a copy-on-write behaviour.
+ Simplicity of interface: read-only views have a minimal interface:
they just define those functions *all* STL containers provide, such
as begin()/end(), empty()/size(), plus various typedef's.
But what about read-and-write views? Some have an insert() methods,
others don't insert(), but push_back(), and so on.
A general-purpose view (i.e. one suitable for all STL containers, not
tailored to a specific one) either has to provide all these methods
(uh oh, somebody just wanted to push_back() into a view<std::map>), or
they have to know (how?) which they should provide, and which not.
If you want to modify the view - why don't you modify the underlying
container? The easiest solution might be that views provide a method
to access the (copy of the) underlying container.
> I was also wondering if Boost was planning to eventually provide a
> VTL-like framework?
I ported boost::view to use the new iterator_adaptors a few months ago,
but got troubles because then the iterator adaptor lib was not stable.
Ok, we have 1.31.0 since a few days, so I will look back. Sorry, can't
promise more at the moment.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk