Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The concept comes entirely from the name <a href="http://en.wikipedia.org/wiki/Meta" rel="noreferrer">Meta-</a> means to abstract from the thing it is prefixed on.<br> In more 'conversational style' to do something with the thing rather than the thing itself.</p> <p>In this regard metaprogramming is essentially writing code, which writes (or causes to be written) more code.</p> <p>The C++ template system is meta programming since it doesn't simply do textual substitution (as the c preprocessor does) but has a (complex and inefficient) means of interacting with the code structure it parses to output code that is far more complex. In this regard the template preprocessing in C++ is Turing complete. This is not a <em>requirement</em> to say that something is metaprogramming but is almost certainly <em>sufficient</em> to be counted as such.</p> <p>Code generation tools which are parametrizable may be considered metaprogramming if their template logic is sufficiently complex.</p> <p>The closer a system gets to working with the abstract syntax tree that represents the language (as opposed to the textual form we represent it in) the more likely it is to be considered metaprogramming.</p> <p>From looking at the QT MetaObjects code I would not (from a cursory inspection) call it meta programming in the sense usually reserved for things like the C++ template system or Lisp macros. It appears to simply be a form of code generation which injects some functionality into existing classes at the compile stage (it can be viewed as a precursor to the sort of Aspect Oriented Programming style currently in vogue or the prototype based object systems in languages like JavaScripts</p> <p>As example of the sort of extreme lengths you can take this in C++ there is <a href="http://www.boost.org/doc/libs/1_39_0/libs/mpl/doc/index.html" rel="noreferrer">Boost MPL</a> whose <a href="http://www.boost.org/doc/libs/1_39_0/libs/mpl/doc/tutorial/tutorial-metafunctions.html" rel="noreferrer">tutorial</a> shows you how to get: </p> <p><a href="http://www.boost.org/doc/libs/1_39_0/libs/mpl/doc/tutorial/dimensional-analysis.html" rel="noreferrer">Dimensioned types</a> (Units of Measure)</p> <pre><code>quantity&lt;float,length&gt; l( 1.0f ); quantity&lt;float,mass&gt; m( 2.0f ); m = l; // compile-time type error </code></pre> <p><a href="http://www.boost.org/doc/libs/1_39_0/libs/mpl/doc/tutorial/higher-order.html" rel="noreferrer">Higher Order Metafunctions</a></p> <blockquote> <p>twice(f, x) := f(f(x))</p> </blockquote> <pre><code>template &lt;class F, class X&gt; struct twice : apply1&lt;F, typename apply1&lt;F,X&gt;::type&gt; {}; struct add_pointer_f { template &lt;class T&gt; struct apply : boost::add_pointer&lt;T&gt; {}; }; </code></pre> <blockquote> <p>Now we can use twice with add_pointer_f to build pointers-to-pointers:</p> </blockquote> <pre><code>BOOST_STATIC_ASSERT(( boost::is_same&lt; twice&lt;add_pointer_f, int&gt;::type , int** &gt;::value )); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload