Boost logo

Boost :

Subject: Re: [boost] [challenge!] find a common domain
From: Eric Niebler (eric_at_[hidden])
Date: 2010-05-20 19:48:11


On 5/20/2010 10:54 AM, John Bytheway wrote:
> On 19/05/10 07:02, Eric Niebler wrote:
> <snip>
>> Your job: implement the deduce_domain3 template that finds the common
>> domain of 3 domains. You're allowed to use decltype, but you get bonus
>> points for a solution that doesn't. Bonus also for instantiating fewest
>> templates. The challenge is for the ternary case, but your solution
>> should scale to N domains. If your solution is better than mine, I'll
>> use it in Proto and credit you!
>
> I attach my solution for completeness, though I think Daniel's is
> neater. I used a similar idea to him, but without the use of
> sizeof/decltype, and with the distance-to-not_a_domain implemented as a
> metafunction, rather than injected into the definition of domain.
>
> I think we use about the same number of instantiations, but Daniel's
> lends itself to unrolling much more than mine. I might argue that my
> implementation is a little easier to follow than his, but it would be a
> pretty feeble claim.

Thanks, John. I'll need to investigate more closely. Everybody's code is
easy to follow when they wrote it! :-) Though I admit, Daniel's solution
is subtle and had me scratching my head for a while.

And for completeness, here is my (decltype-based) solution. I tried to
make one giant expression that calculates the result in one shot. Like
Daniel, I use inheritance and overloading, but I build a parallel
hierarchy instead of reusing the domains. (For reasons that aren't
relevant, I don't want domains to actually inherit from other domains in
Proto.)

-- 
Eric Niebler
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