Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Meta programming question

0 views
Skip to first unread message

Emil Dotchevski

unread,
Mar 24, 2001, 5:08:28 AM3/24/01
to
Hi guys,

I have the following problem: I have a nice hierarchy of simple classes, and
I want to write a template metaprogram that, for given 2 classes, will give
me their first common parent. I wrote something like:

template <class C1,class C2>
struct COMMONROOT
{
typedef
META::IF<
META::EQ<C1::CLASSID,C2::CLASSID>::res, /*condition*/
C1, /*then*/
META::IF< /*else*/
META::GT<C1::LEVEL,C2::LEVEL>::res, /*condition*/
COMMONROOT<C1::ltInherited,C2>::ret, /*then*/
COMMONROOT<C2::ltInherited,C1>::ret /*else*/
>::ret
>::ret ret;
};

For some reason it doesn't work, the result is infinite recursion. Note that
I have 2 helper enums defined in the structures, CLASSID which is unique
identifier of the structure, and LEVEL, which tells the level in the
hierarchy where the class resides.

Please help,
-- Emil.

Victor Bazarov

unread,
Mar 26, 2001, 9:08:01 PM3/26/01
to
"Emil Dotchevski" <za...@home.com> wrote...

> Hi guys,
>
> I have the following problem: I have a nice hierarchy of simple
classes, and
> I want to write a template metaprogram that, for given 2 classes, will
give
> me their first common parent. I wrote something like:
>
> template <class C1,class C2>
> struct COMMONROOT
> {
> typedef
> META::IF<

I am sorry, what is META and what relationship does it have with the
Standard C++ (the subject of this newsgroup)? I am asking because
I don't know, not because I want to pick on you.

Victor
--
Please remove capital A's from my address when replying by mail

Howard Hinnant

unread,
Mar 27, 2001, 8:56:00 PM3/27/01
to
In article <99osm2$is0$1...@nnrp.atgi.net>, Victor Bazarov
<vAba...@dAnai.com> wrote:

| "Emil Dotchevski" <za...@home.com> wrote...
| > Hi guys,
| >
| > I have the following problem: I have a nice hierarchy of simple
| classes, and
| > I want to write a template metaprogram that, for given 2 classes, will
| give
| > me their first common parent. I wrote something like:
| >
| > template <class C1,class C2>
| > struct COMMONROOT
| > {
| > typedef
| > META::IF<
|
| I am sorry, what is META and what relationship does it have with the
| Standard C++ (the subject of this newsgroup)? I am asking because
| I don't know, not because I want to pick on you.

The OP is referring to compile-time computation. It is a very
interesting area. And it is very relevant to C++ (C++'s template
facility to be specific). I regret that I don't have sufficient
information to answer the original question though. So called
meta-programming is notoriously difficult to debug. But often the
rewards are worth it.

-Howard

janc...@my-deja.com

unread,
Mar 28, 2001, 5:35:44 AM3/28/01
to

"Victor Bazarov" <vAba...@dAnai.com> wrote in message
news:99osm2$is0$1...@nnrp.atgi.net...

>
> I am sorry, what is META and what relationship does it have with the
> Standard C++ (the subject of this newsgroup)? I am asking because
> I don't know, not because I want to pick on you.
>
> Victor

If you are interested in the topic of static metaprogramming,
you might check out the book "Generative Programming"
by Krzysztof Czarnecki and Ulrich Eisenecker. It contains a
whole chapter about this stuff as well as other template
wizardry.

Jan

Steve Canfield

unread,
Mar 29, 2001, 9:27:26 PM3/29/01
to
janc...@my-deja.com wrote:
>
> "Victor Bazarov" <vAba...@dAnai.com> wrote in message
> news:99osm2$is0$1...@nnrp.atgi.net...
>>
>> I am sorry, what is META and what relationship does it have with the
>> Standard C++ (the subject of this newsgroup)? I am asking because
>> I don't know, not because I want to pick on you.
>>
> If you are interested in the topic of static metaprogramming,
> you might check out the book "Generative Programming"
> by Krzysztof Czarnecki and Ulrich Eisenecker. It contains a
> whole chapter about this stuff as well as other template
> wizardry.
>
I've just started Andrei Alexandrescu's Modern C++ Design and I think it
covers some of this stuff too. Excellent book, but some of the material is
quite difficult (at least for me). I would jump at the chance to attend a
tutorial or workshop on this stuff (Scott Meyers- are you listening ? :)

-sc

Howard Hinnant

unread,
Mar 29, 2001, 9:53:40 PM3/29/01
to
In article <iaSw6.16867$eX4.2...@typhoon.tampabay.rr.com>, Steve
Canfield <stevec...@my-deja.com> wrote:

| I've just started Andrei Alexandrescu's Modern C++ Design and I think it
| covers some of this stuff too. Excellent book, but some of the material is
| quite difficult (at least for me). I would jump at the chance to attend a
| tutorial or workshop on this stuff (Scott Meyers- are you listening ? :)

Just in case he isn't, here's a fwd from oon-...@oonumerics.org

CALL FOR EXTENDED ABSTRACTS

WORKSHOP ON C++ TEMPLATE PROGRAMMING
(http://www.oonumerics.org/tmpw01/)

Sunday, October 14, 2001
Tampa Bay, Florida, USA

in Conjunction with
OOPSLA 2001
(http://oopsla.acm.org/)


Some of the most exciting research in C++ focuses on the use of
templates, especially as a means to support generic and generative
programming. A number of powerful, flexible, and useful techniques
have been developed but these efforts appear isolated and are only
known to a few experts. This workshop will gather the community of
people interested in C++ template programming. The goal is dual:
first, to increase the visibility of information likely to be helpful
to other workers in the field of C++ template programming; second, to
clearly establish, and hopefully advance, the state-of-the-art in C++
template programming.

We encourage submission of extended abstracts of 7 to 12 pages on any
aspect of C++ template programming, including (but not limited to) the
following:

Generic and generative programming in C++
Uses or extensions of the STL or other templates in the
standard libray
Traits and traits-based programming
Iterators for multidimensional data structures
Template metaprogramming, including the representation of
metainformation in C++
Multiparadigm programming
Combining static configuration with dynamic techniques
Type-theoretic modelling of templates
Interaction of C++ templates with the object model
Expression templates
Experience reports on template programming
Debugging template code
Compiler support for templates, including compilation times and
diagnostics
Implementing C++'s template features
Portability issues
Template design and programming techniques

Our primary interest is in abstracts describing new work, but we will
consider abstracts based on prior publications. (Work that has already
been published should be identified as such.) One of our goals is to
increase the visibility of information likely to be helpful to other
workers in the field of C++ template programming.

As examples of suggested style and possible content, the accepted
papers from last year's (2000) Workshop can be found in:

http://www.oonumerics.org/tmpw00/


A workshop proceedings will be produced in electronic form, to be made
available via the Internet or on CD by the time of the workshop.


SUBMISSION GUIDELINES:

Extended abstracts (7-12 pages) should be sent to
tmp...@josuttis.de. Electronic submission in PDF is
strongly preferred. Questions about the submission process should be
sent to tmp...@josuttis.de.


IMPORTANT DATES:
15 June Extended Abstract Submissions Due
30 July Notification of Accepted Submissions
30 August Final Extended Abstracts Due


PROGRAM COMMITTEE:
Andrei Alexandrescu, RealNetworks, Inc., USA
Matt Austern, AT&T Research, USA
Thomas Becker, Zephyr Associates, Inc., USA
Krzysztof Czarnecki, DaimlerChrysler AG, Germany
Ulrich Eisenecker, University of Applied Sciences, Kaiserslautern,
Germany
Nicolai Josuttis (co-Chair), Author and Consultant, Germany
Scott Meyers, Author and Consultant, USA
Mark Rodgers, Cadenza New Zealand Ltd, New Zealand
Yannis Smaragdakis (co-Chair), Georgia Institute of Technology, USA
Erwin Unruh, Fujitsu Siemens Computers, Germany
David Vandevoorde, Edison Design Group, USA
Todd Veldhuizen, Indiana University, USA

--
Howard Hinnant

0 new messages