Created on 2012-10-04.00:00:00 last changed 131 months ago
Proposed resolution:
This wording is relative to N3376.
The more general criterion for performing the suggested transformation was: Any type with an initializer-list constructor that also has an explicit default constructor.
Change class template basic_string synopsis, [basic.string] p5 as indicated:
basic_string() : basic_string(Allocator()) { } explicit basic_string(const Allocator& a= Allocator());
Change [string.cons] before p1 as indicated:
explicit basic_string(const Allocator& a= Allocator());
Change class template deque synopsis, [deque.overview] p2 as indicated:
deque() : deque(Allocator()) { } explicit deque(const Allocator&= Allocator());
Change [deque.cons] before p1 as indicated:
explicit deque(const Allocator&= Allocator());
Change class template forward_list synopsis, [forwardlist.overview] p3 as indicated:
forward_list() : forward_list(Allocator()) { } explicit forward_list(const Allocator&= Allocator());
Change [forwardlist.cons] before p1 as indicated:
explicit forward_list(const Allocator&= Allocator());
Change class template list synopsis, [list.overview] p2 as indicated:
list() : list(Allocator()) { } explicit list(const Allocator&= Allocator());
Change [list.cons] before p1 as indicated:
explicit list(const Allocator&= Allocator());
Change class template vector synopsis, [vector.overview] p2 as indicated:
vector() : vector(Allocator()) { } explicit vector(const Allocator&= Allocator());
Change [vector.cons] before p1 as indicated:
explicit vector(const Allocator&= Allocator());
Change class template specialization vector<bool> synopsis, [vector.bool] p1 as indicated:
vector() : vector(Allocator()) { } explicit vector(const Allocator&= Allocator());
Change class template map synopsis, [map.overview] p2 as indicated:
map() : map(Compare()) { } explicit map(const Compare& comp= Compare(), const Allocator& = Allocator());
Change [map.cons] before p1 as indicated:
explicit map(const Compare& comp= Compare(), const Allocator& = Allocator());
Change class template multimap synopsis, [multimap.overview] p2 as indicated:
multimap() : multimap(Compare()) { } explicit multimap(const Compare& comp= Compare(), const Allocator& = Allocator());
Change [multimap.cons] before p1 as indicated:
explicit multimap(const Compare& comp= Compare(), const Allocator& = Allocator());
Change class template set synopsis, [set.overview] p2 as indicated:
set() : set(Compare()) { } explicit set(const Compare& comp= Compare(), const Allocator& = Allocator());
Change [set.cons] before p1 as indicated:
explicit set(const Compare& comp= Compare(), const Allocator& = Allocator());
Change class template multiset synopsis, [multiset.overview] p2 as indicated:
multiset() : multiset(Compare()) { } explicit multiset(const Compare& comp= Compare(), const Allocator& = Allocator());
Change [multiset.cons] before p1 as indicated:
explicit multiset(const Compare& comp= Compare(), const Allocator& = Allocator());
Change class template unordered_map synopsis, [unord.map.overview] p3 as indicated:
unordered_map(); explicit unordered_map(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());
Change [unord.map.cnstr] before p1 as indicated:
unordered_map() : unordered_map(size_type(see below)) { } explicit unordered_map(size_type n-1- Effects: Constructs an empty= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());unordered_map
using the specified hash function, key equality func-
tion, and allocator, and using at least n buckets.If n is not provided,For the default constructor
the number of buckets is implementation-defined.max_load_factor()
returns 1.0.
Change class template unordered_multimap synopsis, [unord.multimap.overview] p3 as indicated:
unordered_multimap(); explicit unordered_multimap(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());
Change [unord.multimap.cnstr] before p1 as indicated:
unordered_multimap() : unordered_multimap(size_type(see below)) { } explicit unordered_multimap(size_type n-1- Effects: Constructs an empty= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());unordered_multimap
using the specified hash function, key equality
function, and allocator, and using at least n buckets.If n is not provided,For the default constructor
the number of buckets is implementation-defined.max_load_factor()
returns 1.0.
Change class template unordered_set synopsis, [unord.set.overview] p3 as indicated:
unordered_set(); explicit unordered_set(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());
Change [unord.set.cnstr] before p1 as indicated:
unordered_set() : unordered_set(size_type(see below)) { } explicit unordered_set(size_type n-1- Effects: Constructs an empty= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());unordered_set
using the specified hash function, key equality func-
tion, and allocator, and using at least n buckets.If n is not provided,For the default constructor
the number of buckets is implementation-defined.max_load_factor()
returns 1.0.
Change class template unordered_multiset synopsis, [unord.multiset.overview] p3 as indicated:
unordered_multiset(); explicit unordered_multiset(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());
Change [unord.multiset.cnstr] before p1 as indicated:
unordered_multiset() : unordered_multiset(size_type(see below)) { } explicit unordered_multiset(size_type n-1- Effects: Constructs an empty= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());unordered_multiset
using the specified hash function, key equality
function, and allocator, and using at least n buckets.If n is not provided,For the default constructor
the number of buckets is implementation-defined.max_load_factor()
returns 1.0.
[ Issaquah 2014-02-11: Move to Immediate after final review ]
[ 2014-02-13, Issaquah, Jonathan revises wording ]
Previous resolution from Daniel [SUPERSEDED]:
This wording is relative to N3376.
The more general criterion for performing the suggested transformation was: Any type with an initializer-list constructor that also has an explicit default constructor.
Change class template basic_string synopsis, [basic.string] p5 as indicated:
basic_string() : basic_string(Allocator()) {} explicit basic_string(const Allocator& a= Allocator());Change [string.cons] before p1 as indicated:
explicit basic_string(const Allocator& a= Allocator());Change class template deque synopsis, [deque.overview] p2 as indicated:
deque() : deque(Allocator()) {} explicit deque(const Allocator&= Allocator());Change [deque.cons] before p1 as indicated:
explicit deque(const Allocator&= Allocator());Change class template forward_list synopsis, [forwardlist.overview] p3 as indicated:
forward_list() : forward_list(Allocator()) {} explicit forward_list(const Allocator&= Allocator());Change [forwardlist.cons] before p1 as indicated:
explicit forward_list(const Allocator&= Allocator());Change class template list synopsis, [list.overview] p2 as indicated:
list() : list(Allocator()) {} explicit list(const Allocator&= Allocator());Change [list.cons] before p1 as indicated:
explicit list(const Allocator&= Allocator());Change class template vector synopsis, [vector.overview] p2 as indicated:
vector() : vector(Allocator()) {} explicit vector(const Allocator&= Allocator());Change [vector.cons] before p1 as indicated:
explicit vector(const Allocator&= Allocator());Change class template specialization vector<bool> synopsis, [vector.bool] p1 as indicated:
vector() : vector(Allocator()) {} explicit vector(const Allocator&= Allocator());Change class template map synopsis, [map.overview] p2 as indicated:
map() : map(Compare()) {} explicit map(const Compare& comp= Compare(), const Allocator& = Allocator());Change [map.cons] before p1 as indicated:
explicit map(const Compare& comp= Compare(), const Allocator& = Allocator());Change class template multimap synopsis, [multimap.overview] p2 as indicated:
multimap() : multimap(Compare()) {} explicit multimap(const Compare& comp= Compare(), const Allocator& = Allocator());Change [multimap.cons] before p1 as indicated:
explicit multimap(const Compare& comp= Compare(), const Allocator& = Allocator());Change class template set synopsis, [set.overview] p2 as indicated:
set() : set(Compare()) {} explicit set(const Compare& comp= Compare(), const Allocator& = Allocator());Change [set.cons] before p1 as indicated:
explicit set(const Compare& comp= Compare(), const Allocator& = Allocator());Change class template multiset synopsis, [multiset.overview] p2 as indicated:
multiset() : multiset(Compare()) {} explicit multiset(const Compare& comp= Compare(), const Allocator& = Allocator());Change [multiset.cons] before p1 as indicated:
explicit multiset(const Compare& comp= Compare(), const Allocator& = Allocator());Change class template unordered_map synopsis, [unord.map.overview] p3 as indicated:
unordered_map() : unordered_map(see below) {} explicit unordered_map(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());Change [unord.map.cnstr] before p1 as indicated:
unordered_map() : unordered_map(see below) {} explicit unordered_map(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());Change class template unordered_multimap synopsis, [unord.multimap.overview] p3 as indicated:
unordered_multimap() : unordered_multimap(see below) {} explicit unordered_multimap(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());Change [unord.multimap.cnstr] before p1 as indicated:
unordered_multimap() : unordered_multimap(see below) {} explicit unordered_multimap(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());Change class template unordered_set synopsis, [unord.set.overview] p3 as indicated:
unordered_set() : unordered_set(see below) {} explicit unordered_set(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());Change [unord.set.cnstr] before p1 as indicated:
unordered_set() : unordered_set(see below) {} explicit unordered_set(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());Change class template unordered_multiset synopsis, [unord.multiset.overview] p3 as indicated:
unordered_multiset() : unordered_multiset(see below) {} explicit unordered_multiset(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());Change [unord.multiset.cnstr] before p1 as indicated:
unordered_multiset() : unordered_multiset(see below) {} explicit unordered_multiset(size_type n= see below, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type());
[ 2013-10-06, Daniel comments: ]
Issue 2303 describes the more general problem related to explicit instantiation requests in the current library and may help to solve this problem here as well.
[ 2013-08-27, Joaquín M López Muñoz comments: ]
For the record, I'd like to point out that the resolution proposed by the submitter, namely replacing
explicit basic_string(const Allocator& a = Allocator());
by
basic_string() : basic_string(Allocator()) {} explicit basic_string(const Allocator& a);
(and similarly for other container and container-like classes) might introduce a potential backwards-compatibility problem related with explicit instantiation. Consider for instance
struct my_allocator { my_allocator(...); // no default ctor ... }; template class std::basic_string<char, std::char_traits<char>, my_allocator<char>>;
This (which I understand is currently a valid explicit instantiation of std::basic_string) will break if std::basic_string ctors are modified as proposed by this issue, since my_allocator doesn't have a default ctor.
[ 2012, Portland: Move to Open ]
This may be an issue better solved by a core language tweak. Throw the issue over to EWG and see whether they believe the issue is better resolved in Core or Library.
AJM suggest we spawn a new status of 'EWG' to handle such issues - and will move this issue appropriately when the software can record such resolutions.
[ 2012-10-06: Daniel adds concrete wording. ]
Most (all?) of the standard library containers have explicit default constructors. Consequently:
std::set<int> s1 = { 1, 2 }; // ok std::set<int> s2 = { 1 }; // ok std::set<int> s3 = {}; // ill-formed, copy-list-initialization selected an explicit constructor
Note that Clang + libc++ rejects the declaration of s3 for this reason. This cannot possibly match the intent.
Suggested fix: apply this transformation throughout the standard library:
set() : set(Compare()) {} explicit set(const Compare& comp= Compare(), const Allocator& = Allocator());
History | |||
---|---|---|---|
Date | User | Action | Args |
2014-02-27 17:03:20 | admin | set | status: wp -> c++14 |
2014-02-20 13:52:38 | admin | set | status: immediate -> wp |
2014-02-14 19:48:07 | admin | set | messages: + msg6869 |
2014-02-14 19:48:07 | admin | set | status: ewg -> immediate |
2014-02-14 09:40:24 | admin | set | messages: + msg6861 |
2013-10-06 21:16:04 | admin | set | messages: + msg6676 |
2013-08-27 19:42:08 | admin | set | messages: + msg6573 |
2012-10-21 18:35:06 | admin | set | status: open -> ewg |
2012-10-20 00:32:14 | admin | set | messages: + msg6198 |
2012-10-20 00:32:14 | admin | set | status: new -> open |
2012-10-06 11:55:45 | admin | set | messages: + msg6152 |
2012-10-06 11:55:45 | admin | set | messages: + msg6151 |
2012-10-04 00:00:00 | admin | create |