title: C++ using templates to create methods for specific enum values
body: <p>I'd like to write one method and have the compiler generate multiple methods based on specific enum values.</p>
  
  <p>Below I have some isValid*() methods. They all have the same structure as you can see, so I would like to combine them into one method. Maybe templates would be useful for this? Maybe not.</p>
  
  <p>Something like this pseudo code (Edited for clarity):</p>
  
  <pre><code>enum Dir { East, West, South, North }
  
  bool isValidFromWest(const Dir dir)
  {
    switch (dir)
    {
      case West:    return foo(dir);
      case East:    return true;
      case North:   return false;
      case South:   return false;
    }
  }
  
  bool isValidFromEast(const Dir dir)
  {
    switch (dir)
    {
      case East:    return foo(dir);
      case West:    return true;
      case North:   return false;
      case South:   return false;
    }
  }
  
  bool isValidFromSouth(const Dir dir)
  {
    switch (dir)
    {
      case South:   return foo(dir);
      case North:   return true;
      case West:    return false;
      case East:    return false;
    }
  }
  
  bool isValidFromNorth(const Dir dir)
  {
    switch (dir)
    {
      case North:   return foo(dir);
      case South:   return true;
      case West:    return false;
      case East:    return false;
    }
  }
  </code></pre>
  
  <p>Is there a compile time way to combine these methods into a single method that maintains performance and does not sacrifice too much code clarity.</p>