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
3 answers

Common types in two TypeSets / Tuples

I have two tuples -- TypeSets modeled as tuples, and thus guaranteed to contain each type at maximum once in their parameter packs, to be exact -- (say A = std::tuple and B = std::tuple), and I wish to obtain a typedef that…
3
votes
2 answers

Reimplemented Constructor[Symbol.hasInstance] but it still won't be called

So, I was writing some example code implementing another function for Constructor[Symbol.hasInstance] and I noticed my new implementation just won't get called. The script below is what I expected to happen: function Pirate(name) { this.name =…
lucasfcosta
  • 285
  • 2
  • 10
3
votes
4 answers

Overloading members from template class on bool value

I'm trying to avoid concepts on the master branch of my projects, so I need some kind of alternative with type_trait: I need a class whom some few functions will change depending on the bool value. Someone already suggest me to split my class, but…
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
3
votes
2 answers

Metaprogramming C++, max between two templates parameters

I haven't been doing this for a while. I basically have a class template class MyInteger { //code }; And specifically I'd like to implement something like (as a method) template MyInteger
user8469759
  • 2,522
  • 6
  • 26
  • 50
3
votes
1 answer

Iterator adaptor that calls a member function when dereferenced

I am trying to write an iterator adaptor that should call a member function (or access a member of the object) each time it is dereferenced. Here is an example of such an API: vector> ps = {{1,"a"}, {2,"b"}, {3,"c"}}; // Pairs that…
fuji
  • 1,173
  • 1
  • 10
  • 27
3
votes
2 answers

Python 3 super and metaprogramming

I'm trying to duplicate and then modify a class programmatically but I'm running into problems with python 3's magic super for example the following class Base(): def __init__(self): print("Base init") class Orginal(Base): def…
3
votes
2 answers

Facilities for generating Haskell types in Haskell ("second order Haskell")?

Apologies in advance if this question is a bit vague. It's the result of some weekend daydreaming. With Haskell's wonderful type system, it's delightfully pleasing to express mathematical (especially algebraic) structure as typeclasses. I mean, just…
gspr
  • 11,144
  • 3
  • 41
  • 74
3
votes
3 answers

User-defined literals (Extended literals) of C++11... which compilers support it?

In another thread I introduced some techniques we would use for Model-Driven-Development in C++ once C++11 features, in particular user-defined literals, are available. I just revised the plans for GCC 4.5 and even 4.6 and it shows that this…
Diego Sevilla
  • 28,636
  • 4
  • 59
  • 87
3
votes
4 answers

C++ define a class member type according to its template

In our code we have the following class: template class myClass { typedef std::list> MyList; typedef std::map MyMap MyList mList; MyMap mMap; } class A is metaprogrammed…
user7036306
3
votes
3 answers

Functional C# - using or returning Action's

Browsing the net for better fault handling in C#, I've com across the following to implementation strategies. The first one is natural to me, while the other implementation I'm not certain what its advantages are? 1) static void Fault(Action…
Carlo V. Dango
  • 13,322
  • 16
  • 71
  • 114
3
votes
2 answers

SFINAE C++ method check

I'm trying to wrap my head around SFINAE. We're using it to check whether a class has a method called "Passengers". With some online examples, we constructed the following template classes. #ifndef TYPECHECK #define TYPECHECK #include…
Benjamin Larsen
  • 345
  • 2
  • 15
3
votes
2 answers

Why is Elixir Logger composed of Macros?

Had to use Logger in one of my applications today, and remembered that I needed to call require Logger first. So I decided to look at the Logger source code to see why debug, info, error, etc. are macros and not simple functions. From the code, the…
Sheharyar
  • 73,588
  • 21
  • 168
  • 215
3
votes
2 answers

Turning boost::tuples::cons<...> back into the corresponding boost::tuple<...>

For a little library project I'm using boost::tuple. Right now, I'm facing the problem of turning a "cons list" I operated on via metaprogramming back to a boost::tuple<...> type. The "dirty" solution would be to provide lots of partial…
sellibitze
  • 27,611
  • 3
  • 75
  • 95
3
votes
1 answer

RemoteChannel in a Macro is Stalling

I am trying to find out how to proper way to use RemoteChannel inside of a macro. In a function or the REPL, the following code works: addprocs(3) r = RemoteChannel(3) @spawnat(3,put!(r,10)) fetch(r) # Gives 10 However, if I put that same stuff in…
Chris Rackauckas
  • 18,645
  • 3
  • 50
  • 81
3
votes
3 answers

Turing machine: But why use template metaprogramming?

I am a final year engineering student. Me and my friends have decided that our final year project would be "Simulation of Turing Machine using Template Metaprogramming". I understand what "Turing Machine" and "Template Metaprogramming" are but my…
1 2 3
99
100