Boost logo

Boost :

From: Pavol Droba (droba_at_[hidden])
Date: 2003-01-09 07:30:01


On Wed, Jan 08, 2003 at 12:06:33PM -0500, David Abrahams wrote:
> Vladimir Prus <ghost_at_[hidden]> writes:
>
> > David Abrahams wrote:
> >> Vladimir Prus <ghost_at_[hidden]> writes:
> >
> >>>I'd prefer the latter variant, so that non-broken platforms use more natural
> >>>syntax. Another question is whether we could use only the second version.
> >>>Theoretically, if you call the second version on const string, then InputT
> >>>should be deduced as "const string". You can then write a simple wrapper to
> >>>select const_iterator or iterator.
> >>>
> >>>The only problem is, IIRC, borland drops "const" on template arguments
> >>>sometimes, and that's not possible to fix. Also, the "simple wrapper"
> >>>requires partial specialization. So, I'm not sure this approach is
> >>>viable, either.
> >> There are mostly-transparent solutions. Something like:
> >> // find_first sequence const version
> >> template< typename InputT, typename SearchT >
> >> inline iterator_range< typename InputT::const_iterator >
> >> find_first_impl( const InputT& Input, const SearchT& Search, 0 )
> >> {
> >> ...
> >> }
> >
> > I'm guessing the last parameter should be "int"?
>
> No, sorry. It should be "..."
>
> >> // find_first sequence non-const version
> >> template< typename InputT, typename SearchT >
> >> inline iterator_range< typename InputT::const_iterator >
> >> find_first_impl( InputT& Input, const SearchT& Search, int )
> >> {
> >> ...
> >> }
> >> // find_first sequence
> >> template< typename InputT, typename SearchT >
> >> inline iterator_range< typename InputT::iterator >
> >> find_first( InputT& Input, const SearchT& Search )
> >> {
> >> find_first_impl(Input, Search, 0);
> >> }
> >> Should work on vc6. Can't vouch for Borland, though :(
> >
> > Unfortunately, "first_first" will return the same plain (non-const) iterator
> > in all cases. And we'd need to return const_iterator when string is const.
>
> OK, let me fix that:
>
> // find_first sequence
> template< typename InputT, typename SearchT >
> inline iterator_range<
> typename mpl::if_<
> is_const<InputT>
> , typename InputT::const_iterator
> , typename InputT::iterator
> >::type
> >
> find_first( InputT& Input, const SearchT& Search )
> {
> find_first_impl(Input, Search, 0);
> }
>
> Looking at the name of the function, it occurs to me that dispatching
> to separate implementations might not be needed.
>
> The only restriction on this one is that it doesn't work when the
> Input parameter is an non-const rvalue.

Is this approach feasible for boost? IIRC, somebody mentioned, that BCC does
not handle correctly const templace paramenters, and so, is_const<InputT> would
not work....

I would rather prefer one not-the-pretiest-but-working solution to one which
works only 90% of time without a possible workaround ...

What is the stretegy in Boost development?

Pavol


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