summaryrefslogtreecommitdiffstats
path: root/test/std/utilities/memory/specialized.algorithms
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2015-01-06 15:06:45 -0800
committerDan Albert <danalbert@google.com>2015-01-06 15:08:11 -0800
commit06086258d3d8c48a916ec51c33e1ad8f46821b81 (patch)
tree76eec05dd4f486c0aff58af92f9e216b3d6a32ef /test/std/utilities/memory/specialized.algorithms
parent4385cd8d939d12530f7e533d2c0846bb5732f681 (diff)
downloadexternal_libcxx-06086258d3d8c48a916ec51c33e1ad8f46821b81.tar.gz
external_libcxx-06086258d3d8c48a916ec51c33e1ad8f46821b81.tar.bz2
external_libcxx-06086258d3d8c48a916ec51c33e1ad8f46821b81.zip
Merge to upstream r225300.
Change-Id: I2b23715db9ac129ff80aa78ad5824db0a4d6fbb3
Diffstat (limited to 'test/std/utilities/memory/specialized.algorithms')
-rw-r--r--test/std/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp12
-rw-r--r--test/std/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp51
-rw-r--r--test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp51
-rw-r--r--test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp51
-rw-r--r--test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp50
-rw-r--r--test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp50
6 files changed, 265 insertions, 0 deletions
diff --git a/test/std/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp b/test/std/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp
new file mode 100644
index 000000000..b58f5c55b
--- /dev/null
+++ b/test/std/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/test/std/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp b/test/std/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp
new file mode 100644
index 000000000..e07bec4d0
--- /dev/null
+++ b/test/std/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// template <ObjectType T> T* addressof(T& r);
+
+#include <memory>
+#include <cassert>
+
+struct A
+{
+ void operator&() const {}
+};
+
+struct nothing {
+ operator char&()
+ {
+ static char c;
+ return c;
+ }
+};
+
+int main()
+{
+ {
+ int i;
+ double d;
+ assert(std::addressof(i) == &i);
+ assert(std::addressof(d) == &d);
+ A* tp = new A;
+ const A* ctp = tp;
+ assert(std::addressof(*tp) == tp);
+ assert(std::addressof(*ctp) == tp);
+ delete tp;
+ }
+ {
+ union
+ {
+ nothing n;
+ int i;
+ };
+ assert(std::addressof(n) == (void*)std::addressof(i));
+ }
+}
diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
new file mode 100644
index 000000000..7de7eccc6
--- /dev/null
+++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// template <class InputIterator, class ForwardIterator>
+// ForwardIterator
+// uninitialized_copy(InputIterator first, InputIterator last,
+// ForwardIterator result);
+
+#include <memory>
+#include <cassert>
+
+struct B
+{
+ static int count_;
+ int data_;
+ explicit B() : data_(1) {}
+ B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
+ ~B() {data_ = 0;}
+};
+
+int B::count_ = 0;
+
+int main()
+{
+ const int N = 5;
+ char pool[sizeof(B)*N] = {0};
+ B* bp = (B*)pool;
+ B b[N];
+ try
+ {
+ std::uninitialized_copy(b, b+N, bp);
+ assert(false);
+ }
+ catch (...)
+ {
+ for (int i = 0; i < N; ++i)
+ assert(bp[i].data_ == 0);
+ }
+ B::count_ = 0;
+ std::uninitialized_copy(b, b+2, bp);
+ for (int i = 0; i < 2; ++i)
+ assert(bp[i].data_ == 1);
+}
diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
new file mode 100644
index 000000000..79afa4f8f
--- /dev/null
+++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// template <class InputIterator, class Size, class ForwardIterator>
+// ForwardIterator
+// uninitialized_copy_n(InputIterator first, Size n,
+// ForwardIterator result);
+
+#include <memory>
+#include <cassert>
+
+struct B
+{
+ static int count_;
+ int data_;
+ explicit B() : data_(1) {}
+ B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
+ ~B() {data_ = 0;}
+};
+
+int B::count_ = 0;
+
+int main()
+{
+ const int N = 5;
+ char pool[sizeof(B)*N] = {0};
+ B* bp = (B*)pool;
+ B b[N];
+ try
+ {
+ std::uninitialized_copy_n(b, 5, bp);
+ assert(false);
+ }
+ catch (...)
+ {
+ for (int i = 0; i < N; ++i)
+ assert(bp[i].data_ == 0);
+ }
+ B::count_ = 0;
+ std::uninitialized_copy_n(b, 2, bp);
+ for (int i = 0; i < 2; ++i)
+ assert(bp[i].data_ == 1);
+}
diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
new file mode 100644
index 000000000..8fc6b8194
--- /dev/null
+++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// template <class ForwardIterator, class Size, class T>
+// ForwardIterator
+// uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
+
+#include <memory>
+#include <cassert>
+
+struct B
+{
+ static int count_;
+ int data_;
+ explicit B() : data_(1) {}
+ B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
+ ~B() {data_ = 0;}
+};
+
+int B::count_ = 0;
+
+int main()
+{
+ const int N = 5;
+ char pool[sizeof(B)*N] = {0};
+ B* bp = (B*)pool;
+ try
+ {
+ std::uninitialized_fill_n(bp, 5, B());
+ assert(false);
+ }
+ catch (...)
+ {
+ for (int i = 0; i < N; ++i)
+ assert(bp[i].data_ == 0);
+ }
+ B::count_ = 0;
+ B* r = std::uninitialized_fill_n(bp, 2, B());
+ assert(r == bp + 2);
+ for (int i = 0; i < 2; ++i)
+ assert(bp[i].data_ == 1);
+}
diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
new file mode 100644
index 000000000..c34fdc7a1
--- /dev/null
+++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// template <class ForwardIterator, class T>
+// void
+// uninitialized_fill(ForwardIterator first, ForwardIterator last,
+// const T& x);
+
+#include <memory>
+#include <cassert>
+
+struct B
+{
+ static int count_;
+ int data_;
+ explicit B() : data_(1) {}
+ B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
+ ~B() {data_ = 0;}
+};
+
+int B::count_ = 0;
+
+int main()
+{
+ const int N = 5;
+ char pool[sizeof(B)*N] = {0};
+ B* bp = (B*)pool;
+ try
+ {
+ std::uninitialized_fill(bp, bp+N, B());
+ assert(false);
+ }
+ catch (...)
+ {
+ for (int i = 0; i < N; ++i)
+ assert(bp[i].data_ == 0);
+ }
+ B::count_ = 0;
+ std::uninitialized_fill(bp, bp+2, B());
+ for (int i = 0; i < 2; ++i)
+ assert(bp[i].data_ == 1);
+}