Boost C++ Libraries: Ticket #11993: Add a default constructor to intrusive unordered_set and unordered_multiset https://svn.boost.org/trac10/ticket/11993 <p> All the constructors of intrusive <code>unordered_set</code> and <code>unordered_multiset</code> require a <code>bucket_traits</code>. It is currently not possible to instantiate an <code>unordered_set</code> without having allocated some buckets. </p> <p> It would be useful to add a default constructor to <code>unordered_set</code> and <code>unordered_multiset</code>. That would allow to create hash containers that allocate buckets lazily at the first element insertion. </p> <p> That would also allow this kind of pattern: </p> <div class="wiki-code"><div class="code"><pre><span class="n">unordered_set</span><span class="o">&lt;</span><span class="n">MyType</span><span class="p">,</span> <span class="p">...</span><span class="o">&gt;</span> <span class="n">v</span><span class="p">;</span> <span class="k">if</span> <span class="p">(</span><span class="n">some_condition</span><span class="p">)</span> <span class="p">{</span> <span class="n">v</span> <span class="o">=</span> <span class="n">some_collection</span><span class="p">();</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="n">v</span> <span class="o">=</span> <span class="n">some_other_collection</span><span class="p">();</span> <span class="p">}</span> </pre></div></div><p> Bonus if the const methods of a default-constructed unordered_set/unordered_multiset can be called and behave as an empty collection (in particular <code>empty</code>, <code>size</code>, <code>begin</code>/<code>cbegin</code>, <code>end</code>/<code>cend</code>, <code>count</code>, <code>find</code> and <code>equal_range</code>). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11993 Trac 1.4.3 Ion Gaztañaga Tue, 01 Mar 2016 21:18:12 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11993#comment:1 https://svn.boost.org/trac10/ticket/11993#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> Allowing a intrusive container without buckets, apart from pessimizing functions that must check for this special condition, makes all other insertion functions invalid (the intrusive container can't allocate memory so all functions should have a precondition saying that a bucket must have been introduced). This precondition-free behaviour was a design decision. </p> <p> You can always use a single bucket for the "nearly default constructed" type, in case you want to minimize memory waste (a single bucket requires just the storage of a pointer). </p> Ticket