Fixing whitespace problems
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@111767 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template<class T> class weak_ptr
|
||||
// {
|
||||
// public:
|
||||
// typedef T element_type;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct A; // purposefully incomplete
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::weak_ptr<A>::element_type, A>::value), "");
|
||||
}
|
||||
|
@@ -1 +1,74 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class T> struct owner_less;
|
||||
//
|
||||
// template <class T>
|
||||
// struct owner_less<shared_ptr<T> >
|
||||
// : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
|
||||
// {
|
||||
// typedef bool result_type;
|
||||
// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
|
||||
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
|
||||
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
|
||||
// };
|
||||
//
|
||||
// template <class T>
|
||||
// struct owner_less<weak_ptr<T> >
|
||||
// : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
|
||||
// {
|
||||
// typedef bool result_type;
|
||||
// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
|
||||
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
|
||||
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::shared_ptr<int> p1(new int);
|
||||
const std::shared_ptr<int> p2 = p1;
|
||||
const std::shared_ptr<int> p3(new int);
|
||||
const std::weak_ptr<int> w1(p1);
|
||||
const std::weak_ptr<int> w2(p2);
|
||||
const std::weak_ptr<int> w3(p3);
|
||||
|
||||
{
|
||||
typedef std::owner_less<std::shared_ptr<int> > CS;
|
||||
CS cs;
|
||||
|
||||
assert(!cs(p1, p2));
|
||||
assert(!cs(p2, p1));
|
||||
assert(cs(p1 ,p3) || cs(p3, p1));
|
||||
assert(cs(p3, p1) == cs(p3, p2));
|
||||
|
||||
assert(!cs(p1, w2));
|
||||
assert(!cs(p2, w1));
|
||||
assert(cs(p1, w3) || cs(p3, w1));
|
||||
assert(cs(p3, w1) == cs(p3, w2));
|
||||
}
|
||||
{
|
||||
typedef std::owner_less<std::weak_ptr<int> > CS;
|
||||
CS cs;
|
||||
|
||||
assert(!cs(w1, w2));
|
||||
assert(!cs(w2, w1));
|
||||
assert(cs(w1, w3) || cs(w3, w1));
|
||||
assert(cs(w3, w1) == cs(w3, w2));
|
||||
|
||||
assert(!cs(w1, p2));
|
||||
assert(!cs(w2, p1));
|
||||
assert(cs(w1, p3) || cs(w3, p1));
|
||||
assert(cs(w3, p1) == cs(w3, p2));
|
||||
}
|
||||
}
|
||||
|
@@ -1 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r);
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::shared_ptr<A> pA(new A);
|
||||
{
|
||||
std::weak_ptr<B> pB;
|
||||
pB = pA;
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
assert(pB.use_count() == 1);
|
||||
assert(pA.use_count() == 1);
|
||||
}
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
@@ -1 +1,62 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// weak_ptr& operator=(const weak_ptr& r);
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::shared_ptr<A> ps(new A);
|
||||
const std::weak_ptr<A> pA(ps);
|
||||
{
|
||||
std::weak_ptr<A> pB;
|
||||
pB = pA;
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
assert(pB.use_count() == 1);
|
||||
assert(pA.use_count() == 1);
|
||||
}
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
@@ -1 +1,62 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r);
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::shared_ptr<A> ps(new A);
|
||||
const std::weak_ptr<A> pA(ps);
|
||||
{
|
||||
std::weak_ptr<B> pB;
|
||||
pB = pA;
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
assert(pB.use_count() == 1);
|
||||
assert(pA.use_count() == 1);
|
||||
}
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
@@ -1 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template<class T> class weak_ptr
|
||||
|
||||
// weak_ptr();
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::weak_ptr<A> p;
|
||||
assert(p.use_count() == 0);
|
||||
}
|
||||
|
@@ -1 +1,95 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// template<class Y> weak_ptr(const shared_ptr<Y>& r);
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct C
|
||||
{
|
||||
static int count;
|
||||
|
||||
C() {++count;}
|
||||
C(const C&) {++count;}
|
||||
virtual ~C() {--count;}
|
||||
};
|
||||
|
||||
int C::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(( std::is_convertible<std::shared_ptr<A>, std::weak_ptr<B> >::value), "");
|
||||
static_assert((!std::is_convertible<std::weak_ptr<B>, std::shared_ptr<A> >::value), "");
|
||||
static_assert((!std::is_convertible<std::shared_ptr<A>, std::weak_ptr<C> >::value), "");
|
||||
{
|
||||
const std::shared_ptr<A> pA(new A);
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
{
|
||||
std::weak_ptr<B> pB(pA);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
assert(pB.use_count() == 1);
|
||||
assert(pA.use_count() == 1);
|
||||
}
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<A> pA;
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::weak_ptr<B> pB(pA);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
assert(pB.use_count() == 0);
|
||||
assert(pA.use_count() == 0);
|
||||
}
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
@@ -1 +1,93 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// weak_ptr(const weak_ptr& r);
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct C
|
||||
{
|
||||
static int count;
|
||||
|
||||
C() {++count;}
|
||||
C(const C&) {++count;}
|
||||
virtual ~C() {--count;}
|
||||
};
|
||||
|
||||
int C::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::shared_ptr<A> ps(new A);
|
||||
const std::weak_ptr<A> pA(ps);
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
{
|
||||
std::weak_ptr<A> pB(pA);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
assert(pB.use_count() == 1);
|
||||
assert(pA.use_count() == 1);
|
||||
}
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::weak_ptr<A> pA;
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::weak_ptr<A> pB(pA);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
assert(pB.use_count() == 0);
|
||||
assert(pA.use_count() == 0);
|
||||
}
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
@@ -1 +1,95 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// template<class Y> weak_ptr(const weak_ptr<Y>& r);
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct C
|
||||
{
|
||||
static int count;
|
||||
|
||||
C() {++count;}
|
||||
C(const C&) {++count;}
|
||||
virtual ~C() {--count;}
|
||||
};
|
||||
|
||||
int C::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(( std::is_convertible<std::weak_ptr<A>, std::weak_ptr<B> >::value), "");
|
||||
static_assert((!std::is_convertible<std::weak_ptr<B>, std::weak_ptr<A> >::value), "");
|
||||
static_assert((!std::is_convertible<std::weak_ptr<A>, std::weak_ptr<C> >::value), "");
|
||||
{
|
||||
const std::weak_ptr<A> pA(std::shared_ptr<A>(new A));
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::weak_ptr<B> pB(pA);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
assert(pB.use_count() == 0);
|
||||
assert(pA.use_count() == 0);
|
||||
}
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::weak_ptr<A> pA;
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::weak_ptr<B> pB(pA);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
assert(pB.use_count() == 0);
|
||||
assert(pA.use_count() == 0);
|
||||
}
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
@@ -1 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
@@ -1 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// void swap(weak_ptr& r);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::shared_ptr<A> p1(new A);
|
||||
std::weak_ptr<A> w1(p1);
|
||||
assert(w1.use_count() == 1);
|
||||
w1.reset();
|
||||
assert(w1.use_count() == 0);
|
||||
assert(p1.use_count() == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
@@ -1 +1,49 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// void swap(weak_ptr& r);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* ptr1 = new A;
|
||||
A* ptr2 = new A;
|
||||
std::shared_ptr<A> p1(ptr1);
|
||||
std::weak_ptr<A> w1(p1);
|
||||
{
|
||||
std::shared_ptr<A> p2(ptr2);
|
||||
std::weak_ptr<A> w2(p2);
|
||||
w1.swap(w2);
|
||||
assert(w1.use_count() == 1);
|
||||
assert(w1.lock().get() == ptr2);
|
||||
assert(w2.use_count() == 1);
|
||||
assert(w2.lock().get() == ptr1);
|
||||
assert(A::count == 2);
|
||||
}
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
@@ -1 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// bool expired() const;
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::weak_ptr<A> wp;
|
||||
assert(wp.use_count() == 0);
|
||||
assert(wp.expired() == (wp.use_count() == 0));
|
||||
}
|
||||
{
|
||||
std::shared_ptr<A> sp0(new A);
|
||||
std::weak_ptr<A> wp(sp0);
|
||||
assert(wp.use_count() == 1);
|
||||
assert(wp.expired() == (wp.use_count() == 0));
|
||||
sp0.reset();
|
||||
assert(wp.use_count() == 0);
|
||||
assert(wp.expired() == (wp.use_count() == 0));
|
||||
}
|
||||
}
|
||||
|
@@ -1 +1,58 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// shared_ptr<T> lock() const;
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::weak_ptr<A> wp;
|
||||
std::shared_ptr<A> sp = wp.lock();
|
||||
assert(sp.use_count() == 0);
|
||||
assert(sp.get() == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
{
|
||||
std::shared_ptr<A> sp0(new A);
|
||||
std::weak_ptr<A> wp(sp0);
|
||||
std::shared_ptr<A> sp = wp.lock();
|
||||
assert(sp.use_count() == 2);
|
||||
assert(sp.get() == sp0.get());
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<A> sp0(new A);
|
||||
std::weak_ptr<A> wp(sp0);
|
||||
sp0.reset();
|
||||
std::shared_ptr<A> sp = wp.lock();
|
||||
assert(sp.use_count() == 0);
|
||||
assert(sp.get() == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
@@ -1 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class T> class weak_ptr;
|
||||
//
|
||||
// not less than comparable
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::shared_ptr<int> p1(new int);
|
||||
const std::shared_ptr<int> p2(new int);
|
||||
const std::weak_ptr<int> w1(p1);
|
||||
const std::weak_ptr<int> w2(p2);
|
||||
|
||||
bool b = w1 < w2;
|
||||
}
|
||||
|
@@ -1 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// template<class U> bool owner_before(const shared_ptr<U>& b);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::shared_ptr<int> p1(new int);
|
||||
const std::shared_ptr<int> p2 = p1;
|
||||
const std::shared_ptr<int> p3(new int);
|
||||
const std::weak_ptr<int> w1(p1);
|
||||
const std::weak_ptr<int> w2(p2);
|
||||
const std::weak_ptr<int> w3(p3);
|
||||
assert(!w1.owner_before(p2));
|
||||
assert(!w2.owner_before(p1));
|
||||
assert(w1.owner_before(p3) || w3.owner_before(p1));
|
||||
assert(w3.owner_before(p1) == w3.owner_before(p2));
|
||||
}
|
||||
|
@@ -1 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// template<class U> bool owner_before(const weak_ptr<U>& b);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::shared_ptr<int> p1(new int);
|
||||
const std::shared_ptr<int> p2 = p1;
|
||||
const std::shared_ptr<int> p3(new int);
|
||||
const std::weak_ptr<int> w1(p1);
|
||||
const std::weak_ptr<int> w2(p2);
|
||||
const std::weak_ptr<int> w3(p3);
|
||||
assert(!w1.owner_before(w2));
|
||||
assert(!w2.owner_before(w1));
|
||||
assert(w1.owner_before(w3) || w3.owner_before(w1));
|
||||
assert(w3.owner_before(w1) == w3.owner_before(w2));
|
||||
}
|
||||
|
@@ -1 +1,49 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// weak_ptr
|
||||
|
||||
// template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b)
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* ptr1 = new A;
|
||||
A* ptr2 = new A;
|
||||
std::shared_ptr<A> p1(ptr1);
|
||||
std::weak_ptr<A> w1(p1);
|
||||
{
|
||||
std::shared_ptr<A> p2(ptr2);
|
||||
std::weak_ptr<A> w2(p2);
|
||||
swap(w1, w2);
|
||||
assert(w1.use_count() == 1);
|
||||
assert(w1.lock().get() == ptr2);
|
||||
assert(w2.use_count() == 1);
|
||||
assert(w2.lock().get() == ptr1);
|
||||
assert(A::count == 2);
|
||||
}
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user