Boost logo

Boost :

From: Anand Shankar (anand.shankar.k_at_[hidden])
Date: 2008-04-12 15:13:40


Hi,

Here's a solution similar to Marco's - finds the first non default type
using template specialization.
It uses sizeof to check whether the types following first non-default type
are conforming.

Anand.

On Sat, Apr 12, 2008 at 2:38 PM, Eric Niebler <eric_at_[hidden]>
wrote:

> Eric Niebler wrote:
> > I recently had a C++ problem and found an answer that tickled my brain.
> > In the spirit of Car Talk on NPR, I thought I'd share it in the form of
> > a puzzler.
> <snip>
> > Answer next week, unless someone beats me to it.
>
> Wow, everybody loves a puzzle! This is good fun.
>
> Joaquin and Marco Co.: virtual inheritance. Clever! I think it
> instantiates O(N) templates though.
>
> Matus: This works but has scalability problems. To handle a set with N
> types, you need 2^N specializations of common_type_helper_picker.
>
> Giovalli: conditional operator. Wish I thought of that. But it requires
> types to be associated with integers via a global registry, so I can't
> use it. Is there a way to avoid select() and result<>? It's easy with
> typeof, but can you do it without?
>
> Marco Ce: This is pretty good! I think this instantiates O(1) templates
> in the case that a common type exists. Awesome. It's simpler that what I
> came up with, too.
>
> Steven W: Wow, makes my head hurt. I think I see what's going on -- 2^N
> specializations? Might not scale so well.
>
> Daniel Fey: Similar to what I came up with, but there's a trick that can
> (a) knock the 2^N overloads down to N, and (b) eliminate the need for
> typeof.
>
> --
> Eric Niebler
> Boost Consulting
> www.boost-consulting.com
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>




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