Re: How can I use unqualified names? (Possibly hard or impossible?)
* James Kanze:
On Jul 26, 10:35 pm, "Alf P. Steinbach" <al...@start.no> wrote:
I find it difficult to believe that you're unfamiliar with
typelists.
I've heard the name, but that's about it. I don't doubt that I
could learn them, if I had any reason to, but until now, I've
not had any reason to.
[snip]
In contrast it's trivial to write a typelist implementation
that provides basic functionality, and any C++ programmer
should be able to do so: any C++ programmer should be able to
just sit down and write it without any second thought.
Maybe. Given that all I know about it is the name, I can't
judge. I don't really even know what it does, exactly. (I'm
guessing that it's some sort of list of types, but I don't
really know what that means, or how it is used.)
Typelists were popularized by Andrei. I think he invented them independently but
they already had some history. What Andrei did was to show how all the usual run
time control structures had analogs in template metaprogramming, and to build up
from that to a framework handling types just as for run time you handle values.
I made a basic example "the minimal typelist" :-), shown below.
It may interest other readers of the group (of course what this example does is
very simple, intentionally, whereas the inheritance over a list of types in the
option macro stuff I posted earlier is one or two degrees more complex):
<code>
#include <iostream>
#include <limits>
struct NoSuch {};
// General Lisp-like typelist
template< class HeadType, class TailType = NoSuch >
struct Typelist_
{
typedef HeadType Head;
typedef TailType Tail;
};
template< class T >
void showMaxValue()
{
using namespace std;
cout << numeric_limits<T>::max() << endl;
}
template< class Typelist >
void showMaxValues()
{
showMaxValue< typename Typelist::Head >();
showMaxValues< typename Typelist::Tail >();
}
template<> void showMaxValues<NoSuch>() {}
int main()
{
typedef Typelist_<int, Typelist_<float, Typelist_<double> > > Types;
showMaxValues<Types>();
}
</code>
Cheers,
- Alf