Opened 7 years ago
Closed 7 years ago
#11993 closed Feature Requests (wontfix)
Add a default constructor to intrusive unordered_set and unordered_multiset
Reported by: | anonymous | Owned by: | Ion Gaztañaga |
---|---|---|---|
Milestone: | To Be Determined | Component: | intrusive |
Version: | Boost 1.60.0 | Severity: | Problem |
Keywords: | Cc: |
Description
All the constructors of intrusive unordered_set
and unordered_multiset
require a bucket_traits
. It is currently not possible to instantiate an unordered_set
without having allocated some buckets.
It would be useful to add a default constructor to unordered_set
and unordered_multiset
. That would allow to create hash containers that allocate buckets lazily at the first element insertion.
That would also allow this kind of pattern:
unordered_set<MyType, ...> v; if (some_condition) { v = some_collection(); } else { v = some_other_collection(); }
Bonus if the const methods of a default-constructed unordered_set/unordered_multiset can be called and behave as an empty collection (in particular empty
, size
, begin
/cbegin
, end
/cend
, count
, find
and equal_range
).
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.
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).