[libcxx] r225430 - 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.
Marshall Clow
mclow.lists at gmail.com
Wed Jan 7 22:36:42 PST 2015
Author: marshall
Date: Thu Jan 8 00:36:41 2015
New Revision: 225430
URL: http://llvm.org/viewvc/llvm-project?rev=225430&view=rev
Log:
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.
Modified:
libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp
Modified: libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp?rev=225430&r1=225429&r2=225430&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp Thu Jan 8 00:36:41 2015
@@ -10,40 +10,99 @@
// <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
-// {
+// class function<R(ArgTypes...)> {
// 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 <functional>
#include <type_traits>
+
+template <typename T>
+class has_argument_type
+{
+ typedef char yes;
+ typedef long no;
+
+ template <typename C> static yes check( typename C::argument_type * );
+ template <typename C> static no check(...);
+public:
+ enum { value = sizeof(check<T>(0)) == sizeof(yes) };
+};
+
+template <typename T>
+class has_first_argument_type
+{
+ typedef char yes;
+ typedef long no;
+
+ template <typename C> static yes check( typename C::first_argument_type * );
+ template <typename C> static no check(...);
+public:
+ enum { value = sizeof(check<T>(0)) == sizeof(yes) };
+};
+
+
+template <typename T>
+class has_second_argument_type
+{
+ typedef char yes;
+ typedef long no;
+
+ template <typename C> static yes check( typename C::second_argument_type *);
+ template <typename C> static no check(...);
+public:
+ enum { value = sizeof(check<T>(0)) == sizeof(yes) };
+};
+
+template <class F, class return_type>
+void test_nullary_function ()
+{
+ static_assert((std::is_same<typename F::result_type, return_type>::value), "" );
+ static_assert((!has_argument_type<F>::value), "" );
+ static_assert((!has_first_argument_type<F>::value), "" );
+ static_assert((!has_second_argument_type<F>::value), "" );
+}
+
+template <class F, class return_type, class arg_type>
+void test_unary_function ()
+{
+ static_assert((std::is_same<typename F::result_type, return_type>::value), "" );
+ static_assert((std::is_same<typename F::argument_type, arg_type>::value), "" );
+ static_assert((!has_first_argument_type<F>::value), "" );
+ static_assert((!has_second_argument_type<F>::value), "" );
+}
+
+template <class F, class return_type, class arg_type1, class arg_type2>
+void test_binary_function ()
+{
+ static_assert((std::is_same<typename F::result_type, return_type>::value), "" );
+ static_assert((std::is_same<typename F::first_argument_type, arg_type1>::value), "" );
+ static_assert((std::is_same<typename F::second_argument_type, arg_type2>::value), "" );
+ static_assert((!has_argument_type<F>::value), "" );
+}
+
+template <class F, class return_type>
+void test_other_function ()
+{
+ static_assert((std::is_same<typename F::result_type, return_type>::value), "" );
+ static_assert((!has_argument_type<F>::value), "" );
+ static_assert((!has_first_argument_type<F>::value), "" );
+ static_assert((!has_second_argument_type<F>::value), "" );
+}
+
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), "");
+ test_nullary_function<std::function<int()>, int>();
+ test_unary_function <std::function<double(int)>, double, int>();
+ test_binary_function <std::function<double(int, char)>, double, int, char>();
+ test_other_function <std::function<double(int, char, double)>, double>();
}
More information about the cfe-commits
mailing list