Subject: Re: [boost] [guidelines] why template errors suck
From: Joel Falcou (joel.falcou_at_[hidden])
Date: 2010-09-28 05:44:31
On 28/09/10 08:21, David Abrahams wrote:
> At Mon, 27 Sep 2010 18:22:41 -0700,
> Steven Watanabe wrote:
>> On 9/27/2010 6:06 PM, Eric Niebler wrote:
>>> I think so far I have failed to make my use case sufficiently clear, so
>>> I'll simplify and try to follow the Process. Take the following simple
>>> algorithm sum_ints:
>>> template<class First, class Second>
>>> int sum_ints_impl( std::pair<First, Second> const& p )
>>> return sum_ints_impl(p.first) + sum_ints_impl(p.second);
>>> int sum_ints_impl( int i )
>>> return i;
>>> template<class T>
>>> int sum_ints( T const& t )
>>> return sum_ints_impl( t );
>>> Can you show me how you would approach this problem?
>> The only solution I know is to make sum_ints_impl
>> a concept itself with concept maps for int and std::pair.
>> Frankly, I think that moving the metaprogramming into
>> concepts like this is a terrible idea.
> That seems to presume that the use case is inherently more-naturally
> addressed by metaprogramming than by generic programming. That may be
> true for some use-cases, but I wouldn't know how to identify them. It
> certainly does *not* seem to be true for Eric's example.
Won't it be solved if we used external free function first() and
second() that take pair or int and return the pair element or the scalar
itself/0 for int ?
The constraints then becomes BehaveAsPair and check for any x of type T
if first(x) and second(x) is well formed ? Then again, if I understood
all the concept stuff correctly, one can write a sum_int_impl using this
Concept or is it too hacky ?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk