title: c++11 class member array size constexpr forward declaration
body: <p>I want to exclude some headers from my include chain after having used them. From what I know there is no exclude "header.h" in c++11.</p>
  
  <p>Pseudo Code Wishful thinking:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "the_bad_header.h" //long includechain with later unused declarations
  class bulky { ... };
  constexpr std::size_t bulkysize = sizeof(bulky);
  forget everything included and class bulky and remember only bulkysize
  </code></pre>
  
  <p>My example where the problem becomes evident follows. Please don't argue this is not a serious problem. The Example is broken down to show the minimal abstract language usage. I will describe the old fashioned solutions and their disadvantages too.</p>
  
  <h2>Old style solution</h2>
  
  <p>justanotherheader.h:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class bulkywrap
  {
  public:
      bulkywrap();
  protected:
      friend class bulkywrap_pImpl;
      bulkywrap_pImpl *const pImpl; //opaque pointer, private implementation
  };
  </code></pre>
  
  <p>justanothercppunit.cpp:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "justanotherheader.h"
  #include "boost/lotsofheaders.hpp"
  //#include more and more headers of highly complex libraries so adding millions of known types and other identifiers, macros, and so on
  
  class bulkywrap_pImpl
  {
      //lots of members of types used from the other libraries
  };
  
  bulkywrap::bulkywrap()
  : pImpl( new bulkywrap_pImpl() )
  {}
  </code></pre>
  
  <hr>
  
  <h2>My current Solution</h2>
  
  <p>justanotherheader.h:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "stdint.h" // this is the only header I like to use, but also unnecessary.
  #define UNKNOWNSIZE 12345
  class bulkywrap
  {
  public:
      bulkywrap();
  protected:
      friend class bulkywrap_pImpl;
      bulkywrap_pImpl *const pImpl; //opaque pointer, private implementation
      uint8_t pImpl_Placement[UNKNOWNSIZE]; //placement new for pImpl
  };
  </code></pre>
  
  <p>justanothercppunit.cpp:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "justanotherheader.h"
  #include "boost/lotsofheaders.hpp"
  //#include more and more headers of highly complex libraries so adding millions of known types and other identifiers, macros, and so on
  
  class bulkywrap_pImpl
  {
      //lots of members of types used from the other libraries
  };
  
  bulkywrap::bulkywrap()
  : pImpl( new(this-&gt;pImpl_Placement) bulkywrap_pImpl() ) //using this here is safe
  {}
  </code></pre>
  
  <p>So, the code above is working. The advantages are: hiding complexity and having no runtime dynamic memory indirections. Huh? I mean, the placement new allows the whole object to be put on stack and all member addresses are known at compile time. My attempt is to have best performance while using interface design of opaque pointer.</p>
  
  <p>If you think: "this performance advantage is not worth the thinking effort." then please leave that question.</p>
  
  <hr>
  
  <h2>My expected Solution</h2>
  
  <p>justanotherheader.h:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "stdint.h" // this is the only header I like to use, but also unnecessary.
  
  constexpr std::size_t get_bulkywrap_pImpl_Size( void ); //constexpr function forward declaration
  extern constexpr std::size_t bulkywrap_pImpl_Size; //constexpr literal forward declaration with external initialization
  
  class bulkywrap
  {
  public:
      bulkywrap();
  protected:
      friend class bulkywrap_pImpl;
      bulkywrap_pImpl *const pImpl; //opaque pointer, private implementation
      uint8_t pImpl_Placement[get_bulkywrap_pImpl_Size()]; //undefined constexpr used
      uint8_t pImpl_Placement[bulkywrap_pImpl_Size]; //alternative to above. undefined constexpr used
  };
  </code></pre>
  
  <p>justanothercppunit.cpp:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "justanotherheader.h"
  #include "boost/lotsofheaders.hpp"
  //#include more and more headers of highly complex libraries so adding millions of known types and other identifiers, macros, and so on
  
  class bulkywrap_pImpl
  {
      //lots of members of types used from the other libraries
  };
  
  constexpr std::size_t get_bulkywrap_pImpl_Size( void )
  {
      return sizeof(bulkywrap_pImpl);
  }
  constexpr std::size_t bulkywrap_pImpl_Size = sizeof(bulkywrap_pImpl);
  
  bulkywrap::bulkywrap()
  : pImpl( new(this-&gt;pImpl_Placement) bulkywrap_pImpl() ) //using this here is safe
  {}
  </code></pre>
  
  <p>In my current solution I need to verify the sizeof(bulkywrap_pImpl) and adjusting UNKNOWNSIZE manually.
  I think it is currently not possible to get any information from a compilationunit to others. I know this is typically intended by good reason, but this limits the possibilities of c++11.</p>
  
  <p>I want to point out:</p>
  
  <p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf" rel="nofollow">jtc1 sc22 wg21 paper n3337</a></p>
  
  <p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3308.pdf" rel="nofollow">jtc1 sc22 wg21 paper n3308</a></p>
  
  <p>Please help me to find information weather and why the standard does not allow this.</p>
  
  <p>But furthermore I would like to find a solution of how to export some literal constant during compiliation time out of a compileunit into another compileunit. It's just a literal, so all statements and expressions are not affected by it. Thus compilation does not depend where the size of the array comes from.</p>
  
  <p>My suggestion results in some work for the ISO-jtc1-sc22-wg21 and the compiler developers, but I don't see any relevant difference between template and constexpr since every definition must appear in the same translationunit. This makes modular programming and clean interfaces bogus.</p>
  
  <p>And no: I don't want to use preprocessor macros, dynamic new or virtual member functions. Of importance is maximal const-correctness, since the size of the class is const.</p>
  
  <p><strong>Please help</strong></p>