title: In Qt/GCC/C++; How to create a wrapper which both captures an argument expression text, and returns/casts the argument's explicit type?
body: <h1>Backstory (You can skip)</h1>
  <p>In trying to form the question as best I could, I was informed that the second set of parentheses for a <code>#define</code> macro is not a <code>return</code> like I thought it was, but actually a <code>cast</code>. To that, as far as I know; the only way to capture the expression text is by using the <code>#define</code> macro. The tricky part, perhaps impossible, is to capture the explicit <code>type</code>'s text, but what do I know?</p>
  <p>Also; the reason I specified this to Qt and not just C++/gcc, is that I figure that a solution might involve a class like <code>QVariant</code> which adds some polymorphism, however this is not ideal as it is difficult to distinguish between some various basic types, like <code>int</code> vs <code>bool</code>.</p>
  <h1>What I am hoping to achieve</h1>
  <p>Basically, I want a wrapper, I am guessing a macro, which will log the nested expression text, its value, and return its exact nested's type (no implicit conversions).</p>
  <p>For example:</p>
  <pre><code>/* Basic Definitions */
  // log() could be overloaded or use different namespaces if need be
  // and have preproccessor directives choose the appropriate one,
  // although I dont suspect that is possible.
  QVariant log(QString expression, QVariant value, QString type); 
  
  // TYPE is placeholder code. Normally I specify a real type like &quot;bool&quot;
  // I am hoping TYPE can represent the captured type text
  // #EXPR returns the text of the expression, in case you didnt know
  #define LOG(EXPR)(TYPE)(log(#EXPR, EXPR, TYPE));
  </code></pre>
  <p>In this sample code:</p>
  <pre><code>/* Sample Code */
  QString path;
  if (LOG(path.isEmpty())) {
      path = LOG(QDir::currentPath());
  }
  </code></pre>
  <p>The wrapper <code>LOG</code> should log the following:</p>
  <pre><code>Expression: &quot;path.isEmpty()&quot; Value: &quot;True&quot; Type: &quot;bool&quot;
  Expression: &quot;QDir::currentPath()&quot; Value: &quot;/home/akiva/Programming/&quot; Type: &quot;QString&quot;
  </code></pre>
  <p>Id like to see if I could achieve this <strong>without</strong> having to resort to multiple macro namespaces, like this:</p>
  <pre><code>/* Bad solution because I dont want to have to specify LOG_bool &amp; LOG_QString */
  QString path;
  if (LOG_bool(path.isEmpty())) {
      path = LOG_QString(QDir::currentPath());
  }
  </code></pre>
  <p>and I figure one possible solution would reveal itself if I could capture the text of the type, but I am open to all solutions, be it Macros, Templates, Functions or what have you.</p>
  <p>My minimum requirements are:</p>
  <ul>
  <li>Needs to capture the expression text. (I know how to do that with macros)</li>
  <li>Only require one wrapper namespace, because I dont want to accidentally use the wrong wrapper corrupting my logs or which may cause an implicit conversion, thus potentially changing the intended behaviour of the wrapped expression.</li>
  <li>The wrapper must return/cast the exact type of the nested expression, or in other words, not affect the exact intended behaviour of the nested expression.</li>
  </ul>
  <p>Being able to actually log the type, like <code>Type: &quot;bool&quot;</code> &amp; <code>Type: &quot;QString&quot;</code> would be nice, but is not required.</p>
  <p>I hope this all makes sense. Thanks.</p>