Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2008-04-12 14:38:06

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

Eric Niebler
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at