Boost logo

Boost :

Subject: Re: [boost] [guidelines] why template errors suck
From: David Abrahams (dave_at_[hidden])
Date: 2010-09-28 02:21:32


At Mon, 27 Sep 2010 18:22:41 -0700,
Steven Watanabe wrote:
>
> AMDG
>
> 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 );
> > }
> >
> > <snip>
> >
> > 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.

> The current situation with template error messages may be bad, but I
> strongly suspect that the errors coming from such a concept
> metaprogramming system would be far worse, because of the "silently
> fail to match" behavior of concepts.

You lost me there.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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