title: boost::interprocess scoped_allocator AND Containers of containers NOT in shared memory
body: <p>I have a similar question as before in <a href="https://stackoverflow.com/q/26217012/1358042">boost::interprocess Containers of containers NOT in shared memory</a> and <a href="https://stackoverflow.com/a/26281947/1358042">How to I create a boost interprocess vector of interprocess containers</a> but this time I like to use my class, which uses a scoped_allocator, also on the heap and shared memory.</p>
  
  <ul>
  <li>The solution to my <a href="https://stackoverflow.com/a/26225192/1358042">first question</a> was to use a template class with an allocator type  </li>
  <li>In my <a href="https://stackoverflow.com/a/26281947/1358042">second previous question</a> it turned out that using a scoped_allocator together with a container of containers within the shared memory makes live easier.</li>
  </ul>
  
  <p>Now I like to have both, is this possible?
  Attached a example with a working scoped_allocator but I have no idea how to template in this case the allocator of the class?</p>
  
  <p>Thanks in advance :-)</p>
  
  <p>Markus</p>
  
  <pre><code>#include &lt;boost/interprocess/managed_shared_memory.hpp&gt;
  #include &lt;boost/container/scoped_allocator.hpp&gt;
  #include &lt;boost/interprocess/allocators/allocator.hpp&gt;
  #include &lt;boost/interprocess/containers/vector.hpp&gt;
  #include &lt;boost/algorithm/string.hpp&gt;
  
  namespace bi = boost::interprocess;
  namespace bc = boost::container;
  
  typedef bi::managed_shared_memory::segment_manager                         segment_manager_t;
  typedef bc::scoped_allocator_adaptor&lt;bi::allocator&lt;void, segment_manager_t&gt; &gt;  void_allocator;
  
  class CheckList {
  typedef void_allocator::rebind&lt;double&gt;::other       double_allocator;
  typedef bc::vector&lt;double, double_allocator&gt;         double_vector;
  public:
      double_vector values;
  
      typedef void_allocator allocator_type;
  
      //Since void_allocator is convertible to any other allocator&lt;T&gt;, we can simplify
      //the initialization taking just one allocator for all inner containers.
      CheckList ( const allocator_type &amp;void_alloc )
          :  values ( void_alloc ) {}
  
      CheckList ( CheckList const&amp; other, const allocator_type &amp;void_alloc )
          :  values ( other.values, void_alloc ) {}
  
      friend std::ostream &amp;operator &lt;&lt; ( std::ostream &amp;os, const CheckList &amp;o ) {
          for ( size_t i = 0; i &lt; o.values.size(); i++ )  os &lt;&lt; (i&gt;0?", ":"") &lt;&lt; o.values[i];
          return os;
      }
  };
  
  class Lists {
  typedef void_allocator::rebind&lt;CheckList&gt;::other      checklist_allocator;
  typedef bc::vector&lt;CheckList, checklist_allocator&gt;    checklist_vector;
  
  public:
      Lists ( const void_allocator &amp;void_alloc )
          : checklists ( void_alloc )
      {}
      checklist_vector checklists;
  
      friend std::ostream &amp;operator &lt;&lt; ( std::ostream &amp;os, const Lists &amp;o ) {
          for ( size_t i = 0; i &lt; o.checklists.size(); i++ ) os &lt;&lt; o.checklists[i]  &lt;&lt; std::endl;
          return os;
      }
  };
  
  
  int main ( int argc, char **argv ) {
  
  
      if ( argc &gt; 1 &amp;&amp; (boost::iequals ( "clear", argv[1] ) || boost::iequals ( "c", argv[1] ) ) ) {
          std::cout &lt;&lt; "Remove shared memory" &lt;&lt; std::endl;
          bi::shared_memory_object::remove ( "MySharedMemory" );
      }
  
  
      //Create shared memory
      bi::managed_shared_memory segment ( bi::open_or_create,"MySharedMemory", 16*1024*1024 );
  
      //An allocator convertible to any allocator&lt;T, segment_manager_t&gt; type
      void_allocator alloc_inst ( segment.get_segment_manager() );
  
      Lists *lists = segment.find_or_construct&lt;Lists&gt; ( "Lists" ) ( alloc_inst );
      if ( lists-&gt;checklists.size() != 10 ) {
          std::cout &lt;&lt; "Create Data" &lt;&lt; std::endl;
          lists-&gt;checklists.resize ( 10 );
          for ( size_t i = 0; i &lt; lists-&gt;checklists.size(); i++ ) {
              lists-&gt;checklists[i].values.resize ( i+1 );
              for ( size_t j = 0; j &lt; lists-&gt;checklists[i].values.size(); j++ ) {
                  lists-&gt;checklists[i].values[j] = j;
              }
          }
      } else {
          std::cout &lt;&lt; "Data Exists" &lt;&lt; std::endl;
      }
      std::cout &lt;&lt; *lists &lt;&lt; std::endl;
  }
  </code></pre>