metaprogramming

Boost.Fusion Functional: Calling functions with default arguments

Is it possible to use boost::fusion::invoke function to call a function that has default arguments without specifying those? Example: void foo(int x, int y = 1, int z = 2) { std::cout << "The sum is: " << (x + y + z) << std::endl; } ... // This should call foo(0). It doesn't work because the type of foo is void (*) (int, int, int)....

Can I add numbers with the C/C++ preprocessor?

For some base. Base 1 even. Some sort of complex substitution -ing. Also, and of course, doing this is not a good idea in real life production code. I just asked out of curiosity. ...

Type condition in C++ template class problem

Hello, Using GCC 4.2. I have this metatemplate for conditional type: template <bool condition, typename Then, typename Else> struct IF { typedef Then RET; }; template <class Then, class Else> struct IF<false, Then, Else> { typedef Else RET; }; and when I use it like this: template <typename T> class Param { IF< sizeof(i...

Examples of what D’s templates can be used for

I hear that the D language has powerful metaprogramming features for executing functions at compile time. That sounds very exciting, but I find it difficult to think of practical examples of things that are hard to accomplish without them. Can anyone give some examples of situations where D's metaprogramming features comes in very hand...

How do you determine the nested classes of a class?

In Ruby, how do you determine the nested classes of a class? ...

Can you implement a dynamically created PSObject such that equality and comparison work?

I have been implementing makeshift types by dynamically adding methods to PSObjects I want to be able to compare two instances of my objects using the "-eq" "-lt" and "-gt" operators (I assume this would require me to implement interfaces like IComparible, and IEquatible) Is this sort of thing possible? (I'm thinking perhaps not as the...

Does powershell have a method_missing()?

I have been playing around with the dynamic abilities of powershell and I was wondering something Is there is anything in powershell analogous to Ruby's method_missing() where you can set up a 'catch all method' to dynamically handle calls to non-existant methods on your objects? ...

Add existing classes into a module

Hello, I have some existing ruby classes in a app/classes folder: class A ... end class B ... end I'd like to group those classes in a module MyModule I know I could do like: module MyModule class A ... end class B ... end end but is there a meta programming shortcut that could do the same so I could...

Associating properties to Class objects

I would like to define properties for classes, and be able to access them before I actually instantiate an object of that class. I'll give some context. My application handles a library of components. Each component is mapped to a Python class. Now I want to know what configuration a component needs, before actually instancing the class...

Is metaprogramming being used in real-world c++ software projects?

Possible Duplicate: What's the use of metaprogramming? I know that in C++, there are libraries providing metaprogramming facitlities, like Boost MPL. But are they really useful in real-world C++ projects ( or just used in rare situations ) ? ( I have the feeling that metaprogramming code are weird and can generate hard-to-deb...

Groovy metaprogramming

In a Service of a Grails project, I like to find, at run time, the arguments of Dynamic Methods in order to inform callers. Also, I like to call the method and if doesn't exist to return an error, I will appeciate any help. ...

Making __import__ get the dynamically added methods

Hey, At my work place there is a script (kind of automation system) that loads and runs our application tests from an XML file. In the middle of the process the script calls __import__(testModule) which loads the module from its file. The problem starts when I tried adding a feature by dynamically adding functions to the testModule at...

Python, import string of Python code as module

In python you can do something like this to import a module using a string filename, and assign its namespace a variable on the local namespace. x = __import__(str) I'm wondering if there is a related function that will take take a string of Python code, instead of a path to a file with Python code, and return its namespace as a varia...

Check if a class has a method

Possible Duplicate: Possible for C++ template to check for a function's existence? Do you know of any metaprogramming tricks in C++ that allow me to check whether a class has a specific method. I has been thinking about something like this: template <class T, class Enable = void> class A { ... }; // This version of the clas...

Python metaprogramming for XML parsing

I'm trying to create a simple XML parser where each different XML schema has it's own parser class but I can't figure out what the best way is. What I in effect would like to do is something like this: in = sys.stdin xmldoc = minidom.parse(in).documentElement xmlParser = xmldoc.nodeName parser = xmlParser() out = parser.parse(xmldoc) ...

Generating a set of methods for checking messages' content

Hi, in my unit test framework, for some of the messages ( which are simply POD structures ) I need a method to compare two such messages ( structs ) for equality of all fields. That is if for example I have a message: struct SExampleMessage { int someField; int someField2; char someField3[10]; }; I have a method that take...

How can I print a variable name and its value without typing the name twice?

When you are debugging, it's very useful to do this: var = calc() print("var:", var) Is there any language where this is easy to do? In C and C++ you can use the stringify macro operator # and in Ruby I found this question: http://stackoverflow.com/questions/2603617/ruby-print-the-variable-name-and-then-its-value The solution that u...

Is there a guarantee as to the size of a class that contains an array?

Given: template <int N> struct val2size { char placeholder[N]; }; Is there any guarantee that sizeof(val2size<N>) == N? ...

jQuery - can I "append" an additional parameter to every get/post request made

Hi, I would like to extend jQuery such that every post/get request made on the client side will have an additional parameter sent (always the same key : value). I need this to detect on the client side if the request was made through jQuery, since I have several js libs at work. The additional param is simply jquery : true. A typical re...

How to dynamically create module level functions from methods in a class

I am trying to dynamically create module level functions from the methods in a class. So for every method in a class, I want to create a function with the same name which creates an instance of the class and then calls the method. The reason I want to do this is so I can take an object-oriented approach to creating Fabric files. Since F...