Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// template <class OuterA2>
|
||||
// scoped_allocator_adaptor(OuterA2&& outerAlloc,
|
||||
// const InnerAllocs& ...innerAllocs);
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A1<int> a3(3);
|
||||
A a(a3);
|
||||
assert(a.outer_allocator() == A1<int>(3));
|
||||
assert(a.inner_allocator() == a);
|
||||
assert(A1<int>::copy_called == true);
|
||||
assert(A1<int>::move_called == false);
|
||||
}
|
||||
A1<int>::copy_called = false;
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A a(A1<int>(3));
|
||||
assert(a.outer_allocator() == A1<int>(3));
|
||||
assert(a.inner_allocator() == a);
|
||||
assert(A1<int>::copy_called == false);
|
||||
assert(A1<int>::move_called == true);
|
||||
}
|
||||
A1<int>::move_called = false;
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
A1<int> a4(4);
|
||||
A a(a4, A2<int>(5));
|
||||
assert(A1<int>::copy_called == true);
|
||||
assert(A1<int>::move_called == false);
|
||||
assert(A2<int>::copy_called == true);
|
||||
assert(A2<int>::move_called == false);
|
||||
assert(a.outer_allocator() == A1<int>(4));
|
||||
assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>(A2<int>(5)));
|
||||
}
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A2<int>::copy_called = false;
|
||||
A2<int>::move_called = false;
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
A a(A1<int>(4), A2<int>(5));
|
||||
assert(A1<int>::copy_called == false);
|
||||
assert(A1<int>::move_called == true);
|
||||
assert(A2<int>::copy_called == true);
|
||||
assert(A2<int>::move_called == false);
|
||||
assert(a.outer_allocator() == A1<int>(4));
|
||||
assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>(A2<int>(5)));
|
||||
}
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A2<int>::copy_called = false;
|
||||
A2<int>::move_called = false;
|
||||
A1<int>::move_called = false;
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A1<int> a4(4);
|
||||
A a(a4, A2<int>(5), A3<int>(6));
|
||||
assert(A1<int>::copy_called == true);
|
||||
assert(A1<int>::move_called == false);
|
||||
assert(A2<int>::copy_called == true);
|
||||
assert(A2<int>::move_called == false);
|
||||
assert(A3<int>::copy_called == true);
|
||||
assert(A3<int>::move_called == false);
|
||||
assert(a.outer_allocator() == A1<int>(4));
|
||||
assert((a.inner_allocator() ==
|
||||
std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6))));
|
||||
}
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A2<int>::copy_called = false;
|
||||
A2<int>::move_called = false;
|
||||
A3<int>::copy_called = false;
|
||||
A3<int>::move_called = false;
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a(A1<int>(4), A2<int>(5), A3<int>(6));
|
||||
assert(A1<int>::copy_called == false);
|
||||
assert(A1<int>::move_called == true);
|
||||
assert(A2<int>::copy_called == true);
|
||||
assert(A2<int>::move_called == false);
|
||||
assert(A3<int>::copy_called == true);
|
||||
assert(A3<int>::move_called == false);
|
||||
assert(a.outer_allocator() == A1<int>(4));
|
||||
assert((a.inner_allocator() ==
|
||||
std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6))));
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// template <class OuterA2>
|
||||
// scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2,
|
||||
// InnerAllocs...>& other);
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<double>> B;
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
B a1(A1<int>(3));
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A a2 = a1;
|
||||
assert(A1<int>::copy_called == true);
|
||||
assert(a2 == a1);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<double>, A2<int>> B;
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
B a1(A1<int>(4), A2<int>(5));
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A2<int>::copy_called = false;
|
||||
A2<int>::move_called = false;
|
||||
A a2 = a1;
|
||||
assert(A1<int>::copy_called == true);
|
||||
assert(A2<int>::copy_called == true);
|
||||
assert(a2 == a1);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<double>, A2<int>, A3<int>> B;
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
B a1(A1<int>(4), A2<int>(5), A3<int>(6));
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A2<int>::copy_called = false;
|
||||
A2<int>::move_called = false;
|
||||
A3<int>::copy_called = false;
|
||||
A3<int>::move_called = false;
|
||||
A a2 = a1;
|
||||
assert(A1<int>::copy_called == true);
|
||||
assert(A2<int>::copy_called == true);
|
||||
assert(A3<int>::copy_called == true);
|
||||
assert(a2 == a1);
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// template <class OuterA2>
|
||||
// scoped_allocator_adaptor(scoped_allocator_adaptor<OuterA2,
|
||||
// InnerAllocs...>&& other);
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<double>> B;
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
B a1(A1<int>(3));
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A a2 = std::move(a1);
|
||||
assert(A1<int>::copy_called == false);
|
||||
assert(A1<int>::move_called == true);
|
||||
assert(a2 == a1);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<double>, A2<int>> B;
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
B a1(A1<int>(4), A2<int>(5));
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A2<int>::copy_called = false;
|
||||
A2<int>::move_called = false;
|
||||
A a2 = std::move(a1);
|
||||
assert(A1<int>::copy_called == false);
|
||||
assert(A1<int>::move_called == true);
|
||||
assert(A2<int>::copy_called == false);
|
||||
assert(A2<int>::move_called == true);
|
||||
assert(a2 == a1);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<double>, A2<int>, A3<int>> B;
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
B a1(A1<int>(4), A2<int>(5), A3<int>(6));
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A2<int>::copy_called = false;
|
||||
A2<int>::move_called = false;
|
||||
A3<int>::copy_called = false;
|
||||
A3<int>::move_called = false;
|
||||
A a2 = std::move(a1);
|
||||
assert(A1<int>::copy_called == false);
|
||||
assert(A1<int>::move_called == true);
|
||||
assert(A2<int>::copy_called == false);
|
||||
assert(A2<int>::move_called == true);
|
||||
assert(A3<int>::copy_called == false);
|
||||
assert(A3<int>::move_called == true);
|
||||
assert(a2 == a1);
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// scoped_allocator_adaptor(const scoped_allocator_adaptor& other);
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A a1(A1<int>(3));
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A a2 = a1;
|
||||
assert(A1<int>::copy_called == true);
|
||||
assert(A1<int>::move_called == false);
|
||||
assert(a2 == a1);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
A a1(A1<int>(4), A2<int>(5));
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A2<int>::copy_called = false;
|
||||
A2<int>::move_called = false;
|
||||
A a2 = a1;
|
||||
assert(A1<int>::copy_called == true);
|
||||
assert(A1<int>::move_called == false);
|
||||
assert(A2<int>::copy_called == true);
|
||||
assert(A2<int>::move_called == false);
|
||||
assert(a2 == a1);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a1(A1<int>(4), A2<int>(5), A3<int>(6));
|
||||
A1<int>::copy_called = false;
|
||||
A1<int>::move_called = false;
|
||||
A2<int>::copy_called = false;
|
||||
A2<int>::move_called = false;
|
||||
A3<int>::copy_called = false;
|
||||
A3<int>::move_called = false;
|
||||
A a2 = a1;
|
||||
assert(A1<int>::copy_called == true);
|
||||
assert(A1<int>::move_called == false);
|
||||
assert(A2<int>::copy_called == true);
|
||||
assert(A2<int>::move_called == false);
|
||||
assert(A3<int>::copy_called == true);
|
||||
assert(A3<int>::move_called == false);
|
||||
assert(a2 == a1);
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// scoped_allocator_adaptor();
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A a;
|
||||
assert(a.outer_allocator() == A1<int>());
|
||||
assert(a.inner_allocator() == a);
|
||||
assert(A1<int>::copy_called == false);
|
||||
assert(A1<int>::move_called == false);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
A a;
|
||||
assert(a.outer_allocator() == A1<int>());
|
||||
assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>());
|
||||
assert(A1<int>::copy_called == false);
|
||||
assert(A1<int>::move_called == false);
|
||||
assert(A2<int>::copy_called == false);
|
||||
assert(A2<int>::move_called == false);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a;
|
||||
assert(a.outer_allocator() == A1<int>());
|
||||
assert((a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>, A3<int>>()));
|
||||
assert(A1<int>::copy_called == false);
|
||||
assert(A1<int>::move_called == false);
|
||||
assert(A2<int>::copy_called == false);
|
||||
assert(A2<int>::move_called == false);
|
||||
assert(A3<int>::copy_called == false);
|
||||
assert(A3<int>::move_called == false);
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// pointer allocate(size_type n);
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A a;
|
||||
A1<int>::allocate_called = false;
|
||||
assert(a.allocate(10) == (int*)10);
|
||||
assert(A1<int>::allocate_called == true);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
A a;
|
||||
A1<int>::allocate_called = false;
|
||||
assert(a.allocate(10) == (int*)10);
|
||||
assert(A1<int>::allocate_called == true);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a;
|
||||
A1<int>::allocate_called = false;
|
||||
assert(a.allocate(10) == (int*)10);
|
||||
assert(A1<int>::allocate_called == true);
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// pointer allocate(size_type n, const_void_pointer hint);
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A a;
|
||||
A1<int>::allocate_called = false;
|
||||
assert(a.allocate(10, (const void*)0) == (int*)10);
|
||||
assert(A1<int>::allocate_called == true);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
A a;
|
||||
A1<int>::allocate_called = false;
|
||||
assert(a.allocate(10, (const void*)10) == (int*)10);
|
||||
assert(A1<int>::allocate_called == true);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a;
|
||||
A1<int>::allocate_called = false;
|
||||
assert(a.allocate(10, (const void*)20) == (int*)10);
|
||||
assert(A1<int>::allocate_called == true);
|
||||
}
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A2<int>> A;
|
||||
A a;
|
||||
A2<int>::allocate_called = false;
|
||||
assert(a.allocate(10, (const void*)0) == (int*)0);
|
||||
assert(A2<int>::allocate_called == true);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A2<int>, A2<int>> A;
|
||||
A a;
|
||||
A2<int>::allocate_called = false;
|
||||
assert(a.allocate(10, (const void*)10) == (int*)10);
|
||||
assert(A2<int>::allocate_called == true);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A2<int>, A2<int>, A3<int>> A;
|
||||
A a;
|
||||
A2<int>::allocate_called = false;
|
||||
assert(a.allocate(10, (const void*)20) == (int*)20);
|
||||
assert(A2<int>::allocate_called == true);
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,193 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// template <class T, class... Args> void construct(T* p, Args&&... args);
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
struct B
|
||||
{
|
||||
static bool constructed;
|
||||
|
||||
typedef A1<B> allocator_type;
|
||||
|
||||
explicit B(std::allocator_arg_t, const allocator_type& a, int i)
|
||||
{
|
||||
assert(a.id() == 5);
|
||||
assert(i == 6);
|
||||
constructed = true;
|
||||
}
|
||||
};
|
||||
|
||||
bool B::constructed = false;
|
||||
|
||||
struct C
|
||||
{
|
||||
static bool constructed;
|
||||
|
||||
typedef std::scoped_allocator_adaptor<A2<C>> allocator_type;
|
||||
|
||||
explicit C(std::allocator_arg_t, const allocator_type& a, int i)
|
||||
{
|
||||
assert(a.id() == 7);
|
||||
assert(i == 8);
|
||||
constructed = true;
|
||||
}
|
||||
};
|
||||
|
||||
bool C::constructed = false;
|
||||
|
||||
struct D
|
||||
{
|
||||
static bool constructed;
|
||||
|
||||
typedef std::scoped_allocator_adaptor<A2<D>> allocator_type;
|
||||
|
||||
explicit D(int i, int j, const allocator_type& a)
|
||||
{
|
||||
assert(i == 1);
|
||||
assert(j == 2);
|
||||
assert(a.id() == 3);
|
||||
constructed = true;
|
||||
}
|
||||
};
|
||||
|
||||
bool D::constructed = false;
|
||||
|
||||
struct E
|
||||
{
|
||||
static bool constructed;
|
||||
|
||||
typedef std::scoped_allocator_adaptor<A1<E>> allocator_type;
|
||||
|
||||
explicit E(int i, int j, const allocator_type& a)
|
||||
{
|
||||
assert(i == 1);
|
||||
assert(j == 2);
|
||||
assert(a.id() == 50);
|
||||
constructed = true;
|
||||
}
|
||||
};
|
||||
|
||||
bool E::constructed = false;
|
||||
|
||||
struct F
|
||||
{
|
||||
static bool constructed;
|
||||
|
||||
typedef std::scoped_allocator_adaptor<A2<F>> allocator_type;
|
||||
|
||||
explicit F(int i, int j)
|
||||
{
|
||||
assert(i == 1);
|
||||
assert(j == 2);
|
||||
}
|
||||
|
||||
explicit F(int i, int j, const allocator_type& a)
|
||||
{
|
||||
assert(i == 1);
|
||||
assert(j == 2);
|
||||
assert(a.id() == 50);
|
||||
constructed = true;
|
||||
}
|
||||
};
|
||||
|
||||
bool F::constructed = false;
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<std::string>> A;
|
||||
A a;
|
||||
char buf[100];
|
||||
typedef std::string S;
|
||||
S* s = (S*)buf;
|
||||
a.construct(s, 4, 'c');
|
||||
assert(*s == "cccc");
|
||||
s->~S();
|
||||
}
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<B>> A;
|
||||
A a(A1<B>(5));
|
||||
char buf[100];
|
||||
typedef B S;
|
||||
S* s = (S*)buf;
|
||||
a.construct(s, 6);
|
||||
assert(S::constructed);
|
||||
s->~S();
|
||||
}
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<C>> A;
|
||||
A a(A1<int>(5), A2<C>(7));
|
||||
char buf[100];
|
||||
typedef C S;
|
||||
S* s = (S*)buf;
|
||||
a.construct(s, 8);
|
||||
assert(S::constructed);
|
||||
s->~S();
|
||||
}
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<D>> A;
|
||||
A a(A1<int>(5), A2<D>(3));
|
||||
char buf[100];
|
||||
typedef D S;
|
||||
S* s = (S*)buf;
|
||||
a.construct(s, 1, 2);
|
||||
assert(S::constructed);
|
||||
s->~S();
|
||||
}
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A3<E>, A2<E>> K;
|
||||
typedef std::scoped_allocator_adaptor<K, A1<E>> A;
|
||||
A a(K(), A1<E>(50));
|
||||
char buf[100];
|
||||
typedef E S;
|
||||
S* s = (S*)buf;
|
||||
A3<E>::constructed = false;
|
||||
a.construct(s, 1, 2);
|
||||
assert(S::constructed);
|
||||
assert(A3<E>::constructed);
|
||||
s->~S();
|
||||
}
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A3<F>, A2<F>> K;
|
||||
typedef std::scoped_allocator_adaptor<K, A1<F>> A;
|
||||
A a(K(), A1<F>(50));
|
||||
char buf[100];
|
||||
typedef F S;
|
||||
S* s = (S*)buf;
|
||||
A3<F>::constructed = false;
|
||||
a.construct(s, 1, 2);
|
||||
assert(!S::constructed);
|
||||
assert(A3<F>::constructed);
|
||||
s->~S();
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// void deallocate(pointer p, size_type n);
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A a;
|
||||
a.deallocate((int*)10, 20);
|
||||
assert((A1<int>::deallocate_called == std::pair<int*, std::size_t>((int*)10, 20)));
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
A a;
|
||||
a.deallocate((int*)10, 20);
|
||||
assert((A1<int>::deallocate_called == std::pair<int*, std::size_t>((int*)10, 20)));
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a;
|
||||
a.deallocate((int*)10, 20);
|
||||
assert((A1<int>::deallocate_called == std::pair<int*, std::size_t>((int*)10, 20)));
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// template <class T> void destroy(T* p);
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
struct B
|
||||
{
|
||||
static bool constructed;
|
||||
|
||||
B() {constructed = true;}
|
||||
~B() {constructed = false;}
|
||||
};
|
||||
|
||||
bool B::constructed = false;
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<B>> A;
|
||||
A a;
|
||||
char buf[100];
|
||||
typedef B S;
|
||||
S* s = (S*)buf;
|
||||
assert(!S::constructed);
|
||||
a.construct(s);
|
||||
assert(S::constructed);
|
||||
a.destroy(s);
|
||||
assert(!S::constructed);
|
||||
}
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A3<B>, A1<B>> A;
|
||||
A a;
|
||||
char buf[100];
|
||||
typedef B S;
|
||||
S* s = (S*)buf;
|
||||
assert(!S::constructed);
|
||||
assert(!A3<S>::constructed);
|
||||
assert(!A3<S>::destroy_called);
|
||||
a.construct(s);
|
||||
assert(S::constructed);
|
||||
assert(A3<S>::constructed);
|
||||
assert(!A3<S>::destroy_called);
|
||||
a.destroy(s);
|
||||
assert(!S::constructed);
|
||||
assert(A3<S>::constructed);
|
||||
assert(A3<S>::destroy_called);
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// inner_allocator_type& inner_allocator();
|
||||
// const inner_allocator_type& inner_allocator() const;
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A a(A1<int>(5));
|
||||
assert(a.inner_allocator() == a);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
A a(A1<int>(5), A2<int>(6));
|
||||
assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>(A2<int>(6)));
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a(A1<int>(5), A2<int>(6), A3<int>(8));
|
||||
assert((a.inner_allocator() ==
|
||||
std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(6), A3<int>(8))));
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// size_type max_size() const;
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
const A a(A1<int>(100));
|
||||
assert(a.max_size() == 100);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
const A a(A1<int>(20), A2<int>());
|
||||
assert(a.max_size() == 20);
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
const A a(A1<int>(200), A2<int>(), A3<int>());
|
||||
assert(a.max_size() == 200);
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// outer_allocator_type& outer_allocator();
|
||||
// const outer_allocator_type& outer_allocator() const;
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A a(A1<int>(5));
|
||||
assert(a.outer_allocator() == A1<int>(5));
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
A a(A1<int>(5), A2<int>(6));
|
||||
assert(a.outer_allocator() == A1<int>(5));
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a(A1<int>(5), A2<int>(6), A3<int>(8));
|
||||
assert(a.outer_allocator() == A1<int>(5));
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// scoped_allocator_adaptor select_on_container_copy_construction() const;
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A a1(A1<int>(3));
|
||||
assert(a1.outer_allocator().id() == 3);
|
||||
A a2 = std::allocator_traits<A>::select_on_container_copy_construction(a1);
|
||||
assert(a2.outer_allocator().id() == 3);
|
||||
}
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A3<int>> A;
|
||||
A a1(A3<int>(3));
|
||||
assert(a1.outer_allocator().id() == 3);
|
||||
A a2 = std::allocator_traits<A>::select_on_container_copy_construction(a1);
|
||||
assert(a2.outer_allocator().id() == -1);
|
||||
}
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a1(A1<int>(1), A2<int>(2), A3<int>(3));
|
||||
assert(a1.outer_allocator().id() == 1);
|
||||
assert(a1.inner_allocator().outer_allocator().id() == 2);
|
||||
assert(a1.inner_allocator().inner_allocator().outer_allocator().id() == 3);
|
||||
A a2 = std::allocator_traits<A>::select_on_container_copy_construction(a1);
|
||||
assert(a2.outer_allocator().id() == 1);
|
||||
assert(a2.inner_allocator().outer_allocator().id() == 2);
|
||||
assert(a2.inner_allocator().inner_allocator().outer_allocator().id() == -1);
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
// #include <memory>
|
||||
//
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc allocator_type;
|
||||
// typedef typename allocator_type::value_type
|
||||
// value_type;
|
||||
//
|
||||
// typedef Alloc::pointer | value_type* pointer;
|
||||
// typedef Alloc::const_pointer
|
||||
// | pointer_traits<pointer>::rebind<const value_type>
|
||||
// const_pointer;
|
||||
// typedef Alloc::void_pointer
|
||||
// | pointer_traits<pointer>::rebind<void>
|
||||
// void_pointer;
|
||||
// typedef Alloc::const_void_pointer
|
||||
// | pointer_traits<pointer>::rebind<const void>
|
||||
// const_void_pointer;
|
||||
|
||||
template <typename Alloc>
|
||||
void test_pointer()
|
||||
{
|
||||
typename std::allocator_traits<Alloc>::pointer vp;
|
||||
typename std::allocator_traits<Alloc>::const_pointer cvp;
|
||||
|
||||
static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp != vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp > vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp >= vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp < vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp <= vp)>::value, "");
|
||||
|
||||
static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp == vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp != vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp > cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp > vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, "");
|
||||
|
||||
static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
|
||||
}
|
||||
|
||||
template <typename Alloc>
|
||||
void test_void_pointer()
|
||||
{
|
||||
typename std::allocator_traits<Alloc>::void_pointer vp;
|
||||
typename std::allocator_traits<Alloc>::const_void_pointer cvp;
|
||||
|
||||
static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp != vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp > vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp >= vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp < vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp <= vp)>::value, "");
|
||||
|
||||
static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp == vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp != vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp > cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp > vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, "");
|
||||
|
||||
static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
|
||||
}
|
||||
|
||||
struct Foo { int x; };
|
||||
|
||||
int main()
|
||||
{
|
||||
test_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> ();
|
||||
test_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> ();
|
||||
test_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> ();
|
||||
|
||||
test_void_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> ();
|
||||
test_void_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> ();
|
||||
test_void_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> ();
|
||||
}
|
||||
#else
|
||||
int main() {}
|
||||
#endif
|
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// typedef see below inner_allocator_type;
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <type_traits>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::inner_allocator_type,
|
||||
std::scoped_allocator_adaptor<A1<int>>>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>, A2<int>>::inner_allocator_type,
|
||||
std::scoped_allocator_adaptor<A2<int>>>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::inner_allocator_type,
|
||||
std::scoped_allocator_adaptor<A2<int>, A3<int>>>::value), "");
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// typedef see below propagate_on_container_copy_assignment;
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <type_traits>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::propagate_on_container_copy_assignment,
|
||||
std::false_type>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>, A2<int>>::propagate_on_container_copy_assignment,
|
||||
std::false_type>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_copy_assignment,
|
||||
std::true_type>::value), "");
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// typedef see below propagate_on_container_move_assignment;
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <type_traits>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::propagate_on_container_move_assignment,
|
||||
std::false_type>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>, A2<int>>::propagate_on_container_move_assignment,
|
||||
std::true_type>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_move_assignment,
|
||||
std::true_type>::value), "");
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// typedef see below propagate_on_container_swap;
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <type_traits>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::propagate_on_container_swap,
|
||||
std::false_type>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>, A2<int>>::propagate_on_container_swap,
|
||||
std::false_type>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_swap,
|
||||
std::true_type>::value), "");
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
|
||||
// template <class OuterA1, class OuterA2, class... InnerAllocs>
|
||||
// bool
|
||||
// operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
||||
// const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b);
|
||||
//
|
||||
// template <class OuterA1, class OuterA2, class... InnerAllocs>
|
||||
// bool
|
||||
// operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
||||
// const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b);
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <cassert>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>> A;
|
||||
A a1(A1<int>(3));
|
||||
A a2 = a1;
|
||||
assert(a2 == a1);
|
||||
assert(!(a2 != a1));
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
|
||||
A a1(A1<int>(4), A2<int>(5));
|
||||
A a2 = a1;
|
||||
assert(a2 == a1);
|
||||
assert(!(a2 != a1));
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a1(A1<int>(4), A2<int>(5), A3<int>(6));
|
||||
A a2 = a1;
|
||||
assert(a2 == a1);
|
||||
assert(!(a2 != a1));
|
||||
}
|
||||
{
|
||||
typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
|
||||
A a1(A1<int>(4), A2<int>(5), A3<int>(6));
|
||||
A a2(A1<int>(4), A2<int>(5), A3<int>(5));
|
||||
assert(a2 != a1);
|
||||
assert(!(a2 == a1));
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
102
test/std/utilities/allocator.adaptor/types.pass.cpp
Normal file
102
test/std/utilities/allocator.adaptor/types.pass.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 OuterAlloc, class... InnerAllocs>
|
||||
// class scoped_allocator_adaptor
|
||||
// : public OuterAlloc
|
||||
// {
|
||||
// public:
|
||||
// typedef OuterAlloc outer_allocator_type;
|
||||
// typedef typename OuterTraits::size_type size_type;
|
||||
// typedef typename OuterTraits::difference_type difference_type;
|
||||
// typedef typename OuterTraits::pointer pointer;
|
||||
// typedef typename OuterTraits::const_pointer const_pointer;
|
||||
// typedef typename OuterTraits::void_pointer void_pointer;
|
||||
// typedef typename OuterTraits::const_void_pointer const_void_pointer;
|
||||
// };
|
||||
|
||||
#include <scoped_allocator>
|
||||
#include <type_traits>
|
||||
|
||||
#include "allocators.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
static_assert((std::is_base_of<
|
||||
A1<int>,
|
||||
std::scoped_allocator_adaptor<A1<int>>
|
||||
>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::outer_allocator_type,
|
||||
A1<int>>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::size_type,
|
||||
std::make_unsigned<std::ptrdiff_t>::type>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::difference_type,
|
||||
std::ptrdiff_t>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::pointer,
|
||||
int*>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::const_pointer,
|
||||
const int*>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::void_pointer,
|
||||
void*>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A1<int>>::const_void_pointer,
|
||||
const void*>::value), "");
|
||||
|
||||
static_assert((std::is_base_of<
|
||||
A2<int>,
|
||||
std::scoped_allocator_adaptor<A2<int>, A1<int>>
|
||||
>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A2<int>, A1<int>>::outer_allocator_type,
|
||||
A2<int>>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A2<int>, A1<int>>::size_type,
|
||||
unsigned>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A2<int>, A1<int>>::difference_type,
|
||||
int>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A2<int>, A1<int>>::pointer,
|
||||
int*>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A2<int>, A1<int>>::const_pointer,
|
||||
const int*>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A2<int>, A1<int>>::void_pointer,
|
||||
void*>::value), "");
|
||||
|
||||
static_assert((std::is_same<
|
||||
std::scoped_allocator_adaptor<A2<int>, A1<int>>::const_void_pointer,
|
||||
const void*>::value), "");
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
37
test/std/utilities/date.time/tested_elsewhere.pass.cpp
Normal file
37
test/std/utilities/date.time/tested_elsewhere.pass.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <ctime>
|
||||
#include <type_traits>
|
||||
|
||||
#ifndef NULL
|
||||
#error NULL not defined
|
||||
#endif
|
||||
|
||||
#ifndef CLOCKS_PER_SEC
|
||||
#error CLOCKS_PER_SEC not defined
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
std::clock_t c = 0;
|
||||
std::size_t s = 0;
|
||||
std::time_t t = 0;
|
||||
std::tm tm = {0};
|
||||
char str[3];
|
||||
static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), "");
|
||||
static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), "");
|
||||
static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), "");
|
||||
static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), "");
|
||||
static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), "");
|
||||
static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), "");
|
||||
static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), "");
|
||||
static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), "");
|
||||
static_assert((std::is_same<decltype(std::strftime(str,s,"",&tm)), std::size_t>::value), "");
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// divides
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::divides<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
|
||||
assert(f(36, 4) == 9);
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::divides<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f2(36, 4) == 9);
|
||||
assert(f2(36.0, 4) == 9);
|
||||
assert(f2(18, 4.0) == 4.5); // exact in binary
|
||||
|
||||
constexpr int foo = std::divides<int> () (3, 2);
|
||||
static_assert ( foo == 1, "" );
|
||||
|
||||
constexpr int bar = std::divides<> () (3.0, 2);
|
||||
static_assert ( bar == 1, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// minus
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::minus<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
|
||||
assert(f(3, 2) == 1);
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::minus<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f2(3,2) == 1);
|
||||
assert(f2(3.0, 2) == 1);
|
||||
assert(f2(3, 2.5) == 0.5);
|
||||
|
||||
constexpr int foo = std::minus<int> () (3, 2);
|
||||
static_assert ( foo == 1, "" );
|
||||
|
||||
constexpr int bar = std::minus<> () (3.0, 2);
|
||||
static_assert ( bar == 1, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// modulus
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::modulus<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
|
||||
assert(f(36, 8) == 4);
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::modulus<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f2(36, 8) == 4);
|
||||
assert(f2(36L, 8) == 4);
|
||||
assert(f2(36, 8L) == 4);
|
||||
|
||||
constexpr int foo = std::modulus<int> () (3, 2);
|
||||
static_assert ( foo == 1, "" );
|
||||
|
||||
constexpr int bar = std::modulus<> () (3L, 2);
|
||||
static_assert ( bar == 1, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// multiplies
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::multiplies<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
|
||||
assert(f(3, 2) == 6);
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::multiplies<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f2(3,2) == 6);
|
||||
assert(f2(3.0, 2) == 6);
|
||||
assert(f2(3, 2.5) == 7.5); // exact in binary
|
||||
|
||||
constexpr int foo = std::multiplies<int> () (3, 2);
|
||||
static_assert ( foo == 6, "" );
|
||||
|
||||
constexpr int bar = std::multiplies<> () (3.0, 2);
|
||||
static_assert ( bar == 6, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// negate
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::negate<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::unary_function<int, int>, F>::value), "");
|
||||
assert(f(36) == -36);
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::negate<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f2(36) == -36);
|
||||
assert(f2(36L) == -36);
|
||||
assert(f2(36.0) == -36);
|
||||
|
||||
constexpr int foo = std::negate<int> () (3);
|
||||
static_assert ( foo == -3, "" );
|
||||
|
||||
constexpr int bar = std::negate<> () (3.0);
|
||||
static_assert ( bar == -3, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// plus
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::plus<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
|
||||
assert(f(3, 2) == 5);
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::plus<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f2(3,2) == 5);
|
||||
assert(f2(3.0, 2) == 5);
|
||||
assert(f2(3, 2.5) == 5.5);
|
||||
|
||||
constexpr int foo = std::plus<int> () (3, 2);
|
||||
static_assert ( foo == 5, "" );
|
||||
|
||||
constexpr int bar = std::plus<> () (3.0, 2);
|
||||
static_assert ( bar == 5, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
template <class _Tp>
|
||||
struct is_transparent
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::is_transparent* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
|
||||
|
||||
int main () {
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
static_assert ( !is_transparent<std::plus<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::plus<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::plus<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::plus<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::minus<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::minus<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::minus<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::minus<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::multiplies<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::multiplies<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::multiplies<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::multiplies<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::divides<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::divides<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::divides<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::divides<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::modulus<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::modulus<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::modulus<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::modulus<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::negate<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::negate<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::negate<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::negate<>>::value, "" );
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
// http://llvm.org/bugs/show_bug.cgi?id=16385
|
||||
|
||||
#include <functional>
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
|
||||
float _pow(float a, float b)
|
||||
{
|
||||
return std::pow(a, b);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::function<float(float, float)> fnc = _pow;
|
||||
auto task = std::bind(fnc, 2.f, 4.f);
|
||||
auto task2(task);
|
||||
assert(task() == 16);
|
||||
assert(task2() == 16);
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
template <class R, class F>
|
||||
void
|
||||
test(F f, R expected)
|
||||
{
|
||||
assert(f() == expected);
|
||||
}
|
||||
|
||||
template <class R, class F>
|
||||
void
|
||||
test_const(const F& f, R expected)
|
||||
{
|
||||
assert(f() == expected);
|
||||
}
|
||||
|
||||
int f() {return 1;}
|
||||
|
||||
struct A_int_0
|
||||
{
|
||||
int operator()() {return 4;}
|
||||
int operator()() const {return 5;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
test(std::bind(f), 1);
|
||||
test(std::bind(&f), 1);
|
||||
test(std::bind(A_int_0()), 4);
|
||||
test_const(std::bind(A_int_0()), 5);
|
||||
|
||||
test(std::bind<int>(f), 1);
|
||||
test(std::bind<int>(&f), 1);
|
||||
test(std::bind<int>(A_int_0()), 4);
|
||||
test_const(std::bind<int>(A_int_0()), 5);
|
||||
}
|
@@ -0,0 +1,286 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int count = 0;
|
||||
|
||||
// 1 arg, return void
|
||||
|
||||
void f_void_1(int i)
|
||||
{
|
||||
count += i;
|
||||
}
|
||||
|
||||
struct A_void_1
|
||||
{
|
||||
void operator()(int i)
|
||||
{
|
||||
count += i;
|
||||
}
|
||||
|
||||
void mem1() {++count;}
|
||||
void mem2() const {count += 2;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_1()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
int i = 2;
|
||||
std::bind(f_void_1, _1)(i);
|
||||
assert(count == save_count + 2);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
int i = 2;
|
||||
std::bind(f_void_1, i)();
|
||||
assert(count == save_count + 2);
|
||||
save_count = count;
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
void (*fp)(int) = f_void_1;
|
||||
int i = 3;
|
||||
std::bind(fp, _1)(i);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (*fp)(int) = f_void_1;
|
||||
int i = 3;
|
||||
std::bind(fp, i)();
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
// functor
|
||||
{
|
||||
A_void_1 a0;
|
||||
int i = 4;
|
||||
std::bind(a0, _1)(i);
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
A_void_1 a0;
|
||||
int i = 4;
|
||||
std::bind(a0, i)();
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
void (A_void_1::*fp)() = &A_void_1::mem1;
|
||||
A_void_1 a;
|
||||
std::bind(fp, _1)(a);
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
A_void_1* ap = &a;
|
||||
std::bind(fp, _1)(ap);
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (A_void_1::*fp)() = &A_void_1::mem1;
|
||||
A_void_1 a;
|
||||
std::bind(fp, a)();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
A_void_1* ap = &a;
|
||||
std::bind(fp, ap)();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
void (A_void_1::*fp)() const = &A_void_1::mem2;
|
||||
A_void_1 a;
|
||||
std::bind(fp, _1)(a);
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
A_void_1* ap = &a;
|
||||
std::bind(fp, _1)(ap);
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (A_void_1::*fp)() const = &A_void_1::mem2;
|
||||
A_void_1 a;
|
||||
std::bind(fp, a)();
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
A_void_1* ap = &a;
|
||||
std::bind(fp, ap)();
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
// 1 arg, return int
|
||||
|
||||
int f_int_1(int i)
|
||||
{
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
struct A_int_1
|
||||
{
|
||||
A_int_1() : data_(5) {}
|
||||
int operator()(int i)
|
||||
{
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
int mem1() {return 3;}
|
||||
int mem2() const {return 4;}
|
||||
int data_;
|
||||
};
|
||||
|
||||
void
|
||||
test_int_1()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
// function
|
||||
{
|
||||
int i = 2;
|
||||
assert(std::bind(f_int_1, _1)(i) == 3);
|
||||
assert(std::bind(f_int_1, i)() == 3);
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
int (*fp)(int) = f_int_1;
|
||||
int i = 3;
|
||||
assert(std::bind(fp, _1)(i) == 4);
|
||||
assert(std::bind(fp, i)() == 4);
|
||||
}
|
||||
// functor
|
||||
{
|
||||
int i = 4;
|
||||
assert(std::bind(A_int_1(), _1)(i) == 3);
|
||||
assert(std::bind(A_int_1(), i)() == 3);
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::mem1, _1)(a) == 3);
|
||||
assert(std::bind(&A_int_1::mem1, a)() == 3);
|
||||
A_int_1* ap = &a;
|
||||
assert(std::bind(&A_int_1::mem1, _1)(ap) == 3);
|
||||
assert(std::bind(&A_int_1::mem1, ap)() == 3);
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::mem2, _1)(A_int_1()) == 4);
|
||||
assert(std::bind(&A_int_1::mem2, A_int_1())() == 4);
|
||||
A_int_1* ap = &a;
|
||||
assert(std::bind(&A_int_1::mem2, _1)(ap) == 4);
|
||||
assert(std::bind(&A_int_1::mem2, ap)() == 4);
|
||||
}
|
||||
// member data pointer
|
||||
{
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::data_, _1)(a) == 5);
|
||||
assert(std::bind(&A_int_1::data_, a)() == 5);
|
||||
A_int_1* ap = &a;
|
||||
assert(std::bind(&A_int_1::data_, _1)(a) == 5);
|
||||
std::bind(&A_int_1::data_, _1)(a) = 6;
|
||||
assert(std::bind(&A_int_1::data_, _1)(a) == 6);
|
||||
assert(std::bind(&A_int_1::data_, _1)(ap) == 6);
|
||||
std::bind(&A_int_1::data_, _1)(ap) = 7;
|
||||
assert(std::bind(&A_int_1::data_, _1)(ap) == 7);
|
||||
}
|
||||
}
|
||||
|
||||
// 2 arg, return void
|
||||
|
||||
void f_void_2(int i, int j)
|
||||
{
|
||||
count += i+j;
|
||||
}
|
||||
|
||||
struct A_void_2
|
||||
{
|
||||
void operator()(int i, int j)
|
||||
{
|
||||
count += i+j;
|
||||
}
|
||||
|
||||
void mem1(int i) {count += i;}
|
||||
void mem2(int i) const {count += i;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_2()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
int i = 2;
|
||||
int j = 3;
|
||||
std::bind(f_void_2, _1, _2)(i, j);
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
std::bind(f_void_2, i, _1)(j);
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
std::bind(f_void_2, i, j)();
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
int j = 3;
|
||||
std::bind(&A_void_2::mem1, _1, _2)(A_void_2(), j);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
std::bind(&A_void_2::mem1, _2, _1)(j, A_void_2());
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
struct TFENode
|
||||
{
|
||||
bool foo(unsigned long long) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
test3()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
const auto f = bind(&TFENode::foo, _1, 0UL);
|
||||
const TFENode n = TFENode{};
|
||||
bool b = f(n);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_void_1();
|
||||
test_int_1();
|
||||
test_void_2();
|
||||
}
|
@@ -0,0 +1,266 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int count = 0;
|
||||
|
||||
// 1 arg, return void
|
||||
|
||||
void f_void_1(int i)
|
||||
{
|
||||
count += i;
|
||||
}
|
||||
|
||||
struct A_void_1
|
||||
{
|
||||
void operator()(int i)
|
||||
{
|
||||
count += i;
|
||||
}
|
||||
|
||||
void mem1() {++count;}
|
||||
void mem2() const {count += 2;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_1()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
std::bind(f_void_1, _1)(2);
|
||||
assert(count == save_count + 2);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
std::bind(f_void_1, 2)();
|
||||
assert(count == save_count + 2);
|
||||
save_count = count;
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
void (*fp)(int) = f_void_1;
|
||||
std::bind(fp, _1)(3);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (*fp)(int) = f_void_1;
|
||||
std::bind(fp, 3)();
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
// functor
|
||||
{
|
||||
A_void_1 a0;
|
||||
std::bind(a0, _1)(4);
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
A_void_1 a0;
|
||||
std::bind(a0, 4)();
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
void (A_void_1::*fp)() = &A_void_1::mem1;
|
||||
std::bind(fp, _1)(A_void_1());
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
A_void_1 a;
|
||||
std::bind(fp, _1)(&a);
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (A_void_1::*fp)() = &A_void_1::mem1;
|
||||
std::bind(fp, A_void_1())();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
A_void_1 a;
|
||||
std::bind(fp, &a)();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
void (A_void_1::*fp)() const = &A_void_1::mem2;
|
||||
std::bind(fp, _1)(A_void_1());
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
A_void_1 a;
|
||||
std::bind(fp, _1)(&a);
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (A_void_1::*fp)() const = &A_void_1::mem2;
|
||||
std::bind(fp, A_void_1())();
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
A_void_1 a;
|
||||
std::bind(fp, &a)();
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
// 1 arg, return int
|
||||
|
||||
int f_int_1(int i)
|
||||
{
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
struct A_int_1
|
||||
{
|
||||
A_int_1() : data_(5) {}
|
||||
int operator()(int i)
|
||||
{
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
int mem1() {return 3;}
|
||||
int mem2() const {return 4;}
|
||||
int data_;
|
||||
};
|
||||
|
||||
void
|
||||
test_int_1()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
// function
|
||||
{
|
||||
assert(std::bind(f_int_1, _1)(2) == 3);
|
||||
assert(std::bind(f_int_1, 2)() == 3);
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
int (*fp)(int) = f_int_1;
|
||||
assert(std::bind(fp, _1)(3) == 4);
|
||||
assert(std::bind(fp, 3)() == 4);
|
||||
}
|
||||
// functor
|
||||
{
|
||||
assert(std::bind(A_int_1(), _1)(4) == 3);
|
||||
assert(std::bind(A_int_1(), 4)() == 3);
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
assert(std::bind(&A_int_1::mem1, _1)(A_int_1()) == 3);
|
||||
assert(std::bind(&A_int_1::mem1, A_int_1())() == 3);
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::mem1, _1)(&a) == 3);
|
||||
assert(std::bind(&A_int_1::mem1, &a)() == 3);
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
assert(std::bind(&A_int_1::mem2, _1)(A_int_1()) == 4);
|
||||
assert(std::bind(&A_int_1::mem2, A_int_1())() == 4);
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::mem2, _1)(&a) == 4);
|
||||
assert(std::bind(&A_int_1::mem2, &a)() == 4);
|
||||
}
|
||||
// member data pointer
|
||||
{
|
||||
assert(std::bind(&A_int_1::data_, _1)(A_int_1()) == 5);
|
||||
assert(std::bind(&A_int_1::data_, A_int_1())() == 5);
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::data_, _1)(a) == 5);
|
||||
std::bind(&A_int_1::data_, _1)(a) = 6;
|
||||
assert(std::bind(&A_int_1::data_, _1)(a) == 6);
|
||||
assert(std::bind(&A_int_1::data_, _1)(&a) == 6);
|
||||
std::bind(&A_int_1::data_, _1)(&a) = 7;
|
||||
assert(std::bind(&A_int_1::data_, _1)(&a) == 7);
|
||||
}
|
||||
}
|
||||
|
||||
// 2 arg, return void
|
||||
|
||||
void f_void_2(int i, int j)
|
||||
{
|
||||
count += i+j;
|
||||
}
|
||||
|
||||
struct A_void_2
|
||||
{
|
||||
void operator()(int i, int j)
|
||||
{
|
||||
count += i+j;
|
||||
}
|
||||
|
||||
void mem1(int i) {count += i;}
|
||||
void mem2(int i) const {count += i;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_2()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
std::bind(f_void_2, _1, _2)(2, 3);
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
std::bind(f_void_2, 2, _1)(3);
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
std::bind(f_void_2, 2, 3)();
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
std::bind(&A_void_2::mem1, _1, _2)(A_void_2(), 3);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
std::bind(&A_void_2::mem1, _2, _1)(3, A_void_2());
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
int f_nested(int i)
|
||||
{
|
||||
return i+1;
|
||||
}
|
||||
|
||||
int g_nested(int i)
|
||||
{
|
||||
return i*10;
|
||||
}
|
||||
|
||||
void test_nested()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
assert(std::bind(f_nested, std::bind(g_nested, _1))(3) == 31);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_void_1();
|
||||
test_int_1();
|
||||
test_void_2();
|
||||
test_nested();
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int count = 0;
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test(F f)
|
||||
{
|
||||
int save_count = count;
|
||||
f();
|
||||
assert(count == save_count + 1);
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test_const(const F& f)
|
||||
{
|
||||
int save_count = count;
|
||||
f();
|
||||
assert(count == save_count + 2);
|
||||
}
|
||||
|
||||
void f() {++count;}
|
||||
|
||||
struct A_int_0
|
||||
{
|
||||
void operator()() {++count;}
|
||||
void operator()() const {count += 2;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
test(std::bind(f));
|
||||
test(std::bind(&f));
|
||||
test(std::bind(A_int_0()));
|
||||
test_const(std::bind(A_int_0()));
|
||||
|
||||
test(std::bind<void>(f));
|
||||
test(std::bind<void>(&f));
|
||||
test(std::bind<void>(A_int_0()));
|
||||
test_const(std::bind<void>(A_int_0()));
|
||||
}
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
// http://llvm.org/bugs/show_bug.cgi?id=16343
|
||||
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
struct power
|
||||
{
|
||||
template <typename T>
|
||||
T
|
||||
operator()(T a, T b)
|
||||
{
|
||||
return std::pow(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
struct plus_one
|
||||
{
|
||||
template <typename T>
|
||||
T
|
||||
operator()(T a)
|
||||
{
|
||||
return a + 1;
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using std::placeholders::_1;
|
||||
|
||||
auto g = std::bind(power(), 2, _1);
|
||||
assert(g(5) == 32);
|
||||
assert(std::bind(plus_one(), g)(5) == 33);
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<class T> struct is_bind_expression
|
||||
|
||||
#include <functional>
|
||||
|
||||
template <bool Expected, class T>
|
||||
void
|
||||
test(const T&)
|
||||
{
|
||||
static_assert(std::is_bind_expression<T>::value == Expected, "");
|
||||
}
|
||||
|
||||
struct C {};
|
||||
|
||||
int main()
|
||||
{
|
||||
test<true>(std::bind(C()));
|
||||
test<true>(std::bind(C(), std::placeholders::_2));
|
||||
test<true>(std::bind<int>(C()));
|
||||
test<false>(1);
|
||||
test<false>(std::placeholders::_2);
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// struct is_placeholder
|
||||
|
||||
#include <functional>
|
||||
|
||||
template <int Expected, class T>
|
||||
void
|
||||
test(const T&)
|
||||
{
|
||||
static_assert(std::is_placeholder<T>::value == Expected, "");
|
||||
}
|
||||
|
||||
struct C {};
|
||||
|
||||
int main()
|
||||
{
|
||||
test<1>(std::placeholders::_1);
|
||||
test<2>(std::placeholders::_2);
|
||||
test<3>(std::placeholders::_3);
|
||||
test<4>(std::placeholders::_4);
|
||||
test<5>(std::placeholders::_5);
|
||||
test<6>(std::placeholders::_6);
|
||||
test<7>(std::placeholders::_7);
|
||||
test<8>(std::placeholders::_8);
|
||||
test<9>(std::placeholders::_9);
|
||||
test<10>(std::placeholders::_10);
|
||||
test<0>(4);
|
||||
test<0>(5.5);
|
||||
test<0>('a');
|
||||
test<0>(C());
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// placeholders
|
||||
|
||||
#include <functional>
|
||||
|
||||
template <class T>
|
||||
void
|
||||
test(const T& t)
|
||||
{
|
||||
T t2;
|
||||
T t3 = t;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test(std::placeholders::_1);
|
||||
test(std::placeholders::_2);
|
||||
test(std::placeholders::_3);
|
||||
test(std::placeholders::_4);
|
||||
test(std::placeholders::_5);
|
||||
test(std::placeholders::_6);
|
||||
test(std::placeholders::_7);
|
||||
test(std::placeholders::_8);
|
||||
test(std::placeholders::_9);
|
||||
test(std::placeholders::_10);
|
||||
}
|
@@ -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()
|
||||
{
|
||||
}
|
@@ -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()
|
||||
{
|
||||
}
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// bit_and
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::bit_and<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
|
||||
assert(f(0xEA95, 0xEA95) == 0xEA95);
|
||||
assert(f(0xEA95, 0x58D3) == 0x4891);
|
||||
assert(f(0x58D3, 0xEA95) == 0x4891);
|
||||
assert(f(0x58D3, 0) == 0);
|
||||
assert(f(0xFFFF, 0x58D3) == 0x58D3);
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::bit_and<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f2(0xEA95, 0xEA95) == 0xEA95);
|
||||
assert(f2(0xEA95L, 0xEA95) == 0xEA95);
|
||||
assert(f2(0xEA95, 0xEA95L) == 0xEA95);
|
||||
|
||||
assert(f2(0xEA95, 0x58D3) == 0x4891);
|
||||
assert(f2(0xEA95L, 0x58D3) == 0x4891);
|
||||
assert(f2(0xEA95, 0x58D3L) == 0x4891);
|
||||
|
||||
assert(f2(0x58D3, 0xEA95) == 0x4891);
|
||||
assert(f2(0x58D3L, 0xEA95) == 0x4891);
|
||||
assert(f2(0x58D3, 0xEA95L) == 0x4891);
|
||||
|
||||
assert(f2(0x58D3, 0) == 0);
|
||||
assert(f2(0x58D3L, 0) == 0);
|
||||
assert(f2(0x58D3, 0L) == 0);
|
||||
|
||||
assert(f2(0xFFFF, 0x58D3) == 0x58D3);
|
||||
assert(f2(0xFFFFL, 0x58D3) == 0x58D3);
|
||||
assert(f2(0xFFFF, 0x58D3L) == 0x58D3);
|
||||
|
||||
constexpr int foo = std::bit_and<int> () (0x58D3, 0xEA95);
|
||||
static_assert ( foo == 0x4891, "" );
|
||||
|
||||
constexpr int bar = std::bit_and<> () (0x58D3L, 0xEA95);
|
||||
static_assert ( bar == 0x4891, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// bit_not
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::bit_not<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::unary_function<int, int>, F>::value), "");
|
||||
assert((f(0xEA95) & 0xFFFF ) == 0x156A);
|
||||
assert((f(0x58D3) & 0xFFFF ) == 0xA72C);
|
||||
assert((f(0) & 0xFFFF ) == 0xFFFF);
|
||||
assert((f(0xFFFF) & 0xFFFF ) == 0);
|
||||
|
||||
typedef std::bit_not<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert((f2(0xEA95) & 0xFFFF ) == 0x156A);
|
||||
assert((f2(0xEA95L) & 0xFFFF ) == 0x156A);
|
||||
assert((f2(0x58D3) & 0xFFFF ) == 0xA72C);
|
||||
assert((f2(0x58D3L) & 0xFFFF ) == 0xA72C);
|
||||
assert((f2(0) & 0xFFFF ) == 0xFFFF);
|
||||
assert((f2(0L) & 0xFFFF ) == 0xFFFF);
|
||||
assert((f2(0xFFFF) & 0xFFFF ) == 0);
|
||||
assert((f2(0xFFFFL) & 0xFFFF ) == 0);
|
||||
|
||||
constexpr int foo = std::bit_not<int> () (0xEA95) & 0xFFFF;
|
||||
static_assert ( foo == 0x156A, "" );
|
||||
|
||||
constexpr int bar = std::bit_not<> () (0xEA95) & 0xFFFF;
|
||||
static_assert ( bar == 0x156A, "" );
|
||||
#endif
|
||||
}
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// bit_or
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::bit_or<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
|
||||
assert(f(0xEA95, 0xEA95) == 0xEA95);
|
||||
assert(f(0xEA95, 0x58D3) == 0xFAD7);
|
||||
assert(f(0x58D3, 0xEA95) == 0xFAD7);
|
||||
assert(f(0x58D3, 0) == 0x58D3);
|
||||
assert(f(0xFFFF, 0x58D3) == 0xFFFF);
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::bit_or<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f2(0xEA95, 0xEA95) == 0xEA95);
|
||||
assert(f2(0xEA95L, 0xEA95) == 0xEA95);
|
||||
assert(f2(0xEA95, 0xEA95L) == 0xEA95);
|
||||
|
||||
assert(f2(0xEA95, 0x58D3) == 0xFAD7);
|
||||
assert(f2(0xEA95L, 0x58D3) == 0xFAD7);
|
||||
assert(f2(0xEA95, 0x58D3L) == 0xFAD7);
|
||||
|
||||
assert(f2(0x58D3, 0xEA95) == 0xFAD7);
|
||||
assert(f2(0x58D3L, 0xEA95) == 0xFAD7);
|
||||
assert(f2(0x58D3, 0xEA95L) == 0xFAD7);
|
||||
|
||||
assert(f2(0x58D3, 0) == 0x58D3);
|
||||
assert(f2(0x58D3L, 0) == 0x58D3);
|
||||
assert(f2(0x58D3, 0L) == 0x58D3);
|
||||
|
||||
assert(f2(0xFFFF, 0x58D3) == 0xFFFF);
|
||||
assert(f2(0xFFFFL, 0x58D3) == 0xFFFF);
|
||||
assert(f2(0xFFFF, 0x58D3L) == 0xFFFF);
|
||||
|
||||
constexpr int foo = std::bit_or<int> () (0x58D3, 0xEA95);
|
||||
static_assert ( foo == 0xFAD7, "" );
|
||||
|
||||
constexpr int bar = std::bit_or<> () (0x58D3L, 0xEA95);
|
||||
static_assert ( bar == 0xFAD7, "" );
|
||||
#endif
|
||||
}
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// bit_xor
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::bit_xor<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
|
||||
assert(f(0xEA95, 0xEA95) == 0);
|
||||
assert(f(0xEA95, 0x58D3) == 0xB246);
|
||||
assert(f(0x58D3, 0xEA95) == 0xB246);
|
||||
assert(f(0x58D3, 0) == 0x58D3);
|
||||
assert(f(0xFFFF, 0x58D3) == 0xA72C);
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::bit_xor<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f(0xEA95, 0xEA95) == 0);
|
||||
assert(f(0xEA95L, 0xEA95) == 0);
|
||||
assert(f(0xEA95, 0xEA95L) == 0);
|
||||
|
||||
assert(f(0xEA95, 0x58D3) == 0xB246);
|
||||
assert(f(0xEA95L, 0x58D3) == 0xB246);
|
||||
assert(f(0xEA95, 0x58D3L) == 0xB246);
|
||||
|
||||
assert(f(0x58D3, 0xEA95) == 0xB246);
|
||||
assert(f(0x58D3L, 0xEA95) == 0xB246);
|
||||
assert(f(0x58D3, 0xEA95L) == 0xB246);
|
||||
|
||||
assert(f(0x58D3, 0) == 0x58D3);
|
||||
assert(f(0x58D3L, 0) == 0x58D3);
|
||||
assert(f(0x58D3, 0L) == 0x58D3);
|
||||
|
||||
assert(f(0xFFFF, 0x58D3) == 0xA72C);
|
||||
assert(f(0xFFFFL, 0x58D3) == 0xA72C);
|
||||
assert(f(0xFFFF, 0x58D3L) == 0xA72C);
|
||||
|
||||
constexpr int foo = std::bit_xor<int> () (0x58D3, 0xEA95);
|
||||
static_assert ( foo == 0xB246, "" );
|
||||
|
||||
constexpr int bar = std::bit_xor<> () (0x58D3L, 0xEA95);
|
||||
static_assert ( bar == 0xB246, "" );
|
||||
#endif
|
||||
}
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
template <class _Tp>
|
||||
struct is_transparent
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::is_transparent* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
|
||||
|
||||
int main () {
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
static_assert ( !is_transparent<std::bit_and<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::bit_and<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::bit_and<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::bit_and<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::bit_or<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::bit_or<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::bit_or<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::bit_or<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::bit_xor<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::bit_xor<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::bit_xor<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::bit_xor<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::bit_not<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::bit_not<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::bit_not<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::bit_not<>>::value, "" );
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// equal_to
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::equal_to<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
|
||||
assert(f(36, 36));
|
||||
assert(!f(36, 6));
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::equal_to<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f2(36, 36));
|
||||
assert(!f2(36, 6));
|
||||
assert(f2(36, 36.0));
|
||||
assert(f2(36.0, 36L));
|
||||
|
||||
constexpr bool foo = std::equal_to<int> () (36, 36);
|
||||
static_assert ( foo, "" );
|
||||
|
||||
constexpr bool bar = std::equal_to<> () (36.0, 36);
|
||||
static_assert ( bar, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// greater
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::greater<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
|
||||
assert(!f(36, 36));
|
||||
assert(f(36, 6));
|
||||
assert(!f(6, 36));
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::greater<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(!f2(36, 36));
|
||||
assert(f2(36, 6));
|
||||
assert(!f2(6, 36));
|
||||
assert( f2(36, 6.0));
|
||||
assert( f2(36.0, 6));
|
||||
assert(!f2(6, 36.0));
|
||||
assert(!f2(6.0, 36));
|
||||
|
||||
constexpr bool foo = std::greater<int> () (36, 36);
|
||||
static_assert ( !foo, "" );
|
||||
|
||||
constexpr bool bar = std::greater<> () (36.0, 36);
|
||||
static_assert ( !bar, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// greater_equal
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::greater_equal<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
|
||||
assert(f(36, 36));
|
||||
assert(f(36, 6));
|
||||
assert(!f(6, 36));
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::greater_equal<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(f2(36, 36));
|
||||
assert(f2(36, 6));
|
||||
assert(!f2(6, 36));
|
||||
assert( f2(36, 6.0));
|
||||
assert( f2(36.0, 6));
|
||||
assert(!f2(6, 36.0));
|
||||
assert(!f2(6.0, 36));
|
||||
|
||||
constexpr bool foo = std::greater_equal<int> () (36, 36);
|
||||
static_assert ( foo, "" );
|
||||
|
||||
constexpr bool bar = std::greater_equal<> () (36.0, 36);
|
||||
static_assert ( bar, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// less
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::less<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
|
||||
assert(!f(36, 36));
|
||||
assert(!f(36, 6));
|
||||
assert(f(6, 36));
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::less<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(!f2(36, 36));
|
||||
assert(!f2(36, 6));
|
||||
assert( f2(6, 36));
|
||||
assert(!f2(36, 6.0));
|
||||
assert(!f2(36.0, 6));
|
||||
assert( f2(6, 36.0));
|
||||
assert( f2(6.0, 36));
|
||||
|
||||
constexpr bool foo = std::less<int> () (36, 36);
|
||||
static_assert ( !foo, "" );
|
||||
|
||||
constexpr bool bar = std::less<> () (36.0, 36);
|
||||
static_assert ( !bar, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// less_equal
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::less_equal<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
|
||||
assert(f(36, 36));
|
||||
assert(!f(36, 6));
|
||||
assert(f(6, 36));
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::less_equal<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert( f2(36, 36));
|
||||
assert(!f2(36, 6));
|
||||
assert( f2(6, 36));
|
||||
assert(!f2(36, 6.0));
|
||||
assert(!f2(36.0, 6));
|
||||
assert( f2(6, 36.0));
|
||||
assert( f2(6.0, 36));
|
||||
|
||||
constexpr bool foo = std::less_equal<int> () (36, 36);
|
||||
static_assert ( foo, "" );
|
||||
|
||||
constexpr bool bar = std::less_equal<> () (36.0, 36);
|
||||
static_assert ( bar, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// not_equal_to
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::not_equal_to<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
|
||||
assert(!f(36, 36));
|
||||
assert(f(36, 6));
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::not_equal_to<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(!f2(36, 36));
|
||||
assert( f2(36, 6));
|
||||
assert( f2(36, 6.0));
|
||||
assert( f2(36.0, 6));
|
||||
assert(!f2(36.0, 36));
|
||||
assert(!f2(36, 36.0));
|
||||
|
||||
constexpr bool foo = std::not_equal_to<int> () (36, 36);
|
||||
static_assert ( !foo, "" );
|
||||
|
||||
constexpr bool bar = std::not_equal_to<> () (36.0, 36);
|
||||
static_assert ( !bar, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
template <class _Tp>
|
||||
struct is_transparent
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::is_transparent* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
|
||||
|
||||
int main () {
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
static_assert ( !is_transparent<std::less<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::less<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::less<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::less<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::less_equal<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::less_equal<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::less_equal<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::less_equal<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::equal_to<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::equal_to<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::equal_to<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::equal_to<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::not_equal_to<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::not_equal_to<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::not_equal_to<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::not_equal_to<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::greater<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::greater<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::greater<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::greater<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::greater_equal<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::greater_equal<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::greater_equal<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::greater_equal<>>::value, "" );
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
@@ -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()
|
||||
{
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<Returnable R, class T> unspecified mem_fn(R T::* pm);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
double data_;
|
||||
};
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
f(a) = 5;
|
||||
assert(a.data_ == 5);
|
||||
A* ap = &a;
|
||||
f(ap) = 6;
|
||||
assert(a.data_ == 6);
|
||||
const A* cap = ap;
|
||||
assert(f(cap) == f(ap));
|
||||
f(cap) = 7;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test(std::mem_fn(&A::data_));
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<Returnable R, class T> unspecified mem_fn(R T::* pm);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
double data_;
|
||||
};
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
f(a) = 5;
|
||||
assert(a.data_ == 5);
|
||||
A* ap = &a;
|
||||
f(ap) = 6;
|
||||
assert(a.data_ == 6);
|
||||
const A* cap = ap;
|
||||
assert(f(cap) == f(ap));
|
||||
const F& cf = f;
|
||||
assert(cf(ap) == f(ap));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test(std::mem_fn(&A::data_));
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<Returnable R, class T, CopyConstructible... Args>
|
||||
// unspecified mem_fn(R (T::* pm)(Args...));
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
char test0() {return 'a';}
|
||||
char test1(int) {return 'b';}
|
||||
char test2(int, double) {return 'c';}
|
||||
};
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test0(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a) == 'a');
|
||||
A* ap = &a;
|
||||
assert(f(ap) == 'a');
|
||||
const F& cf = f;
|
||||
assert(cf(ap) == 'a');
|
||||
}
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test1(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a, 1) == 'b');
|
||||
A* ap = &a;
|
||||
assert(f(ap, 2) == 'b');
|
||||
const F& cf = f;
|
||||
assert(cf(ap, 2) == 'b');
|
||||
}
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test2(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a, 1, 2) == 'c');
|
||||
A* ap = &a;
|
||||
assert(f(ap, 2, 3.5) == 'c');
|
||||
const F& cf = f;
|
||||
assert(cf(ap, 2, 3.5) == 'c');
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test0(std::mem_fn(&A::test0));
|
||||
test1(std::mem_fn(&A::test1));
|
||||
test2(std::mem_fn(&A::test2));
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<Returnable R, class T, CopyConstructible... Args>
|
||||
// unspecified mem_fn(R (T::* pm)(Args...) const);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
char test0() const {return 'a';}
|
||||
char test1(int) const {return 'b';}
|
||||
char test2(int, double) const {return 'c';}
|
||||
};
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test0(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a) == 'a');
|
||||
A* ap = &a;
|
||||
assert(f(ap) == 'a');
|
||||
const A* cap = &a;
|
||||
assert(f(cap) == 'a');
|
||||
const F& cf = f;
|
||||
assert(cf(ap) == 'a');
|
||||
}
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test1(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a, 1) == 'b');
|
||||
A* ap = &a;
|
||||
assert(f(ap, 2) == 'b');
|
||||
const A* cap = &a;
|
||||
assert(f(cap, 2) == 'b');
|
||||
const F& cf = f;
|
||||
assert(cf(ap, 2) == 'b');
|
||||
}
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test2(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a, 1, 2) == 'c');
|
||||
A* ap = &a;
|
||||
assert(f(ap, 2, 3.5) == 'c');
|
||||
const A* cap = &a;
|
||||
assert(f(cap, 2, 3.5) == 'c');
|
||||
const F& cf = f;
|
||||
assert(cf(ap, 2, 3.5) == 'c');
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test0(std::mem_fn(&A::test0));
|
||||
test1(std::mem_fn(&A::test1));
|
||||
test2(std::mem_fn(&A::test2));
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<Returnable R, class T, CopyConstructible... Args>
|
||||
// unspecified mem_fn(R (T::* pm)(Args...) const volatile);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
char test0() const volatile {return 'a';}
|
||||
char test1(int) const volatile {return 'b';}
|
||||
char test2(int, double) const volatile {return 'c';}
|
||||
};
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test0(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a) == 'a');
|
||||
A* ap = &a;
|
||||
assert(f(ap) == 'a');
|
||||
const volatile A* cap = &a;
|
||||
assert(f(cap) == 'a');
|
||||
const F& cf = f;
|
||||
assert(cf(ap) == 'a');
|
||||
}
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test1(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a, 1) == 'b');
|
||||
A* ap = &a;
|
||||
assert(f(ap, 2) == 'b');
|
||||
const volatile A* cap = &a;
|
||||
assert(f(cap, 2) == 'b');
|
||||
const F& cf = f;
|
||||
assert(cf(ap, 2) == 'b');
|
||||
}
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test2(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a, 1, 2) == 'c');
|
||||
A* ap = &a;
|
||||
assert(f(ap, 2, 3.5) == 'c');
|
||||
const volatile A* cap = &a;
|
||||
assert(f(cap, 2, 3.5) == 'c');
|
||||
const F& cf = f;
|
||||
assert(cf(ap, 2, 3.5) == 'c');
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test0(std::mem_fn(&A::test0));
|
||||
test1(std::mem_fn(&A::test1));
|
||||
test2(std::mem_fn(&A::test2));
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<Returnable R, class T, CopyConstructible... Args>
|
||||
// unspecified mem_fn(R (T::* pm)(Args...) volatile);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
char test0() volatile {return 'a';}
|
||||
char test1(int) volatile {return 'b';}
|
||||
char test2(int, double) volatile {return 'c';}
|
||||
};
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test0(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a) == 'a');
|
||||
A* ap = &a;
|
||||
assert(f(ap) == 'a');
|
||||
volatile A* cap = &a;
|
||||
assert(f(cap) == 'a');
|
||||
const F& cf = f;
|
||||
assert(cf(ap) == 'a');
|
||||
}
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test1(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a, 1) == 'b');
|
||||
A* ap = &a;
|
||||
assert(f(ap, 2) == 'b');
|
||||
volatile A* cap = &a;
|
||||
assert(f(cap, 2) == 'b');
|
||||
const F& cf = f;
|
||||
assert(cf(ap, 2) == 'b');
|
||||
}
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test2(F f)
|
||||
{
|
||||
{
|
||||
A a;
|
||||
assert(f(a, 1, 2) == 'c');
|
||||
A* ap = &a;
|
||||
assert(f(ap, 2, 3.5) == 'c');
|
||||
volatile A* cap = &a;
|
||||
assert(f(cap, 2, 3.5) == 'c');
|
||||
const F& cf = f;
|
||||
assert(cf(ap, 2, 3.5) == 'c');
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test0(std::mem_fn(&A::test0));
|
||||
test1(std::mem_fn(&A::test1));
|
||||
test2(std::mem_fn(&A::test2));
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// binary_function
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::binary_function<int, short, bool> bf;
|
||||
static_assert((std::is_same<bf::first_argument_type, int>::value), "");
|
||||
static_assert((std::is_same<bf::second_argument_type, short>::value), "");
|
||||
static_assert((std::is_same<bf::result_type, bool>::value), "");
|
||||
}
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// [func.require]
|
||||
|
||||
// INVOKE
|
||||
#if __cplusplus < 201103L
|
||||
int main () {} // no __invoke in C++03
|
||||
#else
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
template <typename T, int N>
|
||||
struct Array
|
||||
{
|
||||
typedef T type[N];
|
||||
};
|
||||
|
||||
struct Type
|
||||
{
|
||||
Array<char, 1>::type& f1();
|
||||
Array<char, 2>::type& f2() const;
|
||||
|
||||
Array<char, 1>::type& g1() &;
|
||||
Array<char, 2>::type& g2() const &;
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
Array<char, 3>::type& g3() &&;
|
||||
Array<char, 4>::type& g4() const &&;
|
||||
#endif
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(sizeof(std::__invoke(&Type::f1, std::declval<Type >())) == 1, "");
|
||||
static_assert(sizeof(std::__invoke(&Type::f2, std::declval<Type const >())) == 2, "");
|
||||
|
||||
static_assert(sizeof(std::__invoke(&Type::g1, std::declval<Type &>())) == 1, "");
|
||||
static_assert(sizeof(std::__invoke(&Type::g2, std::declval<Type const &>())) == 2, "");
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
static_assert(sizeof(std::__invoke(&Type::g3, std::declval<Type &&>())) == 3, "");
|
||||
static_assert(sizeof(std::__invoke(&Type::g4, std::declval<Type const&&>())) == 4, "");
|
||||
#endif
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// unary_function
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::unary_function<int, bool> uf;
|
||||
static_assert((std::is_same<uf::argument_type, int>::value), "");
|
||||
static_assert((std::is_same<uf::result_type, bool>::value), "");
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Class bad_function_call
|
||||
|
||||
// class bad_function_call
|
||||
// : public exception
|
||||
// {
|
||||
// public:
|
||||
// // 20.7.16.1.1, constructor:
|
||||
// bad_function_call();
|
||||
// };
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_base_of<std::exception, std::bad_function_call>::value), "");
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Class bad_function_call
|
||||
|
||||
// bad_function_call();
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::bad_function_call ex;
|
||||
}
|
@@ -0,0 +1,137 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
|
||||
// void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <functional>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
explicit A(int j)
|
||||
{
|
||||
++count;
|
||||
data_[0] = j;
|
||||
}
|
||||
|
||||
A(const A& a)
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = a.data_[i];
|
||||
}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
|
||||
int id() const {return data_[0];}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
int h(int) {return 1;}
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f1 = A(1);
|
||||
std::function<int(int)> f2 = A(2);
|
||||
assert(A::count == 2);
|
||||
assert(new_called == 2);
|
||||
assert(f1.target<A>()->id() == 1);
|
||||
assert(f2.target<A>()->id() == 2);
|
||||
swap(f1, f2);
|
||||
assert(A::count == 2);
|
||||
assert(new_called == 2);
|
||||
assert(f1.target<A>()->id() == 2);
|
||||
assert(f2.target<A>()->id() == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f1 = A(1);
|
||||
std::function<int(int)> f2 = g;
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f1.target<A>()->id() == 1);
|
||||
assert(*f2.target<int(*)(int)>() == g);
|
||||
swap(f1, f2);
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(*f1.target<int(*)(int)>() == g);
|
||||
assert(f2.target<A>()->id() == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f1 = g;
|
||||
std::function<int(int)> f2 = A(1);
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(*f1.target<int(*)(int)>() == g);
|
||||
assert(f2.target<A>()->id() == 1);
|
||||
swap(f1, f2);
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f1.target<A>()->id() == 1);
|
||||
assert(*f2.target<int(*)(int)>() == g);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f1 = g;
|
||||
std::function<int(int)> f2 = h;
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
assert(*f1.target<int(*)(int)>() == g);
|
||||
assert(*f2.target<int(*)(int)>() == h);
|
||||
swap(f1, f2);
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
assert(*f1.target<int(*)(int)>() == h);
|
||||
assert(*f2.target<int(*)(int)>() == g);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// explicit operator bool() const
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
assert(!f);
|
||||
f = g;
|
||||
assert(f);
|
||||
}
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// function(nullptr_t);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <functional>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
|
||||
int foo(int) const {return 1;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = A();
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = g;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>());
|
||||
assert(f.target<A>() == 0);
|
||||
}
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = (int (*)(int))0;
|
||||
assert(!f);
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
}
|
||||
{
|
||||
std::function<int(const A*, int)> f = &A::foo;
|
||||
assert(f);
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int (A::*)(int) const>() != 0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template<class F>
|
||||
// requires CopyConstructible<F> && Callable<F, ArgTypes..>
|
||||
// && Convertible<Callable<F, ArgTypes...>::result_type
|
||||
// operator=(F f);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <functional>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
|
||||
int foo(int) const {return 1;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
f = A();
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
f = g;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>());
|
||||
assert(f.target<A>() == 0);
|
||||
}
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
f = (int (*)(int))0;
|
||||
assert(!f);
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
}
|
||||
{
|
||||
std::function<int(const A*, int)> f;
|
||||
f = &A::foo;
|
||||
assert(f);
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int (A::*)(int) const>() != 0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template<class F> function(F);
|
||||
|
||||
// Allow incomplete argument types in the __is_callable check
|
||||
|
||||
#include <functional>
|
||||
|
||||
struct X{
|
||||
typedef std::function<void(X&)> callback_type;
|
||||
virtual ~X() {}
|
||||
private:
|
||||
callback_type _cb;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template<class A> function(allocator_arg_t, const A&);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
std::function<int(int)> f(std::allocator_arg, test_allocator<int>());
|
||||
assert(!f);
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template<class F, class A> function(allocator_arg_t, const A&, F);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_allocator.h"
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
|
||||
int foo(int) const {return 1;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
void bar(int k) { }
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::function<int(int)> f(std::allocator_arg, test_allocator<A>(), A());
|
||||
assert(A::count == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::function<int(int)> f(std::allocator_arg, test_allocator<int(*)(int)>(), g);
|
||||
assert(f.target<int(*)(int)>());
|
||||
assert(f.target<A>() == 0);
|
||||
}
|
||||
{
|
||||
std::function<int(int)> f(std::allocator_arg, test_allocator<int(*)(int)>(),
|
||||
(int (*)(int))0);
|
||||
assert(!f);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
}
|
||||
{
|
||||
std::function<int(const A*, int)> f(std::allocator_arg,
|
||||
test_allocator<int(A::*)(int)const>(),
|
||||
&A::foo);
|
||||
assert(f);
|
||||
assert(f.target<int (A::*)(int) const>() != 0);
|
||||
}
|
||||
{
|
||||
Foo f;
|
||||
std::function<void(int)> fun = std::bind(&Foo::bar, &f, std::placeholders::_1);
|
||||
fun(10);
|
||||
}
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template<class A> function(allocator_arg_t, const A&, const function&);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <functional>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_allocator.h"
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = A();
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), f);
|
||||
assert(A::count == 2);
|
||||
assert(new_called == 2);
|
||||
assert(f2.target<A>());
|
||||
assert(f2.target<int(*)(int)>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = g;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>());
|
||||
assert(f.target<A>() == 0);
|
||||
std::function<int(int)> f2(std::allocator_arg, test_allocator<int(*)(int)>(), f);
|
||||
assert(new_called == 0);
|
||||
assert(f2.target<int(*)(int)>());
|
||||
assert(f2.target<A>() == 0);
|
||||
}
|
||||
assert(new_called == 0);
|
||||
{
|
||||
assert(new_called == 0);
|
||||
non_default_test_allocator<std::function<int(int)>> al(1);
|
||||
std::function<int(int)> f2(std::allocator_arg, al, g);
|
||||
assert(new_called == 0);
|
||||
assert(f2.target<int(*)(int)>());
|
||||
assert(f2.target<A>() == 0);
|
||||
}
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
std::function<int(int)> f2(std::allocator_arg, test_allocator<int>(), f);
|
||||
assert(new_called == 0);
|
||||
assert(f2.target<int(*)(int)>() == 0);
|
||||
assert(f2.target<A>() == 0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template<class A> function(allocator_arg_t, const A&, nullptr_t);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
std::function<int(int)> f(std::allocator_arg, test_allocator<int>(), nullptr);
|
||||
assert(!f);
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template<class A> function(allocator_arg_t, const A&, function&&);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_allocator.h"
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = A();
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), std::move(f));
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f2.target<A>());
|
||||
assert(f2.target<int(*)(int)>() == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,133 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// function(const function& f);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <functional>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = A();
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
std::function<int(int)> f2 = f;
|
||||
assert(A::count == 2);
|
||||
assert(new_called == 2);
|
||||
assert(f2.target<A>());
|
||||
assert(f2.target<int(*)(int)>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = g;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>());
|
||||
assert(f.target<A>() == 0);
|
||||
std::function<int(int)> f2 = f;
|
||||
assert(new_called == 0);
|
||||
assert(f2.target<int(*)(int)>());
|
||||
assert(f2.target<A>() == 0);
|
||||
}
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
std::function<int(int)> f2 = f;
|
||||
assert(new_called == 0);
|
||||
assert(f2.target<int(*)(int)>() == 0);
|
||||
assert(f2.target<A>() == 0);
|
||||
}
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
assert(!f);
|
||||
std::function<long(int)> g = f;
|
||||
assert(new_called == 0);
|
||||
assert(g.target<long(*)(int)>() == 0);
|
||||
assert(g.target<A>() == 0);
|
||||
assert(!g);
|
||||
}
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = A();
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
std::function<int(int)> f2 = std::move(f);
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f2.target<A>());
|
||||
assert(f2.target<int(*)(int)>() == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// function& operator=(const function& f);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <functional>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = A();
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
std::function<int(int)> f2;
|
||||
f2 = f;
|
||||
assert(A::count == 2);
|
||||
assert(new_called == 2);
|
||||
assert(f2.target<A>());
|
||||
assert(f2.target<int(*)(int)>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = g;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>());
|
||||
assert(f.target<A>() == 0);
|
||||
std::function<int(int)> f2;
|
||||
f2 = f;
|
||||
assert(new_called == 0);
|
||||
assert(f2.target<int(*)(int)>());
|
||||
assert(f2.target<A>() == 0);
|
||||
}
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
std::function<int(int)> f2;
|
||||
f2 = f;
|
||||
assert(new_called == 0);
|
||||
assert(f2.target<int(*)(int)>() == 0);
|
||||
assert(f2.target<A>() == 0);
|
||||
}
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = A();
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
std::function<int(int)> f2;
|
||||
f2 = std::move(f);
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f2.target<A>());
|
||||
assert(f2.target<int(*)(int)>() == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// explicit function();
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
assert(!f);
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R()>
|
||||
|
||||
// template<class F> function(F);
|
||||
|
||||
#define _LIBCPP_HAS_NO_VARIADICS
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::function<void()> f(static_cast<void(*)()>(0));
|
||||
assert(!f);
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// function(nullptr_t);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::function<int(int)> f(nullptr);
|
||||
assert(!f);
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// function& operator=(nullptr_t);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <functional>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f = A();
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f.target<A>());
|
||||
f = nullptr;
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
assert(f.target<A>() == 0);
|
||||
}
|
||||
{
|
||||
std::function<int(int)> f = g;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>());
|
||||
assert(f.target<A>() == 0);
|
||||
f = nullptr;
|
||||
assert(new_called == 0);
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// R operator()(ArgTypes... args) const
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
// member data pointer: cv qualifiers should transfer from argument to return type
|
||||
|
||||
struct A_int_1
|
||||
{
|
||||
A_int_1() : data_(5) {}
|
||||
|
||||
int data_;
|
||||
};
|
||||
|
||||
void
|
||||
test_int_1()
|
||||
{
|
||||
// member data pointer
|
||||
{
|
||||
int A_int_1::*fp = &A_int_1::data_;
|
||||
A_int_1 a;
|
||||
std::function<int& (const A_int_1*)> r2(fp);
|
||||
const A_int_1* ap = &a;
|
||||
assert(r2(ap) == 6);
|
||||
r2(ap) = 7;
|
||||
assert(r2(ap) == 7);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_int_1();
|
||||
}
|
@@ -0,0 +1,335 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// R operator()(ArgTypes... args) const
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int count = 0;
|
||||
|
||||
// 1 arg, return void
|
||||
|
||||
void f_void_1(int i)
|
||||
{
|
||||
count += i;
|
||||
}
|
||||
|
||||
struct A_void_1
|
||||
{
|
||||
void operator()(int i)
|
||||
{
|
||||
count += i;
|
||||
}
|
||||
|
||||
void mem1() {++count;}
|
||||
void mem2() const {++count;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_1()
|
||||
{
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
std::function<void (int)> r1(f_void_1);
|
||||
int i = 2;
|
||||
r1(i);
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
void (*fp)(int) = f_void_1;
|
||||
std::function<void (int)> r1(fp);
|
||||
int i = 3;
|
||||
r1(i);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
// functor
|
||||
{
|
||||
A_void_1 a0;
|
||||
std::function<void (int)> r1(a0);
|
||||
int i = 4;
|
||||
r1(i);
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
void (A_void_1::*fp)() = &A_void_1::mem1;
|
||||
std::function<void (A_void_1)> r1(fp);
|
||||
A_void_1 a;
|
||||
r1(a);
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
A_void_1* ap = &a;
|
||||
std::function<void (A_void_1*)> r2 = fp;
|
||||
r2(ap);
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
void (A_void_1::*fp)() const = &A_void_1::mem2;
|
||||
std::function<void (A_void_1)> r1(fp);
|
||||
A_void_1 a;
|
||||
r1(a);
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
std::function<void (A_void_1*)> r2(fp);
|
||||
A_void_1* ap = &a;
|
||||
r2(ap);
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
// 1 arg, return int
|
||||
|
||||
int f_int_1(int i)
|
||||
{
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
struct A_int_1
|
||||
{
|
||||
A_int_1() : data_(5) {}
|
||||
int operator()(int i)
|
||||
{
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
int mem1() {return 3;}
|
||||
int mem2() const {return 4;}
|
||||
int data_;
|
||||
};
|
||||
|
||||
void
|
||||
test_int_1()
|
||||
{
|
||||
// function
|
||||
{
|
||||
std::function<int (int)> r1(f_int_1);
|
||||
int i = 2;
|
||||
assert(r1(i) == 3);
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
int (*fp)(int) = f_int_1;
|
||||
std::function<int (int)> r1(fp);
|
||||
int i = 3;
|
||||
assert(r1(i) == 4);
|
||||
}
|
||||
// functor
|
||||
{
|
||||
A_int_1 a0;
|
||||
std::function<int (int)> r1(a0);
|
||||
int i = 4;
|
||||
assert(r1(i) == 3);
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
int (A_int_1::*fp)() = &A_int_1::mem1;
|
||||
std::function<int (A_int_1)> r1(fp);
|
||||
A_int_1 a;
|
||||
assert(r1(a) == 3);
|
||||
std::function<int (A_int_1*)> r2(fp);
|
||||
A_int_1* ap = &a;
|
||||
assert(r2(ap) == 3);
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
int (A_int_1::*fp)() const = &A_int_1::mem2;
|
||||
std::function<int (A_int_1)> r1(fp);
|
||||
A_int_1 a;
|
||||
assert(r1(a) == 4);
|
||||
std::function<int (A_int_1*)> r2(fp);
|
||||
A_int_1* ap = &a;
|
||||
assert(r2(ap) == 4);
|
||||
}
|
||||
// member data pointer
|
||||
{
|
||||
int A_int_1::*fp = &A_int_1::data_;
|
||||
std::function<int& (A_int_1&)> r1(fp);
|
||||
A_int_1 a;
|
||||
assert(r1(a) == 5);
|
||||
r1(a) = 6;
|
||||
assert(r1(a) == 6);
|
||||
std::function<int& (A_int_1*)> r2(fp);
|
||||
A_int_1* ap = &a;
|
||||
assert(r2(ap) == 6);
|
||||
r2(ap) = 7;
|
||||
assert(r2(ap) == 7);
|
||||
}
|
||||
}
|
||||
|
||||
// 2 arg, return void
|
||||
|
||||
void f_void_2(int i, int j)
|
||||
{
|
||||
count += i+j;
|
||||
}
|
||||
|
||||
struct A_void_2
|
||||
{
|
||||
void operator()(int i, int j)
|
||||
{
|
||||
count += i+j;
|
||||
}
|
||||
|
||||
void mem1(int i) {count += i;}
|
||||
void mem2(int i) const {count += i;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_2()
|
||||
{
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
std::function<void (int, int)> r1(f_void_2);
|
||||
int i = 2;
|
||||
int j = 3;
|
||||
r1(i, j);
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
void (*fp)(int, int) = f_void_2;
|
||||
std::function<void (int, int)> r1(fp);
|
||||
int i = 3;
|
||||
int j = 4;
|
||||
r1(i, j);
|
||||
assert(count == save_count+7);
|
||||
save_count = count;
|
||||
}
|
||||
// functor
|
||||
{
|
||||
A_void_2 a0;
|
||||
std::function<void (int, int)> r1(a0);
|
||||
int i = 4;
|
||||
int j = 5;
|
||||
r1(i, j);
|
||||
assert(count == save_count+9);
|
||||
save_count = count;
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
void (A_void_2::*fp)(int) = &A_void_2::mem1;
|
||||
std::function<void (A_void_2, int)> r1(fp);
|
||||
A_void_2 a;
|
||||
int i = 3;
|
||||
r1(a, i);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
std::function<void (A_void_2*, int)> r2(fp);
|
||||
A_void_2* ap = &a;
|
||||
r2(ap, i);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
void (A_void_2::*fp)(int) const = &A_void_2::mem2;
|
||||
std::function<void (A_void_2, int)> r1(fp);
|
||||
A_void_2 a;
|
||||
int i = 4;
|
||||
r1(a, i);
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
std::function<void (A_void_2*, int)> r2(fp);
|
||||
A_void_2* ap = &a;
|
||||
r2(ap, i);
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
// 2 arg, return int
|
||||
|
||||
int f_int_2(int i, int j)
|
||||
{
|
||||
return i+j;
|
||||
}
|
||||
|
||||
struct A_int_2
|
||||
{
|
||||
int operator()(int i, int j)
|
||||
{
|
||||
return i+j;
|
||||
}
|
||||
|
||||
int mem1(int i) {return i+1;}
|
||||
int mem2(int i) const {return i+2;}
|
||||
};
|
||||
|
||||
void
|
||||
testint_2()
|
||||
{
|
||||
// function
|
||||
{
|
||||
std::function<int (int, int)> r1(f_int_2);
|
||||
int i = 2;
|
||||
int j = 3;
|
||||
assert(r1(i, j) == i+j);
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
int (*fp)(int, int) = f_int_2;
|
||||
std::function<int (int, int)> r1(fp);
|
||||
int i = 3;
|
||||
int j = 4;
|
||||
assert(r1(i, j) == i+j);
|
||||
}
|
||||
// functor
|
||||
{
|
||||
A_int_2 a0;
|
||||
std::function<int (int, int)> r1(a0);
|
||||
int i = 4;
|
||||
int j = 5;
|
||||
assert(r1(i, j) == i+j);
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
int(A_int_2::*fp)(int) = &A_int_2::mem1;
|
||||
std::function<int (A_int_2, int)> r1(fp);
|
||||
A_int_2 a;
|
||||
int i = 3;
|
||||
assert(r1(a, i) == i+1);
|
||||
std::function<int (A_int_2*, int)> r2(fp);
|
||||
A_int_2* ap = &a;
|
||||
assert(r2(ap, i) == i+1);
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
int (A_int_2::*fp)(int) const = &A_int_2::mem2;
|
||||
std::function<int (A_int_2, int)> r1(fp);
|
||||
A_int_2 a;
|
||||
int i = 4;
|
||||
assert(r1(a, i) == i+2);
|
||||
std::function<int (A_int_2*, int)> r2(fp);
|
||||
A_int_2* ap = &a;
|
||||
assert(r2(ap, i) == i+2);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_void_1();
|
||||
test_int_1();
|
||||
test_void_2();
|
||||
testint_2();
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// R operator()(ArgTypes... args) const
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
// 0 args, return int
|
||||
|
||||
int count = 0;
|
||||
|
||||
int f_int_0()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
struct A_int_0
|
||||
{
|
||||
int operator()() {return 4;}
|
||||
};
|
||||
|
||||
void
|
||||
test_int_0()
|
||||
{
|
||||
// function
|
||||
{
|
||||
std::function<int ()> r1(f_int_0);
|
||||
assert(r1() == 3);
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
int (*fp)() = f_int_0;
|
||||
std::function<int ()> r1(fp);
|
||||
assert(r1() == 3);
|
||||
}
|
||||
// functor
|
||||
{
|
||||
A_int_0 a0;
|
||||
std::function<int ()> r1(a0);
|
||||
assert(r1() == 4);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_int_0();
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// R operator()(ArgTypes... args) const
|
||||
|
||||
#include <functional>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
// 0 args, return void
|
||||
|
||||
int count = 0;
|
||||
|
||||
void f_void_0()
|
||||
{
|
||||
++count;
|
||||
}
|
||||
|
||||
struct A_void_0
|
||||
{
|
||||
void operator()() {++count;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_0()
|
||||
{
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
std::function<void ()> r1(f_void_0);
|
||||
r1();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
void (*fp)() = f_void_0;
|
||||
std::function<void ()> r1(fp);
|
||||
r1();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
// functor
|
||||
{
|
||||
A_void_0 a0;
|
||||
std::function<void ()> r1(a0);
|
||||
r1();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_void_0();
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template<class F, class A> void assign(F&&, const A&);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_allocator.h"
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
|
||||
int foo(int) const {return 1;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
f.assign(A(), test_allocator<A>());
|
||||
assert(A::count == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// void swap(function& other);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <functional>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
explicit A(int j)
|
||||
{
|
||||
++count;
|
||||
data_[0] = j;
|
||||
}
|
||||
|
||||
A(const A& a)
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = a.data_[i];
|
||||
}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
|
||||
int id() const {return data_[0];}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
int h(int) {return 1;}
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f1 = A(1);
|
||||
std::function<int(int)> f2 = A(2);
|
||||
assert(A::count == 2);
|
||||
assert(new_called == 2);
|
||||
assert(f1.target<A>()->id() == 1);
|
||||
assert(f2.target<A>()->id() == 2);
|
||||
f1.swap(f2);
|
||||
assert(A::count == 2);
|
||||
assert(new_called == 2);
|
||||
assert(f1.target<A>()->id() == 2);
|
||||
assert(f2.target<A>()->id() == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f1 = A(1);
|
||||
std::function<int(int)> f2 = g;
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f1.target<A>()->id() == 1);
|
||||
assert(*f2.target<int(*)(int)>() == g);
|
||||
f1.swap(f2);
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(*f1.target<int(*)(int)>() == g);
|
||||
assert(f2.target<A>()->id() == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f1 = g;
|
||||
std::function<int(int)> f2 = A(1);
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(*f1.target<int(*)(int)>() == g);
|
||||
assert(f2.target<A>()->id() == 1);
|
||||
f1.swap(f2);
|
||||
assert(A::count == 1);
|
||||
assert(new_called == 1);
|
||||
assert(f1.target<A>()->id() == 1);
|
||||
assert(*f2.target<int(*)(int)>() == g);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
{
|
||||
std::function<int(int)> f1 = g;
|
||||
std::function<int(int)> f2 = h;
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
assert(*f1.target<int(*)(int)>() == g);
|
||||
assert(*f2.target<int(*)(int)>() == h);
|
||||
f1.swap(f2);
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
assert(*f1.target<int(*)(int)>() == h);
|
||||
assert(*f2.target<int(*)(int)>() == g);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(new_called == 0);
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
|
||||
// bool operator==(const function<R(ArgTypes...)>&, nullptr_t);
|
||||
//
|
||||
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
|
||||
// bool operator==(nullptr_t, const function<R(ArgTypes...)>&);
|
||||
//
|
||||
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
|
||||
// bool operator!=(const function<R(ArgTypes...)>&, nullptr_t);
|
||||
//
|
||||
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
|
||||
// bool operator!=(nullptr_t, const function<R(ArgTypes...)>&);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
assert(f == nullptr);
|
||||
assert(nullptr == f);
|
||||
f = g;
|
||||
assert(f != nullptr);
|
||||
assert(nullptr != f);
|
||||
}
|
||||
}
|
@@ -0,0 +1,89 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// template<typename T>
|
||||
// requires Callable<T, ArgTypes...> && Convertible<Callable<T, ArgTypes...>::result_type, R>
|
||||
// T*
|
||||
// target();
|
||||
// template<typename T>
|
||||
// requires Callable<T, ArgTypes...> && Convertible<Callable<T, ArgTypes...>::result_type, R>
|
||||
// const T*
|
||||
// target() const;
|
||||
|
||||
#include <functional>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
|
||||
int foo(int) const {return 1;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::function<int(int)> f = A();
|
||||
assert(A::count == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::function<int(int)> f = g;
|
||||
assert(A::count == 0);
|
||||
assert(f.target<int(*)(int)>());
|
||||
assert(f.target<A>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
const std::function<int(int)> f = A();
|
||||
assert(A::count == 1);
|
||||
assert(f.target<A>());
|
||||
assert(f.target<int(*)(int)>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
const std::function<int(int)> f = g;
|
||||
assert(A::count == 0);
|
||||
assert(f.target<int(*)(int)>());
|
||||
assert(f.target<A>() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// class function<R(ArgTypes...)>
|
||||
|
||||
// const std::type_info& target_type() const;
|
||||
|
||||
#include <functional>
|
||||
#include <typeinfo>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
int data_[10];
|
||||
public:
|
||||
static int count;
|
||||
|
||||
A()
|
||||
{
|
||||
++count;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
data_[i] = i;
|
||||
}
|
||||
|
||||
A(const A&) {++count;}
|
||||
|
||||
~A() {--count;}
|
||||
|
||||
int operator()(int i) const
|
||||
{
|
||||
for (int j = 0; j < 10; ++j)
|
||||
i += data_[j];
|
||||
return i;
|
||||
}
|
||||
|
||||
int foo(int) const {return 1;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int g(int) {return 0;}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::function<int(int)> f = A();
|
||||
assert(f.target_type() == typeid(A));
|
||||
}
|
||||
{
|
||||
std::function<int(int)> f;
|
||||
assert(f.target_type() == typeid(void));
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<Returnable R, CopyConstructible... ArgTypes>
|
||||
// class function<R(ArgTypes...)>
|
||||
// : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
|
||||
// // ArgTypes contains T1
|
||||
// : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
|
||||
// // ArgTypes contains T1 and T2
|
||||
// {
|
||||
// public:
|
||||
// typedef R result_type;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((!std::is_base_of<std::unary_function <int, int>,
|
||||
std::function<int()> >::value), "");
|
||||
static_assert((!std::is_base_of<std::binary_function<int, int, int>,
|
||||
std::function<int()> >::value), "");
|
||||
static_assert(( std::is_same< std::function<int()>::result_type,
|
||||
int>::value), "");
|
||||
|
||||
static_assert(( std::is_base_of<std::unary_function <int, double>,
|
||||
std::function<double(int)> >::value), "");
|
||||
static_assert((!std::is_base_of<std::binary_function<int, int, double>,
|
||||
std::function<double(int)> >::value), "");
|
||||
static_assert(( std::is_same< std::function<double(int)>::result_type,
|
||||
double>::value), "");
|
||||
|
||||
static_assert((!std::is_base_of<std::unary_function <int, double>,
|
||||
std::function<double(int, char)> >::value), "");
|
||||
static_assert(( std::is_base_of<std::binary_function<int, char, double>,
|
||||
std::function<double(int, char)> >::value), "");
|
||||
static_assert(( std::is_same< std::function<double(int, char)>::result_type,
|
||||
double>::value), "");
|
||||
}
|
@@ -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()
|
||||
{
|
||||
}
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// logical_and
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::logical_and<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
|
||||
assert(f(36, 36));
|
||||
assert(!f(36, 0));
|
||||
assert(!f(0, 36));
|
||||
assert(!f(0, 0));
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::logical_and<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert( f2(36, 36));
|
||||
assert( f2(36, 36L));
|
||||
assert( f2(36L, 36));
|
||||
assert(!f2(36, 0));
|
||||
assert(!f2(0, 36));
|
||||
assert( f2(36, 36L));
|
||||
assert(!f2(36, 0L));
|
||||
assert(!f2(0, 36L));
|
||||
assert( f2(36L, 36));
|
||||
assert(!f2(36L, 0));
|
||||
assert(!f2(0L, 36));
|
||||
|
||||
constexpr bool foo = std::logical_and<int> () (36, 36);
|
||||
static_assert ( foo, "" );
|
||||
|
||||
constexpr bool bar = std::logical_and<> () (36.0, 36);
|
||||
static_assert ( bar, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// logical_not
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::logical_not<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::unary_function<int, bool>, F>::value), "");
|
||||
assert(!f(36));
|
||||
assert(f(0));
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::logical_not<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert(!f2(36));
|
||||
assert( f2(0));
|
||||
assert(!f2(36L));
|
||||
assert( f2(0L));
|
||||
|
||||
constexpr bool foo = std::logical_not<int> () (36);
|
||||
static_assert ( !foo, "" );
|
||||
|
||||
constexpr bool bar = std::logical_not<> () (36);
|
||||
static_assert ( !bar, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// logical_or
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::logical_or<int> F;
|
||||
const F f = F();
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
|
||||
assert(f(36, 36));
|
||||
assert(f(36, 0));
|
||||
assert(f(0, 36));
|
||||
assert(!f(0, 0));
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
typedef std::logical_or<> F2;
|
||||
const F2 f2 = F2();
|
||||
assert( f2(36, 36));
|
||||
assert( f2(36, 36L));
|
||||
assert( f2(36L, 36));
|
||||
assert( f2(36, 0));
|
||||
assert( f2(0, 36));
|
||||
assert( f2(36, 0L));
|
||||
assert( f2(0, 36L));
|
||||
assert(!f2(0, 0));
|
||||
assert(!f2(0, 0L));
|
||||
assert(!f2(0L, 0));
|
||||
|
||||
constexpr bool foo = std::logical_or<int> () (36, 36);
|
||||
static_assert ( foo, "" );
|
||||
|
||||
constexpr bool bar = std::logical_or<> () (36.0, 36);
|
||||
static_assert ( bar, "" );
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
template <class _Tp>
|
||||
struct is_transparent
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::is_transparent* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
|
||||
|
||||
int main () {
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
static_assert ( !is_transparent<std::logical_and<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::logical_and<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::logical_and<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::logical_and<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::logical_or<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::logical_or<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::logical_or<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::logical_or<>>::value, "" );
|
||||
|
||||
static_assert ( !is_transparent<std::logical_not<int>>::value, "" );
|
||||
static_assert ( !is_transparent<std::logical_not<std::string>>::value, "" );
|
||||
static_assert ( is_transparent<std::logical_not<void>>::value, "" );
|
||||
static_assert ( is_transparent<std::logical_not<>>::value, "" );
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// binary_negate
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::binary_negate<std::logical_and<int> > F;
|
||||
const F f = F(std::logical_and<int>());
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
|
||||
assert(!f(36, 36));
|
||||
assert( f(36, 0));
|
||||
assert( f(0, 36));
|
||||
assert( f(0, 0));
|
||||
}
|
22
test/std/utilities/function.objects/negators/not1.pass.cpp
Normal file
22
test/std/utilities/function.objects/negators/not1.pass.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// not1
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::logical_not<int> F;
|
||||
assert(std::not1(F())(36));
|
||||
assert(!std::not1(F())(0));
|
||||
}
|
24
test/std/utilities/function.objects/negators/not2.pass.cpp
Normal file
24
test/std/utilities/function.objects/negators/not2.pass.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// not2
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::logical_and<int> F;
|
||||
assert(!std::not2(F())(36, 36));
|
||||
assert( std::not2(F())(36, 0));
|
||||
assert( std::not2(F())(0, 36));
|
||||
assert( std::not2(F())(0, 0));
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// unary_negate
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::unary_negate<std::logical_not<int> > F;
|
||||
const F f = F(std::logical_not<int>());
|
||||
static_assert((std::is_base_of<std::unary_function<int, bool>, F>::value), "");
|
||||
assert(f(36));
|
||||
assert(!f(0));
|
||||
}
|
80
test/std/utilities/function.objects/refwrap/binary.pass.cpp
Normal file
80
test/std/utilities/function.objects/refwrap/binary.pass.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// reference_wrapper
|
||||
|
||||
// check for deriving from binary_function
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
class functor1
|
||||
: public std::unary_function<int, char>
|
||||
{
|
||||
};
|
||||
|
||||
class functor2
|
||||
: public std::binary_function<char, int, double>
|
||||
{
|
||||
};
|
||||
|
||||
class functor3
|
||||
: public std::unary_function<int, int>,
|
||||
public std::binary_function<char, int, double>
|
||||
{
|
||||
public:
|
||||
typedef float result_type;
|
||||
};
|
||||
|
||||
class functor4
|
||||
: public std::unary_function<int, int>,
|
||||
public std::binary_function<char, int, double>
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
struct C
|
||||
{
|
||||
typedef int argument_type;
|
||||
typedef int result_type;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((!std::is_base_of<std::binary_function<int, char, int>,
|
||||
std::reference_wrapper<functor1> >::value), "");
|
||||
static_assert((std::is_base_of<std::binary_function<char, int, double>,
|
||||
std::reference_wrapper<functor2> >::value), "");
|
||||
static_assert((std::is_base_of<std::binary_function<char, int, double>,
|
||||
std::reference_wrapper<functor3> >::value), "");
|
||||
static_assert((std::is_base_of<std::binary_function<char, int, double>,
|
||||
std::reference_wrapper<functor4> >::value), "");
|
||||
static_assert((!std::is_base_of<std::binary_function<int, int, int>,
|
||||
std::reference_wrapper<C> >::value), "");
|
||||
static_assert((!std::is_base_of<std::binary_function<int, int, float>,
|
||||
std::reference_wrapper<float ()> >::value), "");
|
||||
static_assert((!std::is_base_of<std::binary_function<int, int, float>,
|
||||
std::reference_wrapper<float (int)> >::value), "");
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, float>,
|
||||
std::reference_wrapper<float (int, int)> >::value), "");
|
||||
static_assert((!std::is_base_of<std::binary_function<int, int, float>,
|
||||
std::reference_wrapper<float(*)()> >::value), "");
|
||||
static_assert((!std::is_base_of<std::binary_function<int, int, float>,
|
||||
std::reference_wrapper<float(*)(int)> >::value), "");
|
||||
static_assert((std::is_base_of<std::binary_function<int, int, float>,
|
||||
std::reference_wrapper<float(*)(int, int)> >::value), "");
|
||||
static_assert((!std::is_base_of<std::binary_function<C*, int, float>,
|
||||
std::reference_wrapper<float(C::*)()> >::value), "");
|
||||
static_assert((std::is_base_of<std::binary_function<C*, int, float>,
|
||||
std::reference_wrapper<float(C::*)(int)> >::value), "");
|
||||
static_assert((std::is_base_of<std::binary_function<const volatile C*, int, float>,
|
||||
std::reference_wrapper<float(C::*)(int) const volatile> >::value), "");
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user