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

Constexpr loop with a no constexpr content

I want to use boost hana to generate this final code: template < typename ... Ts > void foo(Ts ... data) { constexpr auto tuple = hana::make_tuple(data...); //Code that I need to be generate container_c[tuple[0_c]].foo2(); …
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
3
votes
1 answer

How to remove metaprogramming recursion with Boost Hana

I'm trying to create a bitset according to the type send to the function. But let's reduce the test case a little. Warning : I'm using auto gcc extension for this example, I don't need to use template parameter. namespace hana =…
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
3
votes
2 answers

template metaprogramming with reference

I was checking some solutions of the book cpp template metaprogramming for the 1st exercise http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?CPPTM_Answers_-_Exercise_2-0 Write a unary metafunction add_const_ref that returns T if it…
pepero
  • 7,095
  • 7
  • 41
  • 72
3
votes
2 answers

Adding a class instance variable and attr_reader to Ruby class at runtime?

How do I add a class instance variable, the data for it and a attr_reader at runtime? class Module def additional_data member, data self.class.send(:define_method, member) { p "Added method #{member} to #{name}" } end end For…
Zabba
  • 64,285
  • 47
  • 179
  • 207
3
votes
0 answers

Groovy AST Transformation: Closure visibility

I would like to make an AST transformation which wraps method body with a closure. My problem is that this closure must access to that method parameters, but it seems that there is no visibility. My code is available on Github. Here is what I…
sinuhepop
  • 20,010
  • 17
  • 72
  • 107
3
votes
1 answer

Multiple template template paremeters for template class

Is it possible to pass two template classes into a template class? I am looking to create a class that holds two different std::tuple>. I am beginning to suspect that what I want to achieve can not be done, but I can not find anything…
3
votes
4 answers

Command line templating in Dockerfiles

I am trying to build a Dockerfile that builds my project for multiple base images (e.g., Ubuntu 17.10 for multiple architectures) I want to be able to write something like FROM {{ ARCH }}/ubuntu:17.10 ... And have it resolve at build time to…
ssb
  • 7,422
  • 10
  • 36
  • 61
3
votes
4 answers

How to get a templated typename as a string?

The following code prints out the string "T" not the actual typename when the templated function is called. Is there a way to get the real typename without adding anything to the types being templated? #define stringify(a) #a #define tostring(a)…
grokus
  • 18,046
  • 9
  • 29
  • 35
3
votes
1 answer

How to implement std::result_of with only c++98 features?

I wonder how can we implement a result_of template class to get the return type of a function. I know C++11 has std::result_of or decltype. But how the boost implement this feature in C++98 standard? I have tried to learn from source code, but I…
Liu Weibo
  • 434
  • 5
  • 16
3
votes
2 answers

Defining an Abstract model with a ForeignKey to another Abstract model

I'm trying to build two abstract classes called SurveyQuestionBase and SurveyResponseBase that will serve as templates to quickly define new concrete Models for implementing specific surveys on our website. The issue I am having is in enforcing that…
rtindru
  • 5,107
  • 9
  • 41
  • 59
3
votes
2 answers

If there is no distinct between read, compile and runtime in Lisp, can someone give me some intuitive examples?

As I read blog Revenge of the nerds, It says (in what made Lisp different section): The whole language there all the time. There is no real distinction between read-time, compile-time, and runtime. You can compile or run code while reading, read or…
Jiacai Liu
  • 2,623
  • 2
  • 22
  • 42
3
votes
3 answers

Is there a better way to get the public "properties" of a Ruby object?

Is there a better way to get the public "properties" of a Ruby object? def props self.public_methods.grep(/.=$/) - ["==","==="] end
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
3
votes
1 answer

How to dynamically create modules with functions

On compilation stage I can easily produce functions with: defmodule A1 do defmodule A2 do Enum.each %{m: 42}, fn {k, v} -> def unquote(k)(), do: unquote(v) end end end IO.puts A1.A2.m #⇒ 42 Also, I can produce modules with…
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
3
votes
7 answers

Are there real world applications that use metaprogramming?

We all know that MetaProgramming is a Concept of Code == Data (or programs that write programs). But are there any applications that use it & what are the advantages of using it? This Question can be closed but i didnt see any related questions.
Saif al Harthi
  • 2,948
  • 1
  • 21
  • 26
3
votes
1 answer

C++ partial template specialization syntax

for primary template: template class MyClass {... with template specialization, what is the difference between template class MyClass {... and template<> class MyClass {...
uray
  • 11,254
  • 13
  • 54
  • 74