From: Brendan M. <cat...@ca...> - 2008-10-18 23:27:04
|
I was looking around for some way to be able to do reflection with template metaprogramming, and was excited to find this tool. I'm wondering what kind of limitations it imposes though. Specifically, the website mentions that partial specialization isn't supported yet. Does that mean that if I make any use of templates with partial specialization in my code the openc++ compiler will barf, or does that mean that there is some limitations in how you can operate on templates with metaobjects? I tend to use boost pretty heavily, which makes extensive use of templates. If I try to operate on a class that takes a boost type as a parameter, has them as members, etc, when those types are based on templates that employ partial specialization, will that break openc++? What can I get away with, and what can I not get away with in terms of using templates. Thanks, Brendan |
From: Stefan S. <se...@sy...> - 2008-10-19 14:29:21
|
Hi Brendan, Brendan Miller wrote: > I was looking around for some way to be able to do reflection with > template metaprogramming, and was excited to find this tool. > Out of curiosity: what are you aiming to do ? Metaprogramming via templates and via OpenC++ are two radically different approaches. Do you want to mix them ? Or have you ran into limitations of what you can do via template metaprogramming, and now are hoping to find a way using OpenC++ ? > I'm wondering what kind of limitations it imposes though. > Specifically, the website mentions that partial specialization isn't > supported yet. Does that mean that if I make any use of templates with > partial specialization in my code the openc++ compiler will barf, or > does that mean that there is some limitations in how you can operate > on templates with metaobjects? > I have very limited experience with the OpenC++ metaprogramming model myself, but have worked a lot with the C++ parser that is part of OpenC++. The latter is rather limited, and falls over even with modern versions of libstdc++. I haven't dared to try it with boost. I have been making adjustments to a version of the OpenC++ C++ parser that I integrated into Synopsis (http://synopsis.fresco.org) a long time (> 8 years) ago. That version works fine with boost (I use it to generate docs for boost.python, for example). However, in that version I don't support the kind of metaprogramming originally promoted by OpenC++. Instead, I'm suggesting a different approach where the tool's internal code representation (IR) is made accessible (parse tree, AST, etc.) so any further source-to-source transformations can be scripted. That is still a project in progress. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... |
From: Brendan M. <cat...@ca...> - 2008-10-19 20:13:06
|
> Out of curiosity: what are you aiming to do ? Metaprogramming via templates > and via OpenC++ are two radically different approaches. Do you want to mix > them ? Or have you ran into limitations of what you can do via template > metaprogramming, and now are hoping to find a way using OpenC++ ? I ran into the problem that there's no way to get a list at compile time (or even run time for that matter) of the members of a class. Nor is there any way to operate on types in place. I'd like to be able to create something like decorators in python that operate on function and class definitions in place where: @MyDecorator class MyClass { ... }; translates into class MyClass_{ ... }; typedef MyDecorator<MyClass_>::type MyClass; Or @MyDecorator int f() { ... } translates into int f_() { ... } void f() { return MyDecorator<f_>::value(); } So for instance, I could have a decorator that performs logging (although I'd need some kind of stringize for that for that as well). Probably this isn't the right tool for that. Especially since it seems like it would be hard to use in production if I can't use the stl and boost. Thanks anyway, Brendan |
From: Stefan S. <se...@sy...> - 2008-10-19 20:36:34
|
Brendan Miller wrote: > > So for instance, I could have a decorator that performs logging > (although I'd need some kind of stringize for that for that as well). > > Probably this isn't the right tool for that. Especially since it seems > like it would be hard to use in production if I can't use the stl and > boost. > Indeed. In fact, I have found the whole idea of putting some markup right into the source code flawed, for one simple reason: it's not C++ any more, and thus, is tied to a particular tool. It's easier to keep the transformation description separate, so at least the code keeps working, albeit un-instrumented, with ordinary C++ compilers. While logging seems to be the one example people keep referring to in such cases, I haven't found much else that such approaches would be useful for. The same holds true for Aspect-Oriented Programming...This reminds me, may be you would be interested in ApectC++ (http://aspectc.org/) ? Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... |
From: Yann D. <yd...@us...> - 2008-10-21 21:10:07
|
On Sun, Oct 19, 2008 at 01:12:57PM -0700, Brendan Miller wrote: > > Out of curiosity: what are you aiming to do ? Metaprogramming via templates > > and via OpenC++ are two radically different approaches. Do you want to mix > > them ? Or have you ran into limitations of what you can do via template > > metaprogramming, and now are hoping to find a way using OpenC++ ? > > I ran into the problem that there's no way to get a list at compile > time (or even run time for that matter) of the members of a class. Nor > is there any way to operate on types in place. This kind of metaprogramming is not unlike what Qt provides. See eg. http://doc.trolltech.com/4.3/object.html and http://doc.trolltech.com/4.3/metaobjects.html HTH, -- Yann |