
Giovanni Piero Deretta wrote:
On Sat, Apr 12, 2008 at 8:38 PM, Eric Niebler <eric@boost-consulting.com> wrote:
Giovalli:
Giova*ll*i ?!?!?!
Whoops, sorry. :-P
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();
Not a problem. It's a function template, so instantiating it would be cheaper than instantiating a class template (I think), but you're not even instantiating it. It doesn't even have a definition.
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.
This solution is very clever! Why do you say that compile time is poor? What are you benchmarking against? -- Eric Niebler Boost Consulting www.boost-consulting.com