|
Boost : |
Subject: Re: [boost] Formal Review Request: Boost.Convert
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2009-02-26 15:42:26
Emil Dotchevski wrote:
>>> Anyway, another question: is there a way to make operator() not be a
>>> template?
>> It should be doable if you only need to receive the "source" argument to
>> convert from. But if you want other arguments as well, I can't figure out
>> how to do it without a template, unless to resort to type erasure.
>
> Well, one way to take arguments is to tell the compiler that your
> function or operator() takes arguments, right?
>
> std::string operator()( uuid const & value, int arg1, float arg2 );
>
> C++ was type-safe even before templates were introduced. :)
It's not about type safety, it's about making the compiler to deduce
your intentions. How do you instruct the compiler to pass the argument
with tag "arg1" into the second argument of your operator, and not in
the first or third? I can only see one way to do so:
template< typename ArgsT >
std::string operator()( ArgsT const& args ) const
{
return operator() (args[source], args[arg1], args[arg2]);
}
Thus, yielding the template I was suggesting to leave in my previous post.
> If I'm the maintainer of class uuid and I am asked to provide a
> to-string conversion, you'll find it very difficult to convince me
> that it makes sense to replace this:
I believe, Robert has already answered this. You get more flexibility
and the common interface for this functionality. If you don't need all
this stuff, you can stay with the simple and restricted interface you
suggest, and I won't even try to reconvince you. :) I'll just say that I
often prefer flexibility if it doesn't compromise user-side usability
too much.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk