title: C++ policy design with variable data
body: <p>There's quite a bit of info on this topic.  This is more of a design question, but I will give examples.  </p>
  
  <p>Let's say that I literally want to pass around a profile class, that dictates policies of a user.  </p>
  
  <pre><code>struct ApplicationAllowedPolicy
  {
  public:
      bool hasAccess() { return true; }
  }
  
  struct ApplicationProhibitedPolicy
  {
  public:
      bool hasAccess() { return false; }
  }
  
  template&lt;typename ApplicationPolicy&gt;
  class Profile : private ApplicationPolicy
  {
      bool hasAccess() { return ApplicationPolicy::access(); }
  }
  
  int main()
  {
      Profile&lt;ApplicationAllowedPolicy&gt; allowed;
      Profile&lt;ApplicationProhibitedPolicy&gt; prohibited;
  
      // do something with allowed &amp; prohibited
  }
  </code></pre>
  
  <p>The above is all fine and dandy, but let's assume there are a lot of policies that need to be read in.  5 Seems like a realistic real world number, although it could be more.  Then, let's assume that this profile will be applied to hundreds of instances, with the 5 policies varying greatly.  To boot, the policy behavior would only be known at run time (read from file, db, whatever).  This quickly becomes unscalable, unless I'm totally missing something.</p>
  
  <p>I thought of doing a non-type template class as a policy.</p>
  
  <pre><code>template&lt;int N&gt;
  struct ApplicationPolicy
  {
      int policy = N;
  };
  
  Profile&lt;ApplicationPolicy&lt;1&gt;&gt; allowed;
  Profile&lt;ApplicationPolicy&lt;0&gt;&gt; prohibited;
  </code></pre>
  
  <p>I think this would indeed work for my situation, but I'm wondering if this is missing the point of policy based design.  I'm having problems seeing the pros of this over just have Profile be a normal struct, and just set it's data members to true/false as needed.</p>
  
  <p>Thoughts?</p>