Boost logo

Boost :

Subject: Re: [boost] [challenge!] find a common domain
From: daniel_at_[hidden]
Date: 2010-05-20 06:05:06


On Wed, May 19, 2010 at 03:54:29PM -0700, Eric Niebler wrote:
> On 5/19/2010 3:29 PM, Daniel Wallin wrote:
> > On Tue, May 18, 2010 at 11:02:56PM -0700, Eric Niebler wrote:
> >> 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.
> >
> > Here's mine. It's decltype based, but I guess it could be sizeof based
> > in C++03.
>
> Wow! SO much simpler than my solution. I'll need to study this in depth.
> I also specialized domain<default_domain> to insert an extra level in
> the inheritance tree like you did. That's a great simplification, but it
> took me a week to see that. Kudos.

Thanks. :)

> BTW, you're creating a zero-sized array in sized_type<0>. I just
> bumped all the integers by one and it works fine on msvc-10.

Duh, good catch.

> This looks more efficient at compile-time, too. I'll be embarrassed to
> post my solution. :-O But not yet. Anybody care to eliminate decltype so
> I can use this in Proto? Anybody think they can instantiate fewer templates?

Here's one without decltype. The changes needed were pretty minor. It
might still be possible to reduce the number of instantiations. For
instance, you could specialize nth_domain<> on some more indicies (I'm
guessing the number of super domains should be fairly low), but I don't
know what the cost of specialization compared to instantiation is.

-- 
Daniel Wallin
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