Boost logo

Boost :

Subject: [boost] [challenge!] find a common domain
From: Eric Niebler (eric_at_[hidden])
Date: 2010-05-19 02:02:56


I recently solved a devilish C++ coding problem related to the new
sub-domain feature of Proto. I don't care for my solution, so I thought
I'd throw it out there and see if some smart person could do better. I'm
sending along the skeleton of the solution and some tests that it needs
to satisfy. The rest is up to you.

The problem goes like this. Every Proto expression has a "domain", which
is a type defined something like this:

  struct my_domain : domain<> {};

A domain can be a sub-domain of another domain, defined like this:

  struct my_sub_domain : domain<my_domain> {};

When combining sub-expressions into larger expressions, the new
expression has some domain that depends on the domains of its children.
This domain is calculated according to some rules.

- Domains that share no common super-domain are incompatible with each
  other. The result should be not_a_domain.
- A sub-domain is "stronger" than its super-domain.
- For a set of domains, the common domain is the strongest domain that
  is a super-domain of every domain in the set.
- default_domain is special; it is compatible with (and dominated by)
  all other domains.
- A sub-domain of default_domain is stronger than default_domain and
  still compatible with and dominated by all other domains.

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!

Good luck.

P.S. I haven't checked my solution in yet, so you can't look in trunk
and cheat. ;-)

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