[libcxx] r236948 - Fix for LWG2454: Add raw_storage_iterator::base() member
Marshall Clow
mclow.lists at gmail.com
Sun May 10 06:14:09 PDT 2015
Author: marshall
Date: Sun May 10 08:14:08 2015
New Revision: 236948
URL: http://llvm.org/viewvc/llvm-project?rev=236948&view=rev
Log:
Fix for LWG2454: Add raw_storage_iterator::base() member
Added:
libcxx/trunk/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp
Modified:
libcxx/trunk/include/memory
Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=236948&r1=236947&r2=236948&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Sun May 10 08:14:08 2015
@@ -1855,6 +1855,9 @@ public:
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
{raw_storage_iterator __t(*this); ++__x_; return __t;}
+#if _LIBCPP_STD_VER >= 14
+ _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
+#endif
};
template <class _Tp>
Added: libcxx/trunk/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp?rev=236948&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp (added)
+++ libcxx/trunk/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp Sun May 10 08:14:08 2015
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// raw_storage_iterator
+
+#include <memory>
+#include <type_traits>
+#include <cassert>
+
+int A_constructed = 0;
+
+struct A
+{
+ int data_;
+public:
+ explicit A(int i) : data_(i) {++A_constructed;}
+
+ A(const A& a) : data_(a.data_) {++A_constructed;}
+ ~A() {--A_constructed; data_ = 0;}
+
+ bool operator==(int i) const {return data_ == i;}
+};
+
+int main()
+{
+#if __cplusplus >= 201402L
+ typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type
+ Storage;
+ Storage buffer;
+ std::raw_storage_iterator<A*, A> it((A*)&buffer);
+ assert(A_constructed == 0);
+ assert(it.base() == (A*)&buffer);
+ for (int i = 0; i < 3; ++i)
+ {
+ *it++ = A(i+1);
+ A* ap = (A*)&buffer + i;
+ assert(*ap == i+1);
+ assert(A_constructed == i+1);
+ assert(it.base() == ap + 1); // next place to write
+ }
+#endif
+}
More information about the cfe-commits
mailing list