|
Boost : |
From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-05-21 10:56:16
Rob Stewart wrote:
>From: "Reece Dunn"
> > Rob Stewart wrote:
> > >From: "Reece Dunn"
> > > >
> > > > Currently, this implementation is missing iterator support (and thus
>all
> > > > basic_string functionality that relies on begin(), end(), etc). This
>is
> > > > because I am wondering how to map them from the basic_string adaptor
>to
> > >the
> > > > implementation (knowing that you cannot have const and non-const
>virtual
> > > > functions).
> > >
> > >Since when can you not have const and non-const virtual
> > >functions?
> >
> > Let me rephrase:
> >
> > class char_string
> > {
> > virtual iterator begin() = 0;
> > virtual const_iterator begin() = 0; // oops! begin already in
>vtable!!
> > };
>
>I'm still missing something. Why would you want a non-const mf
>to return the const iterator type?
That was a typeo!
> class char_string
> {
> virtual iterator begin() = 0;
> virtual const_iterator begin() const = 0;
> };
That is what I was referring to. You need to change the name of the const
version if you are to allow virtual functions.
> > > > I have two possible solutions:
> > > > [1] name the const versions cXXX (cbegin(), crend(), etc.) -- the
> > >problem
> > > > with this is that you have 8 virtual functions!
> >
> > I was meaning to modify the above to:
> >
> > class char_string
> > {
> > virtual iterator begin() = 0;
> > virtual const_iterator cbegin() = 0; // ok - cXXX variant
> > };
> >
> > >You'd have those same eight variations with const and non-const
> > >virtual functions.
> >
> > That's the problem -- too many virtual functions.
>
>But if you need all eight variations, then you need eight virtual
>functions. Is it that you're trying to minimize what the derived
>class must implement for the adaptor to work? Even if that's the
That is indeed what I am trying to do.
>case, because the const and non-const functions return different
>types, you can't have the derived class implement a const
>implementation function that the adaptor can use to provide both
>const and non-const interface functions. So what am I missing?
Nothing. You do indeed need two functions:
iterator iter_offset( difference_type );
const_iterator const_iter_offset( difference_type ) const;
these can be used to implement the 8 iterator functions like this:
begin() const = const_iter_offset( 0 );
begin() = iter_offset( 0 );
end() const = const_iter_offset( size());
end() = iter_offset( size());
rbegin() const = const_reverse_iterator( const_iter_offset( size()));
rbegin() = reverse_iterator( iter_offset( size()));
rend() const = const_reverse_iterator( const_iter_offset( -1 ));
rend() = reverse_iterator( iter_offset( -1 ));
Regards,
Reece
_________________________________________________________________
Get a FREE connection, FREE modem and one month's FREE line rental, plus a
US or European flight when you sign up for BT Broadband!
http://www.msn.co.uk/specials/btbroadband
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk