[libcxx] r188333 - Implement LWG Issue #2187 (emplace_back and emplace for vector<bool>)
Marshall Clow
mclow.lists at gmail.com
Tue Aug 13 16:54:12 PDT 2013
Author: marshall
Date: Tue Aug 13 18:54:12 2013
New Revision: 188333
URL: http://llvm.org/viewvc/llvm-project?rev=188333&view=rev
Log:
Implement LWG Issue #2187 (emplace_back and emplace for vector<bool>)
Added:
libcxx/trunk/test/containers/sequences/vector.bool/emplace.pass.cpp
libcxx/trunk/test/containers/sequences/vector.bool/emplace_back.pass.cpp
Modified:
libcxx/trunk/include/vector
libcxx/trunk/www/cxx1y_status.html
Modified: libcxx/trunk/include/vector
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=188333&r1=188332&r2=188333&view=diff
==============================================================================
--- libcxx/trunk/include/vector (original)
+++ libcxx/trunk/include/vector Tue Aug 13 18:54:12 2013
@@ -216,8 +216,10 @@ public:
const_reference back() const;
void push_back(const value_type& x);
+ template <class... Args> void emplace_back(Args&&... args); // C++14
void pop_back();
+ template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
iterator insert(const_iterator position, const value_type& x);
iterator insert(const_iterator position, size_type n, const value_type& x);
template <class InputIterator>
@@ -2221,8 +2223,20 @@ public:
_LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
void push_back(const value_type& __x);
+#if _LIBCPP_STD_VER > 11
+ template <class... _Args>
+ _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
+ { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); }
+#endif
+
_LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
+#if _LIBCPP_STD_VER > 11
+ template <class... _Args>
+ _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
+ { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
+#endif
+
iterator insert(const_iterator __position, const value_type& __x);
iterator insert(const_iterator __position, size_type __n, const value_type& __x);
iterator insert(const_iterator __position, size_type __n, const_reference __x);
Added: libcxx/trunk/test/containers/sequences/vector.bool/emplace.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector.bool/emplace.pass.cpp?rev=188333&view=auto
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector.bool/emplace.pass.cpp (added)
+++ libcxx/trunk/test/containers/sequences/vector.bool/emplace.pass.cpp Tue Aug 13 18:54:12 2013
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+// vector<bool>
+
+// template <class... Args> iterator emplace(const_iterator pos, Args&&... args);
+
+#include <vector>
+#include <cassert>
+#include "../../min_allocator.h"
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef std::vector<bool> C;
+ C c;
+
+ C::iterator i = c.emplace(c.cbegin());
+ assert(i == c.begin());
+ assert(c.size() == 1);
+ assert(c.front() == false);
+
+ i = c.emplace(c.cend(), true);
+ assert(i == c.end()-1);
+ assert(c.size() == 2);
+ assert(c.front() == false);
+ assert(c.back() == true);
+
+ i = c.emplace(c.cbegin()+1, 1 == 1);
+ assert(i == c.begin()+1);
+ assert(c.size() == 3);
+ assert(c.front() == false);
+ assert(c[1] == true);
+ assert(c.back() == true);
+ }
+ {
+ typedef std::vector<bool, min_allocator<bool>> C;
+ C c;
+
+ C::iterator i = c.emplace(c.cbegin());
+ assert(i == c.begin());
+ assert(c.size() == 1);
+ assert(c.front() == false);
+
+ i = c.emplace(c.cend(), true);
+ assert(i == c.end()-1);
+ assert(c.size() == 2);
+ assert(c.front() == false);
+ assert(c.back() == true);
+
+ i = c.emplace(c.cbegin()+1, 1 == 1);
+ assert(i == c.begin()+1);
+ assert(c.size() == 3);
+ assert(c.size() == 3);
+ assert(c.front() == false);
+ assert(c[1] == true);
+ assert(c.back() == true);
+ }
+#endif
+}
Added: libcxx/trunk/test/containers/sequences/vector.bool/emplace_back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector.bool/emplace_back.pass.cpp?rev=188333&view=auto
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector.bool/emplace_back.pass.cpp (added)
+++ libcxx/trunk/test/containers/sequences/vector.bool/emplace_back.pass.cpp Tue Aug 13 18:54:12 2013
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+// vector.bool
+
+// template <class... Args> void emplace_back(Args&&... args);
+
+#include <vector>
+#include <cassert>
+#include "../../min_allocator.h"
+
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef std::vector<bool> C;
+ C c;
+ c.emplace_back();
+ assert(c.size() == 1);
+ assert(c.front() == false);
+ c.emplace_back(true);
+ assert(c.size() == 2);
+ assert(c.front() == false);
+ assert(c.back() == true);
+ c.emplace_back(1 == 1);
+ assert(c.size() == 3);
+ assert(c.front() == false);
+ assert(c[1] == true);
+ assert(c.back() == true);
+ }
+ {
+ typedef std::vector<bool, min_allocator<bool>> C;
+ C c;
+
+ c.emplace_back();
+ assert(c.size() == 1);
+ assert(c.front() == false);
+ c.emplace_back(true);
+ assert(c.size() == 2);
+ assert(c.front() == false);
+ assert(c.back() == true);
+ c.emplace_back(1 == 1);
+ assert(c.size() == 3);
+ assert(c.front() == false);
+ assert(c[1] == true);
+ assert(c.back() == true);
+ }
+#endif
+}
Modified: libcxx/trunk/www/cxx1y_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1y_status.html?rev=188333&r1=188332&r2=188333&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1y_status.html (original)
+++ libcxx/trunk/www/cxx1y_status.html Tue Aug 13 18:54:12 2013
@@ -123,7 +123,7 @@
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2174">2174</a></td><td>wstring_convert::converted() should be noexcept</td><td>Bristol</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2175">2175</a></td><td>string_convert and wbuffer_convert validity</td><td>Bristol</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2177">2177</a></td><td>Requirements on Copy/MoveInsertable</td><td>Bristol</td><td></td></tr>
- <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2187">2187</a></td><td>vector<bool> is missing emplace and emplace_back member functions</td><td>Bristol</td><td>Not complete</td></tr>
+ <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2187">2187</a></td><td>vector<bool> is missing emplace and emplace_back member functions</td><td>Bristol</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2197">2197</a></td><td>Specification of is_[un]signed unclear for non-arithmetic types</td><td>Bristol</td><td>Complete</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2200">2200</a></td><td>Data race avoidance for all containers, not only for sequences</td><td>Bristol</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2209">2209</a></td><td>assign() overspecified for sequence containers</td><td>Bristol</td><td></td></tr>
More information about the cfe-commits
mailing list