From a257ab08038df7a2ef0262d04548f25e62cf7cc1 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 8 Jan 2015 06:36:41 +0000 Subject: [PATCH] In early C++11 standard drafts, std::function derived from std::unary_function or std::binary_function if there was only one (or two) parameters. Before C++11 shipped, this restiction was lifted, but libc++ still does this (which is fine). However, the tests still check for this outdated requiremnt. Change then to check for the nested typedefs instead (which are still required by the standard). No change to the library. llvm-svn: 225430 --- .../func.wrap/func.wrap.func/types.pass.cpp | 117 +++++++++++++----- 1 file changed, 88 insertions(+), 29 deletions(-) diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp index 6c70db408103..eb4eac65cd2c 100644 --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp @@ -10,40 +10,99 @@ // // template -// class function -// : public unary_function // iff sizeof...(ArgTypes) == 1 and -// // ArgTypes contains T1 -// : public binary_function // iff sizeof...(ArgTypes) == 2 and -// // ArgTypes contains T1 and T2 -// { +// class function { // public: -// typedef R result_type; -// ... -// }; +// typedef R result_type; +// typedef T1 argument_type; // iff sizeof...(ArgTypes) == 1 and +// // the type in ArgTypes is T1 +// typedef T1 first_argument_type; // iff sizeof...(ArgTypes) == 2 and +// // ArgTypes contains T1 and T2 +// typedef T2 second_argument_type; // iff sizeof...(ArgTypes) == 2 and +// // ArgTypes contains T1 and T2 +// ... +// }; #include #include + +template +class has_argument_type +{ + typedef char yes; + typedef long no; + + template static yes check( typename C::argument_type * ); + template static no check(...); +public: + enum { value = sizeof(check(0)) == sizeof(yes) }; +}; + +template +class has_first_argument_type +{ + typedef char yes; + typedef long no; + + template static yes check( typename C::first_argument_type * ); + template static no check(...); +public: + enum { value = sizeof(check(0)) == sizeof(yes) }; +}; + + +template +class has_second_argument_type +{ + typedef char yes; + typedef long no; + + template static yes check( typename C::second_argument_type *); + template static no check(...); +public: + enum { value = sizeof(check(0)) == sizeof(yes) }; +}; + +template +void test_nullary_function () +{ + static_assert((std::is_same::value), "" ); + static_assert((!has_argument_type::value), "" ); + static_assert((!has_first_argument_type::value), "" ); + static_assert((!has_second_argument_type::value), "" ); +} + +template +void test_unary_function () +{ + static_assert((std::is_same::value), "" ); + static_assert((std::is_same::value), "" ); + static_assert((!has_first_argument_type::value), "" ); + static_assert((!has_second_argument_type::value), "" ); +} + +template +void test_binary_function () +{ + static_assert((std::is_same::value), "" ); + static_assert((std::is_same::value), "" ); + static_assert((std::is_same::value), "" ); + static_assert((!has_argument_type::value), "" ); +} + +template +void test_other_function () +{ + static_assert((std::is_same::value), "" ); + static_assert((!has_argument_type::value), "" ); + static_assert((!has_first_argument_type::value), "" ); + static_assert((!has_second_argument_type::value), "" ); +} + int main() { - static_assert((!std::is_base_of, - std::function >::value), ""); - static_assert((!std::is_base_of, - std::function >::value), ""); - static_assert(( std::is_same< std::function::result_type, - int>::value), ""); - - static_assert(( std::is_base_of, - std::function >::value), ""); - static_assert((!std::is_base_of, - std::function >::value), ""); - static_assert(( std::is_same< std::function::result_type, - double>::value), ""); - - static_assert((!std::is_base_of, - std::function >::value), ""); - static_assert(( std::is_base_of, - std::function >::value), ""); - static_assert(( std::is_same< std::function::result_type, - double>::value), ""); + test_nullary_function, int>(); + test_unary_function , double, int>(); + test_binary_function , double, int, char>(); + test_other_function , double>(); }