title: What is a common idiom to abstract cross-platform implementations?
body: <p>I am a writing a program which aims to be cross-platform; as such, it will support multiple implementations of certain operations. My first idea was to write a hierarchy of classes, with a common interface, maybe an abstract factory for each platform.</p>
  
  <pre><code>class Operation {
      DoOperation() = 0;
  }
  
  class OperationPlatform1 : public Operation {
      DoOperation();
  }
  
  class OperationPlatform2 : public Operation {
      DoOperation();
  }
  
  #ifdef USING_PLATFORM1
      Operation *op = new OperationPlatform1;
  #endif
  </code></pre>
  
  <p>I realized, however, that the implementation that will be used is known at compile-time. I tried to think how I could implement this using static polymorphism, after which I realized that I could also write something along these lines:</p>
  
  <pre><code>class OperationPlatform1 {
      DoOperation();
  }
  
  class OperationPlatform2 {
      DoOperation();
  }
  
  #ifdef USING_PLATFORM1
  typedef OperationPlatform1 Operation;
  #endif
  
  Operation op;
  </code></pre>
  
  <p>What is a good way to abstract multiple implementations, of which only one will be selected at compile-time? I am interested in performance as well, so I would like to not use virtual methods unless I have to.</p>