title: Create bitmask based on a pattern as constexpr
body: <p>I would like to implement a template function which generates bitmasks in compile-time for integral types. These masks should be based on 8-bit patterns where the pattern will be repeated consecutively to fill the integer. The following example does exactly what I want but in run-time:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;type_traits&gt;
  #include &lt;cstring&gt;
  
  template&lt;typename Int&gt;
  typename std::enable_if&lt;std::is_integral&lt;Int&gt;::value, Int&gt;::type
  make_mask(unsigned char pattern) {
      Int output {};
      std::memset(&amp;output, pattern, sizeof(Int));
      return output;
  }
  
  int main() {
      auto mask = make_mask&lt;unsigned long&gt;(0xf0);
      std::cout &lt;&lt; "Bitmask: '" &lt;&lt; std::hex &lt;&lt; mask &lt;&lt; "'" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>The output of the code above is:</p>
  
  <pre><code>Bitmask: 'f0f0f0f0f0f0f0f0'
  </code></pre>
  
  <p>I know that the optimizer can eliminate the entire function call in the code above, but I'm looking for a <code>constexpr</code> solution with <a href="/questions/tagged/c%2b%2b14" class="post-tag" title="show questions tagged &#39;c++14&#39;" rel="tag">c++14</a> and optionally with <a href="/questions/tagged/c%2b%2b11" class="post-tag" title="show questions tagged &#39;c++11&#39;" rel="tag">c++11</a>.</p>