1// 2005-02-27 Douglas Gregor <doug.gregor -at- gmail.com> 2// 3// Copyright (C) 2005-2015 Free Software Foundation, Inc. 4// 5// This file is part of the GNU ISO C++ Library. This library is free 6// software; you can redistribute it and/or modify it under the 7// terms of the GNU General Public License as published by the 8// Free Software Foundation; either version 3, or (at your option) 9// any later version. 10// 11// This library is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15// 16// You should have received a copy of the GNU General Public License along 17// with this library; see the file COPYING3. If not see 18// <http://www.gnu.org/licenses/>. 19 20// 2.1 reference wrappers 21#include <tr1/functional> 22#include <tr1/type_traits> 23#include <testsuite_hooks.h> 24#include <testsuite_tr1.h> 25 26using namespace __gnu_test; 27 28struct X {}; 29 30struct int_result_type { typedef int result_type; }; 31 32struct derives_unary : std::unary_function<int, int> {}; 33 34struct derives_binary : std::binary_function<int, float, int> {}; 35 36struct derives_unary_binary 37 : std::unary_function<int, int>, 38 std::binary_function<int, float, int> 39{ 40 typedef int result_type; 41}; 42 43void test01() 44{ 45 bool test __attribute__((unused)) = true; 46 47 using std::tr1::reference_wrapper; 48 using std::tr1::is_same; 49 using std::tr1::is_convertible; 50 using std::unary_function; 51 using std::binary_function; 52 53 // Check result_type typedef 54 VERIFY((is_same<reference_wrapper<int_result_type>::result_type, int>::value)); 55 VERIFY((is_same<reference_wrapper<derives_unary>::result_type, int>::value)); 56 VERIFY((is_same<reference_wrapper<derives_binary>::result_type, int>::value)); 57 VERIFY((is_same<reference_wrapper<derives_unary_binary>::result_type, int>::value)); 58 VERIFY((is_same<reference_wrapper<int(void)>::result_type, int>::value)); 59 VERIFY((is_same<reference_wrapper<int(*)(void)>::result_type, int>::value)); 60 VERIFY((is_same<reference_wrapper<int (::X::*)()>::result_type, int>::value)); 61 VERIFY((is_same<reference_wrapper<int (::X::*)(float)>::result_type, int>::value)); 62 63 // Check derivation from unary_function 64 VERIFY((is_convertible<reference_wrapper<derives_unary>*, unary_function<int, int>*>::value)); 65 VERIFY((is_convertible<reference_wrapper<derives_unary_binary>*, unary_function<int, int>*>::value)); 66 VERIFY((is_convertible<reference_wrapper<int(int)>*, unary_function<int, int>*>::value)); 67 VERIFY((is_convertible<reference_wrapper<int(*)(int)>*, unary_function<int, int>*>::value)); 68 VERIFY((is_convertible<reference_wrapper<int (::X::*)()>*, unary_function< ::X*, int>*>::value)); 69 VERIFY((is_convertible<reference_wrapper<int (::X::*)() const>*, unary_function<const ::X*, int>*>::value)); 70 VERIFY((is_convertible<reference_wrapper<int (::X::*)() volatile>*, unary_function<volatile ::X*, int>*>::value)); 71 VERIFY((is_convertible<reference_wrapper<int (::X::*)() const volatile>*, unary_function<const volatile ::X*, int>*>::value)); 72 73 // Check derivation from binary_function 74 VERIFY((is_convertible<reference_wrapper<derives_binary>*, binary_function<int, float, int>*>::value)); 75 VERIFY((is_convertible<reference_wrapper<derives_unary_binary>*, binary_function<int, float, int>*>::value)); 76 VERIFY((is_convertible<reference_wrapper<int(int, float)>*, binary_function<int, float, int>*>::value)); 77 VERIFY((is_convertible<reference_wrapper<int(*)(int, float)>*, binary_function<int, float, int>*>::value)); 78 VERIFY((is_convertible<reference_wrapper<int (::X::*)(float)>*, binary_function< ::X*, float, int>*>::value)); 79 VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) const>*, binary_function<const ::X*, float, int>*>::value)); 80 VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) volatile>*, binary_function<volatile ::X*, float, int>*>::value)); 81 VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) const volatile>*, binary_function<const volatile ::X*, float, int>*>::value)); 82} 83 84int main() 85{ 86 test01(); 87 return 0; 88} 89