Boost logo

Boost :

From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-04-12 20:22:25

On Sat, Apr 12, 2008 at 8: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.

Yup! Great fun.

> Giovalli:

Giova*ll*i ?!?!?!

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

Here is a try. it probably will look more at home at an obfuscated C++ context.

It works up to 5 types. Extending it beyond is a matter of a little of
pp metaprogramming.

The only O(N) template (that I can see) instantiation is
template<class T> default_type::operator T();
And you do not pay for it if you do not use default_type (partially
specializing common_type may work as an optimization).

I'll try to get rid even of this.

Even if there are very few template instantiations, compile time isn't
that good. I thought that compile time integral expression
computations were basically free. Maybe I'm missing something.


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