From 1bcd5b0003d52cf7b24ccdf87423dcfeb449ab1d Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 23 Oct 2016 13:31:07 +0100 Subject: [PATCH] Make no argument constructor implicit --- doc/changes.qbk | 1 + doc/ref.php | 14 +++++- doc/ref.xml | 56 +++++++++++++++++++++-- include/boost/unordered/unordered_map.hpp | 21 ++++++++- include/boost/unordered/unordered_set.hpp | 20 +++++++- test/unordered/compile_tests.hpp | 11 +++++ 6 files changed, 114 insertions(+), 9 deletions(-) diff --git a/doc/changes.qbk b/doc/changes.qbk index cd7cba86..1ac6e023 100644 --- a/doc/changes.qbk +++ b/doc/changes.qbk @@ -294,5 +294,6 @@ C++11 support has resulted in some breaking changes: wrong bucket and equivalent elements would be incorrectly handled. * Various reference documentation improvements. * Better allocator support ([ticket 12459]). +* Make the no argument constructors implicit. [endsect] diff --git a/doc/ref.php b/doc/ref.php index d2fb2b42..bd16992c 100644 --- a/doc/ref.php +++ b/doc/ref.php @@ -189,10 +189,22 @@ EOL; A const_local_iterator object can be used to iterate through a single bucket. + + + size() == 0 + + + Constructs an empty container using hasher() as the hash function, key_equal() as the key equality predicate, allocator_type() as the allocator and a maximum load factor of 1.0. + + + If the defaults are used, hasher, key_equal and + allocator_type need to be DefaultConstructible. + + + size_type - implementation-defined hasher const& diff --git a/doc/ref.xml b/doc/ref.xml index d03e8dd3..73ec2920 100644 --- a/doc/ref.xml +++ b/doc/ref.xml @@ -130,10 +130,22 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) A const_local_iterator object can be used to iterate through a single bucket. + + + size() == 0 + + + Constructs an empty container using hasher() as the hash function, key_equal() as the key equality predicate, allocator_type() as the allocator and a maximum load factor of 1.0. + + + If the defaults are used, hasher, key_equal and + allocator_type need to be DefaultConstructible. + + + size_type - implementation-defined hasher const& @@ -1204,10 +1216,22 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) A const_local_iterator object can be used to iterate through a single bucket. + + + size() == 0 + + + Constructs an empty container using hasher() as the hash function, key_equal() as the key equality predicate, allocator_type() as the allocator and a maximum load factor of 1.0. + + + If the defaults are used, hasher, key_equal and + allocator_type need to be DefaultConstructible. + + + size_type - implementation-defined hasher const& @@ -2287,10 +2311,22 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) A const_local_iterator object can be used to iterate through a single bucket. + + + size() == 0 + + + Constructs an empty container using hasher() as the hash function, key_equal() as the key equality predicate, allocator_type() as the allocator and a maximum load factor of 1.0. + + + If the defaults are used, hasher, key_equal and + allocator_type need to be DefaultConstructible. + + + size_type - implementation-defined hasher const& @@ -3408,10 +3444,22 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) A const_local_iterator object can be used to iterate through a single bucket. + + + size() == 0 + + + Constructs an empty container using hasher() as the hash function, key_equal() as the key equality predicate, allocator_type() as the allocator and a maximum load factor of 1.0. + + + If the defaults are used, hasher, key_equal and + allocator_type need to be DefaultConstructible. + + + size_type - implementation-defined hasher const& diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index 84f144c5..88108363 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -82,8 +82,10 @@ namespace unordered // constructors + unordered_map(); + explicit unordered_map( - size_type = boost::unordered::detail::default_bucket_count, + size_type, const hasher& = hasher(), const key_equal& = key_equal(), const allocator_type& = allocator_type()); @@ -565,8 +567,9 @@ namespace unordered // constructors + unordered_multimap(); explicit unordered_multimap( - size_type = boost::unordered::detail::default_bucket_count, + size_type, const hasher& = hasher(), const key_equal& = key_equal(), const allocator_type& = allocator_type()); @@ -1002,6 +1005,13 @@ namespace unordered //////////////////////////////////////////////////////////////////////////////// + template + unordered_map::unordered_map() + : table_(boost::unordered::detail::default_bucket_count, hasher(), + key_equal(), allocator_type()) + { + } + template unordered_map::unordered_map( size_type n, const hasher &hf, const key_equal &eql, @@ -1335,6 +1345,13 @@ namespace unordered //////////////////////////////////////////////////////////////////////////////// + template + unordered_multimap::unordered_multimap() + : table_(boost::unordered::detail::default_bucket_count, hasher(), + key_equal(), allocator_type()) + { + } + template unordered_multimap::unordered_multimap( size_type n, const hasher &hf, const key_equal &eql, diff --git a/include/boost/unordered/unordered_set.hpp b/include/boost/unordered/unordered_set.hpp index ea411f6d..42c30bc9 100644 --- a/include/boost/unordered/unordered_set.hpp +++ b/include/boost/unordered/unordered_set.hpp @@ -79,8 +79,9 @@ namespace unordered // constructors + unordered_set(); explicit unordered_set( - size_type = boost::unordered::detail::default_bucket_count, + size_type, const hasher& = hasher(), const key_equal& = key_equal(), const allocator_type& = allocator_type()); @@ -548,8 +549,9 @@ namespace unordered // constructors + unordered_multiset(); explicit unordered_multiset( - size_type = boost::unordered::detail::default_bucket_count, + size_type, const hasher& = hasher(), const key_equal& = key_equal(), const allocator_type& = allocator_type()); @@ -976,6 +978,13 @@ namespace unordered //////////////////////////////////////////////////////////////////////////////// + template + unordered_set::unordered_set() + : table_(boost::unordered::detail::default_bucket_count, hasher(), + key_equal(), allocator_type()) + { + } + template unordered_set::unordered_set( size_type n, const hasher &hf, const key_equal &eql, @@ -1260,6 +1269,13 @@ namespace unordered //////////////////////////////////////////////////////////////////////////////// + template + unordered_multiset::unordered_multiset() + : table_(boost::unordered::detail::default_bucket_count, hasher(), + key_equal(), allocator_type()) + { + } + template unordered_multiset::unordered_multiset( size_type n, const hasher &hf, const key_equal &eql, diff --git a/test/unordered/compile_tests.hpp b/test/unordered/compile_tests.hpp index 9e5dba30..62a4c3fc 100644 --- a/test/unordered/compile_tests.hpp +++ b/test/unordered/compile_tests.hpp @@ -101,7 +101,18 @@ void container_test(X& r, T const&) static_cast( (std::numeric_limits::max)())); + // Constructors + // I don't test the runtime post-conditions here. + +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + // It isn't specified in the container requirements that the no argument + // constructor is implicit, but it is defined that way in the concrete + // container specification. + X u_implicit = {}; + sink(u_implicit); +#endif + X u; BOOST_TEST(u.size() == 0); BOOST_TEST(X().size() == 0);