diff options
Diffstat (limited to 'libcxx/test/utilities/function.objects/refwrap')
18 files changed, 1144 insertions, 18 deletions
diff --git a/libcxx/test/utilities/function.objects/refwrap/binary.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/binary.pass.cpp index e9d7dda00a3..5c4c730ac6a 100644 --- a/libcxx/test/utilities/function.objects/refwrap/binary.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/binary.pass.cpp @@ -1 +1,80 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. 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), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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), ""); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp index 76986162b49..7c33f7712e5 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// operator T& () const;
#include <functional>
#include <cassert>
class functor1
: public std::unary_function<int, char>
{
};
template <class T>
void
test(T& t)
{
std::reference_wrapper<T> r(t);
T& r2 = r;
assert(&r2 == &t);
}
void f() {}
int main()
{
void (*fp)() = f;
test(fp);
test(f);
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// operator T& () const; + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + T& r2 = r; + assert(&r2 == &t); +} + +void f() {} + +int main() +{ + void (*fp)() = f; + test(fp); + test(f); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp index bccafd746e2..b08fb87b075 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp @@ -1 +1,58 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// reference_wrapper& operator=(const reference_wrapper<T>& x);
#include <functional>
#include <cassert>
class functor1
: public std::unary_function<int, char>
{
};
template <class T>
void
test(T& t)
{
std::reference_wrapper<T> r(t);
T t2 = t;
std::reference_wrapper<T> r2(t2);
r2 = r;
assert(&r2.get() == &t);
}
void f() {}
void g() {}
void
test_function()
{
std::reference_wrapper<void ()> r(f);
std::reference_wrapper<void ()> r2(g);
r2 = r;
assert(&r2.get() == &f);
}
int main()
{
void (*fp)() = f;
test(fp);
test_function();
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper& operator=(const reference_wrapper<T>& x); + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + T t2 = t; + std::reference_wrapper<T> r2(t2); + r2 = r; + assert(&r2.get() == &t); +} + +void f() {} +void g() {} + +void +test_function() +{ + std::reference_wrapper<void ()> r(f); + std::reference_wrapper<void ()> r2(g); + r2 = r; + assert(&r2.get() == &f); +} + +int main() +{ + void (*fp)() = f; + test(fp); + test_function(); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp index 8bdbec5a75c..497e5fbc199 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp @@ -1 +1,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// reference_wrapper(const reference_wrapper<T>& x);
#include <functional>
#include <cassert>
class functor1
: public std::unary_function<int, char>
{
};
template <class T>
void
test(T& t)
{
std::reference_wrapper<T> r(t);
std::reference_wrapper<T> r2 = r;
assert(&r2.get() == &t);
}
void f() {}
int main()
{
void (*fp)() = f;
test(fp);
test(f);
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper(const reference_wrapper<T>& x); + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + std::reference_wrapper<T> r2 = r; + assert(&r2.get() == &t); +} + +void f() {} + +int main() +{ + void (*fp)() = f; + test(fp); + test(f); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp index f07592db475..78153d6bd7d 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp @@ -1 +1,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// reference_wrapper(T&&) = delete;
#include <functional>
#include <cassert>
int main()
{
std::reference_wrapper<const int> r(3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper(T&&) = delete; + +#include <functional> +#include <cassert> + +int main() +{ + std::reference_wrapper<const int> r(3); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp index a4c2c8727b1..770ac52dde2 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp @@ -1 +1,45 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// reference_wrapper(T& t);
#include <functional>
#include <cassert>
class functor1
: public std::unary_function<int, char>
{
};
template <class T>
void
test(T& t)
{
std::reference_wrapper<T> r(t);
assert(&r.get() == &t);
}
void f() {}
int main()
{
void (*fp)() = f;
test(fp);
test(f);
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper(T& t); + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + assert(&r.get() == &t); +} + +void f() {} + +int main() +{ + void (*fp)() = f; + test(fp); + test(f); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp index f60de648d96..22ad0b8a2e5 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <ObjectType T> reference_wrapper<const T> cref(const T& t);
#include <functional>
#include <cassert>
int main()
{
int i = 0;
std::reference_wrapper<const int> r = std::cref(i);
assert(&r.get() == &i);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<const T> cref(const T& t); + +#include <functional> +#include <cassert> + +int main() +{ + int i = 0; + std::reference_wrapper<const int> r = std::cref(i); + assert(&r.get() == &i); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp index 2f05d467eb3..a11e3dad9dd 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <ObjectType T> reference_wrapper<const T> cref(reference_wrapper<T> t);
#include <functional>
#include <cassert>
int main()
{
const int i = 0;
std::reference_wrapper<const int> r1 = std::cref(i);
std::reference_wrapper<const int> r2 = std::cref(r1);
assert(&r2.get() == &i);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<const T> cref(reference_wrapper<T> t); + +#include <functional> +#include <cassert> + +int main() +{ + const int i = 0; + std::reference_wrapper<const int> r1 = std::cref(i); + std::reference_wrapper<const int> r2 = std::cref(r1); + assert(&r2.get() == &i); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp index 7fe32d7b023..abdd9fa26b9 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp @@ -1 +1,27 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <ObjectType T> reference_wrapper<T> ref(T& t);
// Don't allow binding to a temp
#include <functional>
struct A {};
const A source() {return A();}
int main()
{
std::reference_wrapper<const A> r = std::ref(source());
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<T> ref(T& t); + +// Don't allow binding to a temp + +#include <functional> + +struct A {}; + +const A source() {return A();} + +int main() +{ + std::reference_wrapper<const A> r = std::ref(source()); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp index d4e493e0906..c01286c17c0 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp @@ -1 +1,24 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <ObjectType T> reference_wrapper<T> ref(T& t);
#include <functional>
#include <cassert>
int main()
{
int i = 0;
std::reference_wrapper<int> r = std::ref(i);
assert(&r.get() == &i);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<T> ref(T& t); + +#include <functional> +#include <cassert> + +int main() +{ + int i = 0; + std::reference_wrapper<int> r = std::ref(i); + assert(&r.get() == &i); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp index f486a00aed4..646cd10aa11 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp @@ -1 +1,25 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <ObjectType T> reference_wrapper<T> ref(reference_wrapper<T>t);
#include <functional>
#include <cassert>
int main()
{
int i = 0;
std::reference_wrapper<int> r1 = std::ref(i);
std::reference_wrapper<int> r2 = std::ref(r1);
assert(&r2.get() == &i);
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<T> ref(reference_wrapper<T>t); + +#include <functional> +#include <cassert> + +int main() +{ + int i = 0; + std::reference_wrapper<int> r1 = std::ref(i); + std::reference_wrapper<int> r2 = std::ref(r1); + assert(&r2.get() == &i); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp index d7b94ab6064..60c7bf06074 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp @@ -1 +1,52 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <class... ArgTypes>
// requires Callable<T, ArgTypes&&...>
// Callable<T, ArgTypes&&...>::result_type
// 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_;
std::reference_wrapper<int A_int_1::*> r1(fp);
A_int_1 a;
assert(r1(a) == 5);
r1(a) = 6;
assert(r1(a) == 6);
const A_int_1* ap = &a;
assert(r1(ap) == 6);
r1(ap) = 7;
assert(r1(ap) == 7);
}
}
int main()
{
test_int_1();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// 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_; + std::reference_wrapper<int A_int_1::*> r1(fp); + A_int_1 a; + assert(r1(a) == 5); + r1(a) = 6; + assert(r1(a) == 6); + const A_int_1* ap = &a; + assert(r1(ap) == 6); + r1(ap) = 7; + assert(r1(ap) == 7); + } +} + +int main() +{ + test_int_1(); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp index ca7f226b682..b750564ff6d 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp @@ -1 +1,329 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <class... ArgTypes>
// requires Callable<T, ArgTypes&&...>
// Callable<T, ArgTypes&&...>::result_type
// 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::reference_wrapper<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::reference_wrapper<void (*)(int)> r1(fp);
int i = 3;
r1(i);
assert(count == save_count+3);
save_count = count;
}
// functor
{
A_void_1 a0;
std::reference_wrapper<A_void_1> 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::reference_wrapper<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;
r1(ap);
assert(count == save_count+1);
save_count = count;
}
// const member function pointer
{
void (A_void_1::*fp)() const = &A_void_1::mem2;
std::reference_wrapper<void (A_void_1::*)() const> r1(fp);
A_void_1 a;
r1(a);
assert(count == save_count+1);
save_count = count;
A_void_1* ap = &a;
r1(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::reference_wrapper<int (int)> r1(f_int_1);
int i = 2;
assert(r1(i) == 3);
}
// function pointer
{
int (*fp)(int) = f_int_1;
std::reference_wrapper<int (*)(int)> r1(fp);
int i = 3;
assert(r1(i) == 4);
}
// functor
{
A_int_1 a0;
std::reference_wrapper<A_int_1> r1(a0);
int i = 4;
assert(r1(i) == 3);
}
// member function pointer
{
int (A_int_1::*fp)() = &A_int_1::mem1;
std::reference_wrapper<int (A_int_1::*)()> r1(fp);
A_int_1 a;
assert(r1(a) == 3);
A_int_1* ap = &a;
assert(r1(ap) == 3);
}
// const member function pointer
{
int (A_int_1::*fp)() const = &A_int_1::mem2;
std::reference_wrapper<int (A_int_1::*)() const> r1(fp);
A_int_1 a;
assert(r1(a) == 4);
A_int_1* ap = &a;
assert(r1(ap) == 4);
}
// member data pointer
{
int A_int_1::*fp = &A_int_1::data_;
std::reference_wrapper<int A_int_1::*> r1(fp);
A_int_1 a;
assert(r1(a) == 5);
r1(a) = 6;
assert(r1(a) == 6);
A_int_1* ap = &a;
assert(r1(ap) == 6);
r1(ap) = 7;
assert(r1(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::reference_wrapper<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::reference_wrapper<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::reference_wrapper<A_void_2> 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::reference_wrapper<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;
A_void_2* ap = &a;
r1(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::reference_wrapper<void (A_void_2::*)(int) const> r1(fp);
A_void_2 a;
int i = 4;
r1(a, i);
assert(count == save_count+4);
save_count = count;
A_void_2* ap = &a;
r1(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::reference_wrapper<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::reference_wrapper<int (*)(int, int)> r1(fp);
int i = 3;
int j = 4;
assert(r1(i, j) == i+j);
}
// functor
{
A_int_2 a0;
std::reference_wrapper<A_int_2> 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::reference_wrapper<int (A_int_2::*)(int)> r1(fp);
A_int_2 a;
int i = 3;
assert(r1(a, i) == i+1);
A_int_2* ap = &a;
assert(r1(ap, i) == i+1);
}
// const member function pointer
{
int (A_int_2::*fp)(int) const = &A_int_2::mem2;
std::reference_wrapper<int (A_int_2::*)(int) const> r1(fp);
A_int_2 a;
int i = 4;
assert(r1(a, i) == i+2);
A_int_2* ap = &a;
assert(r1(ap, i) == i+2);
}
}
int main()
{
test_void_1();
test_int_1();
test_void_2();
testint_2();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// 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::reference_wrapper<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::reference_wrapper<void (*)(int)> r1(fp); + int i = 3; + r1(i); + assert(count == save_count+3); + save_count = count; + } + // functor + { + A_void_1 a0; + std::reference_wrapper<A_void_1> 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::reference_wrapper<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; + r1(ap); + assert(count == save_count+1); + save_count = count; + } + // const member function pointer + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + std::reference_wrapper<void (A_void_1::*)() const> r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + r1(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::reference_wrapper<int (int)> r1(f_int_1); + int i = 2; + assert(r1(i) == 3); + } + // function pointer + { + int (*fp)(int) = f_int_1; + std::reference_wrapper<int (*)(int)> r1(fp); + int i = 3; + assert(r1(i) == 4); + } + // functor + { + A_int_1 a0; + std::reference_wrapper<A_int_1> r1(a0); + int i = 4; + assert(r1(i) == 3); + } + // member function pointer + { + int (A_int_1::*fp)() = &A_int_1::mem1; + std::reference_wrapper<int (A_int_1::*)()> r1(fp); + A_int_1 a; + assert(r1(a) == 3); + A_int_1* ap = &a; + assert(r1(ap) == 3); + } + // const member function pointer + { + int (A_int_1::*fp)() const = &A_int_1::mem2; + std::reference_wrapper<int (A_int_1::*)() const> r1(fp); + A_int_1 a; + assert(r1(a) == 4); + A_int_1* ap = &a; + assert(r1(ap) == 4); + } + // member data pointer + { + int A_int_1::*fp = &A_int_1::data_; + std::reference_wrapper<int A_int_1::*> r1(fp); + A_int_1 a; + assert(r1(a) == 5); + r1(a) = 6; + assert(r1(a) == 6); + A_int_1* ap = &a; + assert(r1(ap) == 6); + r1(ap) = 7; + assert(r1(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::reference_wrapper<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::reference_wrapper<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::reference_wrapper<A_void_2> 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::reference_wrapper<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; + A_void_2* ap = &a; + r1(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::reference_wrapper<void (A_void_2::*)(int) const> r1(fp); + A_void_2 a; + int i = 4; + r1(a, i); + assert(count == save_count+4); + save_count = count; + A_void_2* ap = &a; + r1(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::reference_wrapper<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::reference_wrapper<int (*)(int, int)> r1(fp); + int i = 3; + int j = 4; + assert(r1(i, j) == i+j); + } + // functor + { + A_int_2 a0; + std::reference_wrapper<A_int_2> 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::reference_wrapper<int (A_int_2::*)(int)> r1(fp); + A_int_2 a; + int i = 3; + assert(r1(a, i) == i+1); + A_int_2* ap = &a; + assert(r1(ap, i) == i+1); + } + // const member function pointer + { + int (A_int_2::*fp)(int) const = &A_int_2::mem2; + std::reference_wrapper<int (A_int_2::*)(int) const> r1(fp); + A_int_2 a; + int i = 4; + assert(r1(a, i) == i+2); + A_int_2* ap = &a; + assert(r1(ap, i) == i+2); + } +} + +int main() +{ + test_void_1(); + test_int_1(); + test_void_2(); + testint_2(); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp index 2bef95e6d60..709836bd3cb 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp @@ -1 +1,76 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <class... ArgTypes>
// requires Callable<T, ArgTypes&&...>
// Callable<T, ArgTypes&&...>::result_type
// 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::reference_wrapper<int ()> r1(f_int_0);
assert(r1() == 3);
}
// function pointer
{
int (*fp)() = f_int_0;
std::reference_wrapper<int (*)()> r1(fp);
assert(r1() == 3);
}
// functor
{
A_int_0 a0;
std::reference_wrapper<A_int_0> r1(a0);
assert(r1() == 4);
}
}
// 1 arg, return void
void f_void_1(int i)
{
count += i;
}
struct A_void_1
{
void operator()(int i)
{
count += i;
}
};
int main()
{
test_int_0();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// 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::reference_wrapper<int ()> r1(f_int_0); + assert(r1() == 3); + } + // function pointer + { + int (*fp)() = f_int_0; + std::reference_wrapper<int (*)()> r1(fp); + assert(r1() == 3); + } + // functor + { + A_int_0 a0; + std::reference_wrapper<A_int_0> r1(a0); + assert(r1() == 4); + } +} + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } +}; + +int main() +{ + test_int_0(); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp index e7445217cc0..127a97c6711 100644 --- a/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp @@ -1 +1,68 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// template <class... ArgTypes>
// requires Callable<T, ArgTypes&&...>
// Callable<T, ArgTypes&&...>::result_type
// operator()(ArgTypes&&... args) const;
#include <functional>
#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::reference_wrapper<void ()> r1(f_void_0);
r1();
assert(count == save_count+1);
save_count = count;
}
// function pointer
{
void (*fp)() = f_void_0;
std::reference_wrapper<void (*)()> r1(fp);
r1();
assert(count == save_count+1);
save_count = count;
}
// functor
{
A_void_0 a0;
std::reference_wrapper<A_void_0> r1(a0);
r1();
assert(count == save_count+1);
save_count = count;
}
}
int main()
{
test_void_0();
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// operator()(ArgTypes&&... args) const; + +#include <functional> +#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::reference_wrapper<void ()> r1(f_void_0); + r1(); + assert(count == save_count+1); + save_count = count; + } + // function pointer + { + void (*fp)() = f_void_0; + std::reference_wrapper<void (*)()> r1(fp); + r1(); + assert(count == save_count+1); + save_count = count; + } + // functor + { + A_void_0 a0; + std::reference_wrapper<A_void_0> r1(a0); + r1(); + assert(count == save_count+1); + save_count = count; + } +} + +int main() +{ + test_void_0(); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/type.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/type.pass.cpp index 0ff12536803..fb1523e7d46 100644 --- a/libcxx/test/utilities/function.objects/refwrap/type.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/type.pass.cpp @@ -1 +1,37 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// check for member typedef type
#include <functional>
#include <type_traits>
class C {};
int main()
{
static_assert((std::is_same<std::reference_wrapper<C>::type,
C>::value), "");
static_assert((std::is_same<std::reference_wrapper<void ()>::type,
void ()>::value), "");
static_assert((std::is_same<std::reference_wrapper<int* (double*)>::type,
int* (double*)>::value), "");
static_assert((std::is_same<std::reference_wrapper<void(*)()>::type,
void(*)()>::value), "");
static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::type,
int*(*)(double*)>::value), "");
static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::type,
int*(C::*)(double*)>::value), "");
static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::type,
int (C::*)(double*) const volatile>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// check for member typedef type + +#include <functional> +#include <type_traits> + +class C {}; + +int main() +{ + static_assert((std::is_same<std::reference_wrapper<C>::type, + C>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void ()>::type, + void ()>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int* (double*)>::type, + int* (double*)>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void(*)()>::type, + void(*)()>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::type, + int*(*)(double*)>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::type, + int*(C::*)(double*)>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::type, + int (C::*)(double*) const volatile>::value), ""); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/unary.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/unary.pass.cpp index 411d34fa26f..5998deacead 100644 --- a/libcxx/test/utilities/function.objects/refwrap/unary.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/unary.pass.cpp @@ -1 +1,78 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// check for deriving from unary_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::unary_function<int, char>,
std::reference_wrapper<functor1> >::value), "");
static_assert((!std::is_base_of<std::unary_function<char, int>,
std::reference_wrapper<functor2> >::value), "");
static_assert((std::is_base_of<std::unary_function<int, int>,
std::reference_wrapper<functor3> >::value), "");
static_assert((std::is_base_of<std::unary_function<int, int>,
std::reference_wrapper<functor4> >::value), "");
static_assert((!std::is_base_of<std::unary_function<int, int>,
std::reference_wrapper<C> >::value), "");
static_assert((!std::is_base_of<std::unary_function<int, float>,
std::reference_wrapper<float(*)()> >::value), "");
static_assert((std::is_base_of<std::unary_function<int, float>,
std::reference_wrapper<float (int)> >::value), "");
static_assert((!std::is_base_of<std::unary_function<int, float>,
std::reference_wrapper<float (int, int)> >::value), "");
static_assert((std::is_base_of<std::unary_function<int, float>,
std::reference_wrapper<float(*)(int)> >::value), "");
static_assert((!std::is_base_of<std::unary_function<int, float>,
std::reference_wrapper<float(*)(int, int)> >::value), "");
static_assert((std::is_base_of<std::unary_function<C*, float>,
std::reference_wrapper<float(C::*)()> >::value), "");
static_assert((std::is_base_of<std::unary_function<const volatile C*, float>,
std::reference_wrapper<float(C::*)() const volatile> >::value), "");
static_assert((!std::is_base_of<std::unary_function<C*, float>,
std::reference_wrapper<float(C::*)(int)> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// check for deriving from unary_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::unary_function<int, char>, + std::reference_wrapper<functor1> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<char, int>, + std::reference_wrapper<functor2> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<functor3> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<functor4> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<C> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)()> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float (int)> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float (int, int)> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)(int)> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)(int, int)> >::value), ""); + static_assert((std::is_base_of<std::unary_function<C*, float>, + std::reference_wrapper<float(C::*)()> >::value), ""); + static_assert((std::is_base_of<std::unary_function<const volatile C*, float>, + std::reference_wrapper<float(C::*)() const volatile> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<C*, float>, + std::reference_wrapper<float(C::*)(int)> >::value), ""); +} diff --git a/libcxx/test/utilities/function.objects/refwrap/weak_result.pass.cpp b/libcxx/test/utilities/function.objects/refwrap/weak_result.pass.cpp index 09cef664298..794651dbde7 100644 --- a/libcxx/test/utilities/function.objects/refwrap/weak_result.pass.cpp +++ b/libcxx/test/utilities/function.objects/refwrap/weak_result.pass.cpp @@ -1 +1,82 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// reference_wrapper
// has weak result type
#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<char, int>,
public std::binary_function<char, int, double>
{
public:
typedef float result_type;
};
class functor4
: public std::unary_function<char, int>,
public std::binary_function<char, int, double>
{
public:
};
class C {};
template <class T>
struct has_result_type
{
private:
struct two {char _; char __;};
template <class U> static two test(...);
template <class U> static char test(typename U::result_type* = 0);
public:
static const bool value = sizeof(test<T>(0)) == 1;
};
int main()
{
static_assert((std::is_same<std::reference_wrapper<functor1>::result_type,
char>::value), "");
static_assert((std::is_same<std::reference_wrapper<functor2>::result_type,
double>::value), "");
static_assert((std::is_same<std::reference_wrapper<functor3>::result_type,
float>::value), "");
static_assert((std::is_same<std::reference_wrapper<void()>::result_type,
void>::value), "");
static_assert((std::is_same<std::reference_wrapper<int*(double*)>::result_type,
int*>::value), "");
static_assert((std::is_same<std::reference_wrapper<void(*)()>::result_type,
void>::value), "");
static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::result_type,
int*>::value), "");
static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::result_type,
int*>::value), "");
static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::result_type,
int>::value), "");
static_assert((std::is_same<std::reference_wrapper<C()>::result_type,
C>::value), "");
static_assert(has_result_type<std::reference_wrapper<functor3> >::value, "");
static_assert(!has_result_type<std::reference_wrapper<functor4> >::value, "");
static_assert(!has_result_type<std::reference_wrapper<C> >::value, "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// has weak result type + +#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<char, int>, + public std::binary_function<char, int, double> +{ +public: + typedef float result_type; +}; + +class functor4 + : public std::unary_function<char, int>, + public std::binary_function<char, int, double> +{ +public: +}; + +class C {}; + +template <class T> +struct has_result_type +{ +private: + struct two {char _; char __;}; + template <class U> static two test(...); + template <class U> static char test(typename U::result_type* = 0); +public: + static const bool value = sizeof(test<T>(0)) == 1; +}; + +int main() +{ + static_assert((std::is_same<std::reference_wrapper<functor1>::result_type, + char>::value), ""); + static_assert((std::is_same<std::reference_wrapper<functor2>::result_type, + double>::value), ""); + static_assert((std::is_same<std::reference_wrapper<functor3>::result_type, + float>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void()>::result_type, + void>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(double*)>::result_type, + int*>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void(*)()>::result_type, + void>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::result_type, + int*>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::result_type, + int*>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::result_type, + int>::value), ""); + static_assert((std::is_same<std::reference_wrapper<C()>::result_type, + C>::value), ""); + static_assert(has_result_type<std::reference_wrapper<functor3> >::value, ""); + static_assert(!has_result_type<std::reference_wrapper<functor4> >::value, ""); + static_assert(!has_result_type<std::reference_wrapper<C> >::value, ""); +} |