title: Elegant way to force vector elements having same properties
body: <p>The title is a bit vague but I can't come up with a better wording, here's the deal:</p>
  
  <pre><code>class A
  {
  public:
    A();
    A( const PropertyB&amp; b );
    PropertyA GetPropertyA();
    PropertyB GetPropertyB();
    SetPropertyA( const PropertyA&amp; b );
    SetPropertyB( const PropertyB&amp; b );
    //assignment not allowed
  };
  </code></pre>
  
  <p>Suppose I want to use an std::vector&lt; A >, but, it only makes sense to have a vector of A if all it's elements have the same value for PropertyB. The current solutions is to supply a contrcutor-like method to create such array which guarantees all elements of the returned array have the same value for PropertyB, and a method that checks if that is the case:</p>
  
  <pre><code>Array MakeArray( size_t, const PropertyB&amp; );
  bool CheckIfArrayIsSane( const Array&amp; );
  </code></pre>
  
  <p>So users can still call SetPropertyB() on the elements, but have a utility to check it and bail out if someone did:</p>
  
  <pre><code>Array x( MakeArray( 3, someValue ) );
  x.SetPropertyA( aaa );             //should be allowed
  x.SetPropertyB( someOtherValue );  //should NOT be allowed
  //somewhat further in the program
  if( !CheckIfArrayIsSane( x ) )
    throw InsaneArrayExcpetion();
  </code></pre>
  
  <p>While this works, it's error-prone since it is hard to force this check everywhere and not forget it, and clutters the code with checks.</p>
  
  <p>Approcahes that do <em>not</em> work:</p>
  
  <ul>
  <li>Making SetPropertyB() private, and making MakeArray a friend function: then SetPropertyB() is not accessible anymore for users that simply want to use A without caring about the array.</li>
  <li>Wrapping std::vector&lt; A > in a seperate class and only returning const A&amp; references: this would mean the other setters like SetPropertyA() can also not be called, but users should be able to call them. It's only SetPropertyB() that should be disallowed.</li>
  </ul>
  
  <p>One more intrusive approach that would work but feels a bit unelegant, and needs extra functions to convert between the two etc:</p>
  
  <pre><code>class AWithFixedPropertyB
  {
  public:
    A( const PropertyB&amp; b );
    PropertyA GetPropertyA();
    PropertyB GetPropertyB();
    SetPropertyA( const PropertyA&amp; b );
  };
  
  class A : public AWithFixedPropertyB
  {
  public:
    //contrcutors etc
    SetPropertyB( const PropertyB&amp; b );
  };
  
  //ok, users cannot modify property B in this Array
  typedef std::vector&lt; AWithFixedPropertyB &gt; Array;
  </code></pre>
  
  <p>What would be the most elegant solution for this problem?</p>