diff options
Diffstat (limited to 'libcxx/test/depr/depr.lib.binders')
6 files changed, 209 insertions, 0 deletions
diff --git a/libcxx/test/depr/depr.lib.binders/depr.lib.bind.1st/bind1st.pass.cpp b/libcxx/test/depr/depr.lib.binders/depr.lib.bind.1st/bind1st.pass.cpp new file mode 100644 index 00000000000..9d167026f99 --- /dev/null +++ b/libcxx/test/depr/depr.lib.binders/depr.lib.bind.1st/bind1st.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <class Fn, class T> +// binder1st<Fn> +// bind1st(const Fn& fn, const T& x); + +#include <functional> +#include <cassert> + +#include "../test_func.h" + +int main() +{ + assert(std::bind1st(test_func(1), 5)(10.) == -5.); +} diff --git a/libcxx/test/depr/depr.lib.binders/depr.lib.bind.2nd/bind2nd.pass.cpp b/libcxx/test/depr/depr.lib.binders/depr.lib.bind.2nd/bind2nd.pass.cpp new file mode 100644 index 00000000000..ed1f706984e --- /dev/null +++ b/libcxx/test/depr/depr.lib.binders/depr.lib.bind.2nd/bind2nd.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <class Fn, class T> +// binder2nd<Fn> +// bind2nd(const Fn& op, const T& x); + +#include <functional> +#include <cassert> + +#include "../test_func.h" + +int main() +{ + assert(std::bind2nd(test_func(1), 5)(10) == 5.); +} diff --git a/libcxx/test/depr/depr.lib.binders/depr.lib.binder.1st/binder1st.pass.cpp b/libcxx/test/depr/depr.lib.binders/depr.lib.binder.1st/binder1st.pass.cpp new file mode 100644 index 00000000000..f998421ac77 --- /dev/null +++ b/libcxx/test/depr/depr.lib.binders/depr.lib.binder.1st/binder1st.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <class Fn> +// class binder1st +// : public unary_function<typename Fn::second_argument_type, typename Fn::result_type> +// { +// protected: +// Fn op; +// typename Fn::first_argument_type value; +// public: +// binder2nd(const Fn& x, const typename Fn::second_argument_type& y); +// +// typename Fn::result_type operator()(const typename Fn::first_argument_type& x) const; +// typename Fn::result_type operator()(typename Fn::first_argument_type& x) const; +// }; + +#include <functional> +#include <type_traits> +#include <cassert> + +#include "../test_func.h" + +class test + : public std::binder1st<test_func> +{ + typedef std::binder1st<test_func> base; +public: + test() : std::binder1st<test_func>(test_func(2), 30) {} + + void do_test() + { + static_assert((std::is_base_of< + std::unary_function<test_func::second_argument_type, + test_func::result_type>, + test>::value), ""); + assert(op.id() == 2); + assert(value == 30); + + double d = 5; + assert((*this)(d) == 35); + assert((*this)(5) == 25); + } +}; + +int main() +{ + test t; + t.do_test(); +} diff --git a/libcxx/test/depr/depr.lib.binders/depr.lib.binder.2nd/binder2nd.pass.cpp b/libcxx/test/depr/depr.lib.binders/depr.lib.binder.2nd/binder2nd.pass.cpp new file mode 100644 index 00000000000..44770570cb9 --- /dev/null +++ b/libcxx/test/depr/depr.lib.binders/depr.lib.binder.2nd/binder2nd.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <class Fn> +// class binder2nd +// : public unary_function<typename Fn::first_argument_type, typename Fn::result_type> +// { +// protected: +// Fn op; +// typename Fn::second_argument_type value; +// public: +// binder2nd(const Fn& x, const typename Fn::second_argument_type& y); +// +// typename Fn::result_type operator()(const typename Fn::first_argument_type& x) const; +// typename Fn::result_type operator()(typename Fn::first_argument_type& x) const; +// }; + +#include <functional> +#include <type_traits> +#include <cassert> + +#include "../test_func.h" + +class test + : public std::binder2nd<test_func> +{ + typedef std::binder2nd<test_func> base; +public: + test() : std::binder2nd<test_func>(test_func(3), 4.5) {} + + void do_test() + { + static_assert((std::is_base_of< + std::unary_function<test_func::first_argument_type, + test_func::result_type>, + test>::value), ""); + assert(op.id() == 3); + assert(value == 4.5); + + int i = 5; + assert((*this)(i) == 22.5); + assert((*this)(5) == 0.5); + } +}; + +int main() +{ + test t; + t.do_test(); +} diff --git a/libcxx/test/depr/depr.lib.binders/nothing_to_do.pass.cpp b/libcxx/test/depr/depr.lib.binders/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..fa4d462f18d --- /dev/null +++ b/libcxx/test/depr/depr.lib.binders/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/depr/depr.lib.binders/test_func.h b/libcxx/test/depr/depr.lib.binders/test_func.h new file mode 100644 index 00000000000..1535f340bec --- /dev/null +++ b/libcxx/test/depr/depr.lib.binders/test_func.h @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef TEST_FUNC_H +#define TEST_FUNC_H + +class test_func +{ + int id_; +public: + typedef int first_argument_type; + typedef double second_argument_type; + typedef long double result_type; + + explicit test_func(int id) : id_(id) {} + + int id() const {return id_;} + + result_type operator() (const first_argument_type& x, second_argument_type& y) const + {return x+y;} + result_type operator() (const first_argument_type& x, const second_argument_type& y) const + {return x-y;} + result_type operator() (first_argument_type& x, const second_argument_type& y) const + {return x*y;} +}; + +#endif |