title: Is it possible to get hash values as compile-time constants?
body: <p>I thought I'd try selecting different options as strings by hashing them, but this doesn't work:</p>
  
  <pre><code>#include &lt;type_traits&gt;
  #include &lt;string&gt;
  
  inline void selectMenuOptionString(const std::string&amp; str)
  {
      switch (std::hash&lt;std::string&gt;()(str))
      {
      case std::hash&lt;std::string&gt;()(std::string("Selection one")) : break; 
          // Expression must have a constant value
      }
  }
  
  inline void selectMenuOptionString2(const std::string&amp; str)
  {
      size_t selectionOneHash = std::hash&lt;std::string&gt;()(std::string("Selection one"));
  
      switch (std::hash&lt;std::string&gt;()(str))
      {
      case selectionOneHash: // Expression must have a constant value 
                             // The variable of selectionOneHash cannot be used as a constant
      }
  
      constexpr size_t hash = std::hash&lt;int&gt;()(6); // Expression must have a constant value
  }
  </code></pre>
  
  <p>It seems I can't get hash values at compile time. From what I've read each different input should yield the same unique output every time, with a very low chance of collision. Given these properties couldn't the hash value be calculated at compile time? I don't know much at all about hashing, I usually use an unordered_map, but I wanted to try something new for learning's sake. </p>