<div dir="ltr"><div><div><div><div>Hi,<br><br></div><br>I started to think on a new kind of templating system in c++. Idea come from the AngularJS.com templating framework.<br><br></div>Here is a link for a longer description:<br>
<a href="https://github.com/hun-nemethpeter/cpp-reflector-mini/blob/master/Proposal.md">https://github.com/hun-nemethpeter/cpp-reflector-mini/blob/master/Proposal.md</a><br><br></div>here is an example:<br><br><pre><span class="">// template part</span>
<span class="">template</span><span class=""><</span><span class="">typename</span> <span class="">T</span><span class="">></span> <span class="">[[</span><span class="">meta</span><span class="">::</span><span class="">driver</span><span class="">=</span><span class="">"EnumDriver(meta::class<T>) driver"</span><span class="">]]</span>
<span class="">// EnumDriver is a constexpr class, that gets a compiler generated AST node</span>
<span class="">// in constructor parameter, through meta::class<T> in a type safe manner.</span>
<span class="">// (ex. enum declaration generates const EnumDecl*,</span>
<span class="">// and a class declaration generates const CXXRecordDecl*).</span>
<span class="">// driver instance name will be "driver", this is a normal C++ syntax</span>
<span class="">// members and methods of this object can be accessed with the following syntax:</span>
<span class="">// $driver.member$ or $driver.method(param1, param2, ...)$</span>
<span class="">void</span> <span class="">Json</span><span class="">::</span><span class="">readFrom</span><span class="">(</span><span class="">boost</span><span class="">::</span><span class="">optional</span><span class=""><</span><span class="">$</span><span class="">driver</span><span class="">.</span><span class="">enumName</span><span class="">$</span><span class="">>&</span> <span class="">obj</span><span class="">,</span> <span class="">const</span> <span class="">std</span><span class="">::</span><span class="">string</span><span class="">&</span> <span class="">data</span><span class="">)</span>
<span class="">{</span>
<span class="">folly</span><span class="">::</span><span class="">fbstring</span> <span class="">jsonVal</span> <span class="">=</span> <span class="">folly</span><span class="">::</span><span class="">parseJson</span><span class="">(</span><span class="">data</span><span class="">).</span><span class="">asString</span><span class="">();</span>
<span class="">llvm</span><span class="">::</span><span class="">StringRef</span> <span class="">decoded</span><span class="">(</span><span class="">jsonVal</span><span class="">.</span><span class="">c_str</span><span class="">(),</span> <span class="">jsonVal</span><span class="">.</span><span class="">length</span><span class="">());</span>
<span class="">obj</span> <span class="">=</span> <span class="">llvm</span><span class="">::</span><span class="">StringSwitch</span><span class=""><</span><span class="">$</span><span class="">driver</span><span class="">.</span><span class="">enumName</span><span class="">$</span><span class="">></span><span class="">(</span><span class="">decoded</span><span class="">)</span>
<span class="">// controlling directive meta::for, with the syntax of range base for</span>
<span class="">// enumValueName will be a local variable of a CODT</span>
<span class="">[[</span><span class="">meta</span><span class="">::</span><span class="">for</span><span class="">=</span><span class="">"(enumValueName:driver.enumValueNames)"</span><span class="">]]</span>
<span class="">.</span><span class="">Case</span><span class="">(</span><span class="">$</span><span class="">enumValueName</span><span class="">.</span><span class="">asStr</span><span class="">()</span><span class="">$</span><span class="">,</span> <span class="">$</span><span class="">enumValueName</span><span class="">$</span><span class="">)</span>
<span class="">;</span>
<span class="">}</span>
<span class="">// driver part</span>
<span class="">class</span> <span class="">EnumDriver</span>
<span class="">{</span>
<span class="">const</span> <span class="">EnumDecl</span><span class="">*</span> <span class="">enumDecl</span><span class="">;</span>
<span class="">public:</span>
<span class="">// used in [[std::driver="EnumDriver(meta::class<EVote>) driver"]]</span>
<span class="">constexpr</span> <span class="">EnumDriver</span><span class="">(</span><span class="">const</span> <span class="">EnumDecl</span><span class="">*</span> <span class="">enumDecl</span><span class="">)</span>
<span class="">:</span> <span class="">enumDecl</span><span class="">(</span><span class="">enumDecl</span><span class="">)</span>
<span class="">{</span>
<span class="">std</span><span class="">::</span><span class="">string</span> <span class="">enumName</span> <span class="">=</span> <span class="">enumDecl</span><span class="">-></span><span class="">getNameAsString</span><span class="">();</span>
<span class="">for</span> <span class="">(</span><span class="">auto</span> <span class="">it</span> <span class="">=</span> <span class="">enumDecl</span><span class="">-></span><span class="">enumerator_begin</span><span class="">();</span> <span class="">it</span> <span class="">!=</span> <span class="">enumDecl</span><span class="">-></span><span class="">enumerator_end</span><span class="">();</span> <span class="">it</span><span class="">++</span><span class="">)</span>
<span class="">enumNames</span><span class="">.</span><span class="">push_back</span><span class="">((</span><span class="">*</span><span class="">it</span><span class="">)</span><span class="">-></span><span class="">getName</span><span class="">().</span><span class="">data</span><span class="">());</span>
<span class="">}</span>
<span class="">// used in [[meta::for(enumValueName:driver.enumValueNames)]]</span>
<span class="">// meta::vector is a constexpr vector</span>
<span class="">meta</span><span class="">::</span><span class="">vector</span><span class=""><</span><span class="">meta</span><span class="">::</span><span class="">id_string</span><span class="">></span> <span class="">enumValueNames</span><span class="">;</span>
<span class="">// used in $driver.enumName$</span>
<span class="">// meta::id_string is a constexpr string that contains only valid C++ identifier</span>
<span class="">// it has an asStr() that gives back a stringified string, so between "" signes</span>
<span class="">meta</span><span class="">::</span><span class="">id_string</span> <span class="">enumName</span><span class="">;</span>
<span class="">};</span></pre><br></div>Is there any chance that I'm able to implement it in some day? How much effort implementing such a feature?<br><div><br><br>Peter<br></div></div>