Boost logo

Boost :

Subject: Re: [boost] [challenge!] find a common domain
From: Krishna Achuthan (krishna.achuthan_at_[hidden])
Date: 2010-05-20 22:54:45


----- Original Message -----
From: <daniel_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.devel
To: <boost_at_[hidden]>
Sent: Thursday, May 20, 2010 6:05 AM
Subject: Re: [challenge!] find a common domain

> 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

When I tried to compile the code using VC 2005, it failed with the following
error:
error C2064: term does not evaluate to a function taking 1 arguments
deduce_domain.cpp 53
After I broke the struct into two pieces like below, it works fine.

template <class D0, class D1>
struct domain_depth
{
   static const int value = domain<D0>::index -
sizeof(domain<D0>::deduce((D1*)0));
};

template <class D0, class D1, int DefaultCase = sizeof(default_case((D0*)0,
(D1*)0))>
struct deduce_common : nth_domain<domain_depth<D0, D1>::value, D0>
{};

- Krishna Achuthan


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