Boost logo

Boost :

Subject: Re: [boost] [challenge!] find a common domain
From: Krishna Achuthan (krishna.achuthan_at_[hidden])
Date: 2010-05-21 10:58:23


"Eric Niebler" <eric_at_[hidden]> wrote in message news:<
4BF5CA3B.8090807_at_[hidden]>...
> 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
>

Here's another try. No inheritance or function overloading. I have no idea
how many template instantiations are there in this code and if it is
acceptable.
There is some influence from Daniel's solution in getting the
default_domain
resolutions right.

- Krishna Achuthan




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