Specialize if value of a variable is known/unknown at compile time
<p>How to specialize a template function for the case that the value of one of its argument is known/unknown during compile time (before actually compile and run the program)?</p>

<p>I can't figure out how yet.</p>

<p>idea 1:</p>

<pre><code>#include &lt;type_traits&gt;
#include &lt;iostream&gt;
int main(void){
    int a; //value of a is not known at compile time
    bool b = (a == a); //value of b is known at compile time.
    std::is_assignable&lt; constexpr bool, bool &gt;::value
}
//g++ magic.cpp -std=c++14
//error: wrong number of template arguments (1, should be 2)
// std::is_assignable&lt; constexpr bool, bool &gt;::value
</code></pre>

<p>Idea 2:</p>

<pre><code>#include &lt;type_traits&gt;
#include &lt;iostream&gt;
int main(void){
    const int a=1;
    int b = (a == a);
    std::cout &lt;&lt;  __builtin_constant_p (a)  &lt;&lt; std::endl;
    std::cout &lt;&lt;  __builtin_constant_p (b)  &lt;&lt; std::endl;
}
//prints 0 and 0.
</code></pre>