I read about typelists in 'Modern C++ Design' and I understood it as some kind of union for types. By putting diffrent, non-related types in a typelist, one can use it to represent more than one type at once, without inheritance. I tested typelist in some simple functions with primitive types, but I couldn't get any of them to work.
Cou...
I have tried reading:
http://www.boost.org/doc/libs/1_41_0/boost/variant.hpp
http://www.codeproject.com/KB/cpp/TTLTyplist.aspx
and chapter 3 of "Modern C++ Design"
but still don't understand how variants are implemented. Can anyone paste a short example of how to define something like:
class Foo {
void process(Type1) { ... };
...
(from reading chapter 3 of modern c++ design)
typelist.hpp:
class NullType {};
struct EmptyType {};
template <class T, class U>
struct Typelist
{
typedef T Head;
typedef U Tail;
};
#define TYPELIST_1(T1) Typelist<T1, NullType>
#define TYPELIST_2(T1, T2) Typelist<T1, TYPELIST_1(T2) >
#define TYPELIST_3(T1, T2, T3) Typelist<T1, T...
Here,
http://stackoverflow.com/questions/2150618/how-do-i-fix-this-c-typelist-template-compile-error
we built a typelist, using the code from modern c++ design.
Question is now -- how do I take this and built it into a variant class?
Thanks!
...
This is from TTL:
////////////////////////////////////////////////////////////
// run-time type switch
template <typename L, int N = 0, bool Stop=(N==length<L>::value) > struct type_switch;
template <typename L, int N, bool Stop>
struct type_switch
{
template< typename F >
void operator()( size_t i, F& f )
{
...
Here's what I want to be able to type:
class foo : public watchKeys<A, B, C> {}; //Or any list of keys
Boost::mpl has sequences, which allow you to do this, but I don't want to have to do:
class foo : public watchKeys<mpl::list<A, B, C> > {};
I don't mind it being "ugly" or verbose on the inside, but I want the way watchKeys is ult...
I was having a look at the "Function" class documentation in Boost, and stumbled across this:
boost::function<float (int x, int y)> f;
I must admit this syntax is highly confusing for me. How can this be legal C++ ?
Is there any trick under the hood ? Is this syntax documented anywhere?
...
can we have a note typelist to include another link typelist in typepad.
which has a link typelist.
...