Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-05-21 09:31:27


From: "Reece Dunn" <msclrhd_at_[hidden]>
> Rob Stewart wrote:
> >From: "Reece Dunn" <msclrhd_at_[hidden]>
> > >
> > > 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?

   class char_string
   {
      virtual iterator begin() = 0;
      virtual const_iterator begin() const = 0;
   };

> > > 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
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?

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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