473,326 Members | 2,012 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,326 software developers and data experts.

Using template metaprogramming to generate a composite class withID derived from components

Given a set of classes

class A { enum [ ID = 0x0001} };
class B { enum [ ID = 0x0002} };
class B { enum [ ID = 0x0004} };

I wish to generate a composite class, perhaps using something like
Alexandrescu's typelists

(pseudo-code:)

template<class TList>
class Composite : TList
{
enum {ID = SumID<TList>::result}
};

typedef composite<TYPELIST(A,B,C)> CompABC; // ID == 0x0007

Of course, the trivial A, B and C classes above would have data members
to make Composite meaningful, but the really important issue is
Composite's ID member, the value of which must be unique to the
combinations of components.

Thus, there are two parts to this. One, generating a linear inheritance
hierarchy from the typelist; and two, summing up the components' ID
values as the ID value of the generated composite.

Though I know exactly what I need I've so far (due to my inexperience
with metaprogramming) failed to implement this. I've tried using
Alexandrescu's Loki and BoostMPL, but am stymied. Any help would be
deeply appreciated!
Jul 23 '05 #1
0 1420

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

Similar topics

5
by: Mohammad | last post by:
Hi, Is it possible to disable a method of a template class depending on the typename at compile time? thanks!
5
by: Gonçalo Rodrigues | last post by:
Hi all, (note: newbie alert) Suppose you have a hierarchy of objects that you deal with via smart pointers, e.g. something like: template<typename T> class Ref { private:
19
by: n.torrey.pines | last post by:
I have the following tree definition: template<typename T> struct tree { T first; vector<tree<T second; // branches }; which compiles successfully. What I'd like to do though is to use...
7
by: Joe | last post by:
Hi, I found a concept named template metaprogramming that can be used in C+ + code at compile-time. I am a beginner at C++. But I am a programmer on the .NET platform. Do you know if template...
1
by: Ted | last post by:
I have cross posted this to comp.lang.c++ and to sci.math.num- analysis in the belief that the topic is of interest to some in both groups. I am building my toolkit, in support of my efforts in...
4
by: Alan Woodland | last post by:
I've been trying out more template metaprogramming ideas with typelists (mostly for personal learning, I'm aware boost most probably provides this facility already), and I've run into this small...
4
by: suman.nandan | last post by:
Hi C++ Experts ! I have a little weird requirement. I have a base class, say B and lots of classes D1 .. Dn publicly derived from it. Over the course of development the number of derived...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
4
by: nooneinparticular314159 | last post by:
I'm trying to understand template metaprogramming syntax. It's been years since I've touched C++, so this may actually be a C++ syntax issue (although it seems that the language has changed...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.