//===----------------------------------------------------------------------===// // // 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. // //===----------------------------------------------------------------------===// // // template // class function { // public: // 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() { test_nullary_function, int>(); test_unary_function , double, int>(); test_binary_function , double, int, char>(); test_other_function , double>(); }