title: How to check at compile time that an expression is illegal?
body: <p>I have a problem in my application where I'd like to assert that a function application would be rejected by the compiler. Is there a way to check this with SFINAE?</p>
  
  <p>For example, assume that I'd like to validate that <code>std::transform</code> to a <code>const</code> range is illegal. Here's what I have so far:</p>
  
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;functional&gt;
  #include &lt;iostream&gt;
  
  namespace ns
  {
  
  using std::transform;
  
  template&lt;typename Iterator1, typename Iterator2, typename UnaryFunction&gt;
    struct valid_transform
  {
    static Iterator1 first1, last1;
    static Iterator2 first2;
    static UnaryFunction f;
  
    typedef Iterator2                   yes_type;
    typedef struct {yes_type array[2];} no_type;
  
    static no_type transform(...);
  
    static bool const value = sizeof(transform(first1, last1, first2, f)) == sizeof(yes_type);
  };
  
  }
  
  int main()
  {
    typedef int *iter1;
    typedef const int *iter2;
    typedef std::negate&lt;int&gt; func;
  
    std::cout &lt;&lt; "valid transform compiles: " &lt;&lt; ns::valid_transform&lt;iter1,iter1,func&gt;::value &lt;&lt; std::endl;
  
    std::cout &lt;&lt; "invalid transform compiles: " &lt;&lt; ns::valid_transform&lt;iter1,iter2,func&gt;::value &lt;&lt; std::endl;
  
    return 0;
  }
  </code></pre>
  
  <p>Unfortunately, my trait rejects both the legal and the illegal cases. The result:</p>
  
  <pre><code>$ g++ valid_transform.cpp 
  $ ./a.out 
  valid transform compiles: 0
  invalid transform compiles: 0
  </code></pre>