Commit 76225d2c by François Dumont

stl_vector.h (push_back(const value_type&)): Forward to _M_realloc_insert.

2016-07-11  François Dumont  <fdumont@gcc.gnu.org>

	* include/bits/stl_vector.h (push_back(const value_type&)): Forward
	to _M_realloc_insert.
	(insert(const_iterator, value_type&&)): Forward to _M_insert_rval.
	(_M_realloc_insert): Declare new function.
	(_M_emplace_back_aux): Remove definition.
	* include/bits/vector.tcc (emplace_back(_Args...)):
	Use _M_realloc_insert.
	(insert(const_iterator, const value_type&)): Likewise.
	(_M_insert_rval, _M_emplace_aux): Likewise.
	(_M_emplace_back_aux): Remove declaration.
	(_M_realloc_insert): Define.
	* testsuite/23_containers/vector/modifiers/insert_vs_emplace.cc:
	Adjust expected results for emplacing an lvalue with reallocation.

From-SVN: r238226
parent 4368a420
2016-07-11 François Dumont <fdumont@gcc.gnu.org>
* include/bits/stl_vector.h (push_back(const value_type&)): Forward
to _M_realloc_insert.
(insert(const_iterator, value_type&&)): Forward to _M_insert_rval.
(_M_realloc_insert): Declare new function.
(_M_emplace_back_aux): Remove definition.
* include/bits/vector.tcc (emplace_back(_Args...)):
Use _M_realloc_insert.
(insert(const_iterator, const value_type&)): Likewise.
(_M_insert_rval, _M_emplace_aux): Likewise.
(_M_emplace_back_aux): Remove declaration.
(_M_realloc_insert): Define.
* testsuite/23_containers/vector/modifiers/insert_vs_emplace.cc:
Adjust expected results for emplacing an lvalue with reallocation.
2016-07-10 Ville Voutilainen <ville.voutilainen@gmail.com> 2016-07-10 Ville Voutilainen <ville.voutilainen@gmail.com>
Implement std::optional. Implement std::optional.
......
...@@ -946,11 +946,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -946,11 +946,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
++this->_M_impl._M_finish; ++this->_M_impl._M_finish;
} }
else else
#if __cplusplus >= 201103L _M_realloc_insert(end(), __x);
_M_emplace_back_aux(__x);
#else
_M_insert_aux(end(), __x);
#endif
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
...@@ -1436,6 +1432,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1436,6 +1432,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
// Called by insert(p,x) // Called by insert(p,x)
void void
_M_insert_aux(iterator __position, const value_type& __x); _M_insert_aux(iterator __position, const value_type& __x);
void
_M_realloc_insert(iterator __position, const value_type& __x);
#else #else
// A value_type object constructed with _Alloc_traits::construct() // A value_type object constructed with _Alloc_traits::construct()
// and destroyed with _Alloc_traits::destroy(). // and destroyed with _Alloc_traits::destroy().
...@@ -1469,16 +1468,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1469,16 +1468,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
void void
_M_insert_aux(iterator __position, _Arg&& __arg); _M_insert_aux(iterator __position, _Arg&& __arg);
template<typename... _Args>
void
_M_realloc_insert(iterator __position, _Args&&... __args);
// Either move-construct at the end, or forward to _M_insert_aux. // Either move-construct at the end, or forward to _M_insert_aux.
iterator iterator
_M_insert_rval(const_iterator __position, value_type&& __v); _M_insert_rval(const_iterator __position, value_type&& __v);
// Called by push_back(x) and emplace_back(args) when they need to
// reallocate.
template<typename... _Args>
void
_M_emplace_back_aux(_Args&&... __args);
// Try to emplace at the end, otherwise forward to _M_insert_aux. // Try to emplace at the end, otherwise forward to _M_insert_aux.
template<typename... _Args> template<typename... _Args>
iterator iterator
......
...@@ -223,8 +223,7 @@ test03() ...@@ -223,8 +223,7 @@ test03()
void void
test04() test04()
{ {
const X::special expected_ins{ 0, 3, 1, 0, 3, 0 }; const X::special expected{ 0, 3, 1, 0, 3, 0 };
const X::special expected_emp{ 0, 4, 1, 0, 4, 0 };
X::special ins, emp; X::special ins, emp;
{ {
std::vector<X> v; std::vector<X> v;
...@@ -254,8 +253,8 @@ test04() ...@@ -254,8 +253,8 @@ test04()
// std::cout << "----\n"; // std::cout << "----\n";
emp = X::sp; emp = X::sp;
} }
VERIFY( ins == expected_ins ); VERIFY( ins == emp );
VERIFY( emp == expected_emp ); VERIFY( ins == expected );
} }
// insert vs emplace xvalue reallocation // insert vs emplace xvalue reallocation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment