Detecting instance method constexpr with SFINAE
<p>Let me first start off by noting the very similar question here: <a href="https://stackoverflow.com/questions/15232758/detecting-constexpr-with-sfinae">Detecting constexpr with SFINAE</a>. The difference is that in this question, the detection method works to detect a static method of a class.</p>

<p>I am trying to detect if something can be constexpr copy constructed. I'm quite close, here's what I've got:</p>

<pre><code>template &lt;class T&gt;
constexpr int return_int(T t) {  return 0; }

template &lt;class T&gt;
T&amp; unmove(T&amp;&amp; t) { return t; }

template &lt;class ... T&gt;
using void_t = void;

template &lt;class T, class = void&gt;
struct is_constexpr_copy_constructible : std::false_type {};

template &lt;class T&gt;
struct is_constexpr_copy_constructible&lt;T, void_t&lt;
                                              std::integral_constant&lt;int, 
                                                  return_int(unmove(T{}))
                                              &gt;
                                          &gt;&gt; : std::true_type {};
</code></pre>

<p>The logical progression of ideas in this solution is as follows:</p>

<ol>
<li>Only constant expression integers can be used for integer template parameters.</li>
<li>The result of a function call is only considered constexpr if the function is constexpr and all of its parameters are constexpr.</li>
<li>Passing something by value will entail making a copy.</li>
</ol>

<p>So I write the function <code>return_int</code> which gives me a constexpr integer iff a constexpr expression of type having a constexpr copy constructor is passed. <code>unmove</code> just ensures that the copy constructor rather than the move constructor is called.</p>

<p>The problem is that in order to get an expression in the first place, I have to create my type. I cannot use <code>declval</code> for this as would be standard in TMP, because this is not an unevaluated context; return_int will actually be evaluated at compile time to compute the type. So I am stuck with a meta-function that detects whether a type is constexpr copy constructible AND constexpr default constructible.</p>

<p>This isn't the end of the world per se as these things tend to overlap, but it's not ideal. Is there any way around this? Fundamentally it boils down to:</p>

<ol>
<li>I don't see any way to verify if something is constexpr in an unevaluated context.</li>
<li>In an evaluated context, I don't see any way to get an instance of the type I'm testing in order to try to make a copy without calling a constructor.</li>
</ol>

<p>Note that in the similar question I linked, this simply isn't an issue because it is checking static methods, and therefore just doesn't need an instance.</p>

<p>Help?</p>