Re: [boost] [guidelines] why template errors suck

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 ); }
Hi, how about the below. Concept IntOrPair is empty because you do not require it to have any operations. Keyword "explicit" indicates that we do not want it to be an auto-concept: concept map is > always required. The second concept_map implements the recursion.
Regards, &rzej
explicit concept< typename T > IntOrPair { }
concept_map IntOrPair<int> { }
template< IntOrPair type1, IntOrPair type2 > concept_map IntOrPair< std::pair<type1, type2> > { }
template<IntOrPair First, IntOrPair 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<IntOrPair T> int sum_ints( T const & t ) { return sum_ints_impl( t ); }
Well, I believe I got it wrong. It is concept maps where the specializtion is to tke plce. It should read: explicit concept< typename T > IntOrPair { int sum_ints_impl( T const& ); } concept_map IntOrPair<int> { int sum_ints_impl( int const& i ) { return i; } } template< IntOrPair type1, IntOrPair type2 > concept_map IntOrPair< std::pair<type1, type2> > { int sum_ints_impl( std::pair<First, Second> const& p ) { return sum_ints_impl(p.first) + sum_ints_impl(p.second); } } template<IntOrPair T> int sum_ints( T const & t ) { return IntOrPair::sum_ints_impl( t ); } Regrds, &rzej

At Tue, 28 Sep 2010 19:05:00 +0200, Andrzej Krzemienski wrote:
Well, I believe I got it wrong. It is concept maps where the specializtion is to tke plce. It should read:
explicit concept< typename T > IntOrPair
"explicit concepts" were never part of any accepted proposal ;-)
{ int sum_ints_impl( T const& ); }
concept_map IntOrPair<int> { int sum_ints_impl( int const& i ) { return i; } }
template< IntOrPair type1, IntOrPair type2 > concept_map IntOrPair< std::pair<type1, type2> > { int sum_ints_impl( std::pair<First, Second> const& p ) { return sum_ints_impl(p.first) + sum_ints_impl(p.second); } }
template<IntOrPair T> int sum_ints( T const & t ) { return IntOrPair::sum_ints_impl( t ); }
I think what you wrote is equivalent to what I posted in http://permalink.gmane.org/gmane.comp.lib.boost.devel/209012 However, as I noted in that message, trying to constrain something to be either an Int or a Pair is really against the spirit of GP. -- Dave Abrahams BoostPro Computing http://www.boostpro.com
participants (2)
-
Andrzej Krzemienski
-
David Abrahams