Re: [boost] [challenge!] find a common domain

----- Original Message ----- From: <daniel@boostpro.com> Newsgroups: gmane.comp.lib.boost.devel To: <boost@lists.boost.org> 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

On 5/20/2010 7:54 PM, Krishna Achuthan wrote:
daniel@boostpro.com wrote:
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.
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. <snip>
I also had to rearrange Daniel's code to make it work on msvc. For my own purposes, I moved the inheritance and overloads out of the domain types and into wrappers. I'm attaching the code. I'll probably end up using this. -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (2)
-
Eric Niebler
-
Krishna Achuthan