From 9b81593bbcb4151c135af547647cb9b65ecbd6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dumont?= Date: Fri, 9 Dec 2011 20:01:04 +0000 Subject: hashtable.h (_Hashtable<>::emplace, [...]): Add. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2011-12-09 François Dumont * include/bits/hashtable.h (_Hashtable<>::emplace, _Hashtable<>::emplace_hint): Add. * include/debug/unordered_set (unordered_set<>::emplace, unordered_set<>::emplace_hint, unordered_multiset<>::emplace, unordered_multiset<>::emplace_hint): Add. * include/profile/unordered_set: Likewise. * include/debug/unordered_map (unordered_map<>::emplace, unordered_map<>::emplace_hint, unordered_multimap<>::emplace, unordered_multimap<>::emplace_hint): Add. * include/profile/unordered_map: Likewise. * testsuite/23_containers/unordered_map/modifiers/emplace.cc: New. * testsuite/23_containers/unordered_multimap/modifiers/emplace.cc: New. * testsuite/23_containers/unordered_set/modifiers/emplace.cc: New. * testsuite/23_containers/unordered_multiset/modifiers/emplace.cc: New. * testsuite/util/testsuite_container_traits.h (traits_base::has_emplace): Add and defined as std::true_type for unordered containers. * testsuite/util/exception/safety.h (emplace, emplace_hint): Add and use them in basic_safety exception test case. * doc/xml/manual/status_cxx2011.xml: Update unordered containers status. From-SVN: r182174 --- libstdc++-v3/testsuite/util/exception/safety.h | 110 +++++++++++++++++++++++++ 1 file changed, 110 insertions(+) (limited to 'libstdc++-v3/testsuite/util/exception') diff --git a/libstdc++-v3/testsuite/util/exception/safety.h b/libstdc++-v3/testsuite/util/exception/safety.h index b85f7fe..5041898 100644 --- a/libstdc++-v3/testsuite/util/exception/safety.h +++ b/libstdc++-v3/testsuite/util/exception/safety.h @@ -826,6 +826,110 @@ namespace __gnu_test operator()(_Tp&, _Tp&) { } }; + template::has_emplace::value> + struct emplace; + + // Specialization for most containers. + template + struct emplace<_Tp, true> + { + typedef _Tp container_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::size_type size_type; + + void + operator()(_Tp& __test) + { + try + { + const value_type cv = generate_unique(); + __test.emplace(cv); + } + catch(const __gnu_cxx::forced_error&) + { throw; } + } + + // Assumes containers start out equivalent. + void + operator()(_Tp& __control, _Tp& __test) + { + try + { + const value_type cv = generate_unique(); + __test.emplace(cv); + } + catch(const __gnu_cxx::forced_error&) + { throw; } + } + }; + + // Specialization, empty. + template + struct emplace<_Tp, false> + { + void + operator()(_Tp&) { } + + void + operator()(_Tp&, _Tp&) { } + }; + + template::has_emplace::value> + struct emplace_hint; + + // Specialization for most containers. + template + struct emplace_hint<_Tp, true> + { + typedef _Tp container_type; + typedef typename container_type::value_type value_type; + + void + operator()(_Tp& __test) + { + try + { + const value_type cv = generate_unique(); + const size_type sz = std::distance(__test.begin(), __test.end()); + size_type s = generate(sz); + auto i = __test.begin(); + std::advance(i, s); + __test.emplace_hint(i, cv); + } + catch(const __gnu_cxx::forced_error&) + { throw; } + } + + // Assumes containers start out equivalent. + void + operator()(_Tp& __control, _Tp& __test) + { + try + { + const value_type cv = generate_unique(); + const size_type sz = std::distance(__test.begin(), __test.end()); + size_type s = generate(sz); + auto i = __test.begin(); + std::advance(i, s); + __test.emplace_hint(i, cv); + } + catch(const __gnu_cxx::forced_error&) + { throw; } + } + }; + + // Specialization, empty. + template + struct emplace_hint<_Tp, false> + { + void + operator()(_Tp&) { } + + void + operator()(_Tp&, _Tp&) { } + }; template::is_associative::value || traits<_Tp>::is_unordered::value> @@ -1023,6 +1127,8 @@ namespace __gnu_test typedef erase_point erase_point; typedef erase_range erase_range; typedef insert_point insert_point; + typedef emplace emplace; + typedef emplace_hint emplace_hint; typedef pop_front pop_front; typedef pop_back pop_back; typedef push_front push_front; @@ -1039,6 +1145,8 @@ namespace __gnu_test erase_point _M_erasep; erase_range _M_eraser; insert_point _M_insertp; + emplace _M_emplace; + emplace_hint _M_emplaceh; pop_front _M_popf; pop_back _M_popb; push_front _M_pushf; @@ -1098,6 +1206,8 @@ namespace __gnu_test _M_functions.push_back(function_type(base_type::_M_erasep)); _M_functions.push_back(function_type(base_type::_M_eraser)); _M_functions.push_back(function_type(base_type::_M_insertp)); + _M_functions.push_back(function_type(base_type::_M_emplace)); + _M_functions.push_back(function_type(base_type::_M_emplaceh)); _M_functions.push_back(function_type(base_type::_M_popf)); _M_functions.push_back(function_type(base_type::_M_popb)); _M_functions.push_back(function_type(base_type::_M_pushf)); -- cgit v1.1