Questions tagged [metaprogramming]

Metaprogramming is the capability to reprogram ones programming environment, as with macros or metaclasses.

Metaprogramming - the capability to reprogram ones programming environment - can save time and code by allowing one to create new abstractions, or new and more concise syntax for repetitive tasks.

Notable metaprogramming facilities include:

  • Common lisp macros
  • Scheme hygienic macros
  • Common lisp metaobject protocol
  • Python metaclass facility
  • Smalltalk's entirely transparent and reflective execution environment

For more info see http://en.wikipedia.org/wiki/Metaprogramming.

4722 questions
3
votes
1 answer

why is this short snippet of template code valid?

As per the title, I do not understand how can the following code compile when has_type_struct is certainly an invalid type. template using my_int = int; struct no_type {}; template struct has_type_struct { using…
blue
  • 2,683
  • 19
  • 29
3
votes
1 answer

Idiomatic MetaProgramming

While the web abounds with resources extolling the myriad metaprogramming capabilities of Groovy, I've yet to find anything close to a comprehensive "best-practices" guide for the actual use of such features. Aside from the typical caveat emptor…
Northover
  • 981
  • 8
  • 14
3
votes
2 answers

How can I invoke a macro with all points in a catersian product of argument sets?

Suppose I have a macro FOO(a, b) and I want to invoke this macro with a certain (fixed) set of possible values for a; and a certain fixed set of values for b. Thus, if my set of b values is bar and baz and my set of b values is fiz and bang, I…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
3
votes
1 answer

hana::second can't deduce type

I'm trying to access a hana::type from a pair using hana::second... namespace hana = boost::hana; using namespace hana::literals; struct Key {}; struct Foo {}; int main() { auto test = hana::make_tuple( hana::make_pair( …
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
3
votes
2 answers

hana::tuple to auto && ... args

Is there a way to use something like : constexpr auto foo = hana::make_tuple(hana::type_c,hana::type_c); with something like: template < typename ... Ts > struct Final { constexpr Final(Ts && ... args) {} }; hana::unpack(foo, []…
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
3
votes
3 answers

Is there a good way of getting MethodInfo of open generic method?

Consider type like this one public interface IHaveGenericMethod { T1 Method(T1 parm); T2 Method(T1 parm); int Method2(int parm); } How do I get a methodInfo for its methods? for a regular non-generic method, like method2, I can…
Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115
3
votes
1 answer

What *exactly* do the "public", "private" and "protected" methods do?

Almost all decent resources about OOP in Ruby state the existence of access modifiers - keywords public, private and protected - and show how to properly use them. Fewer go to the extent of explaining that these modifiers are not keywords, but are…
DeFazer
  • 521
  • 3
  • 17
3
votes
4 answers

use metaprogramming to surround methods in a class

I have classes with methods that log when a method is entered and exited like so: def methodName1(args) @logger.debug(">>#{callee}") ... @logger.debug("<<#{callee}") end def methodName2(args) @logger.debug(">>#{callee}") …
amadain
  • 2,724
  • 4
  • 37
  • 58
3
votes
1 answer

Clojure's macro - define a binding whose name is composed from an argument

OK, I want to write a Clojure macro that defines a struct-map and let caller to specify types for each field. The signature will look like this: (defmodel category :id Integer :name String) What this does is it creates a struct-map called category,…
EnToutCas
  • 1,297
  • 2
  • 15
  • 20
3
votes
2 answers

Is there a XML meta language for expressing complex search queries?

during the past couple of years a lot of our internal APIs for modifying and searching our database have become more and more entangled with the specific needs and application logic of the front ends that they power. To counter that trend we've…
n3rd
  • 5,989
  • 4
  • 39
  • 56
3
votes
3 answers

Preserving struct field visibility with a macro

I'm trying to write a Rust macro that allows me to make use of the field names and types of a struct declaration, but I still need to emit the struct. I've got it working with optional attributes, visibility of the struct (thanks to The Little Book…
lloydmeta
  • 1,289
  • 1
  • 15
  • 25
3
votes
2 answers

C++ function converting question

I attempted to use boost::function wrapper to store and convert my functional objects and I want to know if there a compile-check for "does a conversion from arbitrary type T to type boost::function exists". Here is a code example: struct…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
3
votes
1 answer

Metaprogramming in awk, convert file to html table format

I have the following files: table.txt (comma separate) 1,Example Title COL1,COL2,COL3,COL4,COL5 BRCC,ACGC,15869,105A,1 BCAS,GAAG,73345,369T,2 template.awk function parse_print(s){ s = gensub(/^\s+|\s+$/,"","g",s) s =…
Jose Ricardo Bustos M.
  • 8,016
  • 6
  • 40
  • 62
3
votes
1 answer

Trapping class definition via Proxy in ES6

Is it possible to trap extends? Or to trap definitions inside a class? Eg: class B extends A { method1( ) { } static method2( ) { } } Is there any way to trap the events that: B extended A. method1( ) was defined on B.prototype method2( )…
Gubbi
  • 756
  • 1
  • 7
  • 18
3
votes
2 answers

In Python, how can you respond to method calls that don't exist on an object?

Possible Duplicate: Dynamic Finders and Method Missing in Python I know you can do this in Ruby, but how would it be done in Python? So basically you could maybe to a regex on the method call that didn't exist, and create 'syntactic sugar'.
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
1 2 3
99
100