Boost logo

Boost :

Subject: Re: [boost] Formal Review Request: Boost.Convert
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-02-27 08:40:12


On Thursday, February 26, 2009 5:09 PM
Emil Dotchevski wrote:
> On Thu, Feb 26, 2009 at 12:42 PM, Andrey Semashev
> <andrey.semashev_at_[hidden]> wrote:
> >
> > template< typename ArgsT >
> > std::string operator()( ArgsT const& args ) const
> > {
> > return operator() (args[source], args[arg1], args[arg2]);
> > }
>
> I understand the problem very well, and I think the solution is not to
> write a function that takes a single args argument, but instead to
> provide overloads. This would not only solve your problem, it would
> also make convert() compatible with boost::bind/function/lambda etc.
>
> What's wrong with the following call syntax:
>
> boost::convert<target>( source const & [,arg1,arg2,...] )
>
> that is, the caller provides the target type for the conversion, then
> the first argument is considered the source (deduced automatically),
> and the rest of the arguments configure the conversion.

That only works if the argument types and number are known ahead of time. The Boost.Parameter approach allows for open ended extension -- for good or ill.

> Going back to my uuid example, uuid.hpp could simply say:
>
> #include <string>
>
> namespace user {
> class uuid;
> template <class Target> Target convert( uuid const & );
> template <> std::string convert<std::string>( uuid const & );
> }
>
> (no need to include anything.)

That's nice and clean. To support a variable number of formatting arguments, Boost.Parameter is helpful, so it would necessitate an overload to support those arguments:

   namespace user
   {
      template <class Target, class Args>
      Target
      convert(uuid const &, Args const &);
   }

Applying Boost.ConceptCheck can ensure that Args is a Boost.Parameter arguments pack. Since that is, of necessity a function template, it isn't as clean as your overload and since we don't yet have partial specialization of function templates, you can't create just the Target = std::string variant.

> Now, the user of uuid.hpp can also #include "boost/convert.hpp" when
> making calls to convert. This could provide generic overloads that
> support common conversion options, which would bind only if uuid.hpp
> doesn't provide overloads itself (which would obviously be more
> specialized and the overload resolution will prefer them over the
> convert.hpp generics.)

I like the idea of the framework providing default recognition of any supplied formatting information while deferring to customizations when available.

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

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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