473,378 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

A new approach to specifying typelists?

Hi,

I've been using Loki-style typelists extensivley in my code for a while
now, and have found them extremely useful, although somewhat annoying
to specify due to all the close angle brackets required.

Recently, though, I started using this syntax:

////////////////////////////////////////////////////////////////////////////
struct TypelistEnd {};

template<class _head, class _tail = TypelistEnd>
struct Typelist
{
typedef _head Head;
typedef _tail Tail;

template<class t>
struct Add
{
typedef Typelist<t, Typelist<_head, _tail Type;
};
};

//////////////////////////////////////////////////////////////////////////

Which allows the following construct to be used to specify
a typelist.

typedef Typelist
<Type1>::Add
<Type2>::Type::Add
<Type3>::Type::Add
<Type4>::Type::Add
<Type5>::Type::Add
<Type6>::Type::Add
<Type7>::Type tTypelist;

Which is much more convenient to use than the recusive approach,
provided
you don't mind that the list will end up in the opposite order.

A more complex approach allows the list to be constructed in the
correct order:

//////////////////////////////////////////////////////////////////////////

struct TypelistEnd {};
template<class TList, class NewItemstruct Append;

template<class _head, class _tail = TypelistEnd>
struct Typelist
{
typedef _head Head;
typedef _tail Tail;

template<class t>
struct Add
{
typedef typename Append<Typelist<_head, _tail>, t >::Result Type;
};
};

template<class H, class NewItem>
struct Append<Typelist<H, TypelistEnd>, NewItem>
{
typedef Typelist<H, Typelist<NewItem, TypelistEnd Result;
};

template<class H, class T, class NewItem>
struct Append<Typelist<H, T>, NewItem>
{
typedef Typelist<H, typename Append<T, NewItem>::Result Result;
};
Is this new? Or am I just re-inventing something? Or is it, in some
way, bad?

-dave

Nov 2 '06 #1
0 1069

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: BenOne© | last post by:
Hi all, I want to create a layout with a heading at the top and two columns below it, with the left containing a menu, and the right containing the main content of the page. I'd like the heading...
5
by: Jon Slaughter | last post by:
I'm having some issues using loki's typelists and I'm wondering if there is something I'm missing. I'm trying to create a template who's specialization sorta looks like template <int I, class...
56
by: Luke Matuszewski | last post by:
I am designing the library, which will hidden all its functions within singleton object ... So for clients they will use it like . eg. system.getElementWithId('ruler'); At library side, i...
1
by: greek_bill | last post by:
Hi all, I'd like to have code that looks like the following : BEGIN(Foo) ADD(float); ADD(int); ADD(char); END()
6
by: satish mullapudi | last post by:
Hi All, I am getting strange situation. These r the steps I have followed: 1. Created an EMPLOYEE table with around 14 fields & 688038 records. (so a large table indeed). 2. Tried to delete all...
1
by: zufie | last post by:
Hi, I want to specifying a foreign key by altering a table. First, I create an ORDERS table without specifying a foreign key. Here is my code: CREATE TABLE ORDERS (Order_ID integer,...
2
by: mathieu | last post by:
Hello, I am trying to work around the issue with floating point as template parameter. Basically all I want is be able to take advantage of the compile time optimization. For instance how would...
14
by: Leah | last post by:
I am a student and are required to build a website that provide services (client-server). I need advice in choosing approach or to be exact the methodology that appropriate for such development....
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.