1// { dg-options "-std=gnu++0x" } 2 3// Copyright (C) 2008, 2009, 2010 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#include <functional> 21#include <type_traits> 22#include <testsuite_hooks.h> 23#include <testsuite_tr1.h> 24 25using namespace __gnu_test; 26 27bool test __attribute__((unused)) = true; 28 29struct X 30{ 31 typedef int result_type; 32 33 X() : bar(17) {} 34 35 int foo(float x) { return truncate_float(x); } 36 int foo_c(float x) const { return truncate_float(x); } 37 int foo_v(float x) volatile { return truncate_float(x); } 38 int foo_cv(float x) const volatile { return truncate_float(x); } 39 40 int operator()(float x) 41 { 42 return foo(x) + 1; 43 } 44 45 int operator()(float x) const 46 { 47 return foo_c(x) + 2; 48 } 49 50 int bar; 51 52 private: 53 X(const X&); 54 X& operator=(const X&); 55}; 56 57int seventeen() { return 17; } 58 59struct get_seventeen 60{ 61 typedef int result_type; 62 int operator()() const { return 17; } 63}; 64 65void test01() 66{ 67 using std::ref; 68 using std::cref; 69 70 ::get_seventeen get_sev; 71 ::X x; 72 73 const float pi = 3.14; 74 75 // Functions 76 VERIFY(ref(truncate_float)(pi) == 3); 77 VERIFY(ref(seventeen)() == 17); 78 79 // Function pointers 80 VERIFY(cref(&truncate_float)(pi) == 3); 81 VERIFY(cref(&seventeen)() == 17); 82 83 // Function objects 84 VERIFY(ref(get_sev)() == 17); 85 VERIFY(cref(get_sev)() == 17); 86 VERIFY(ref(x)(pi) == 4); 87 VERIFY(cref(x)(pi) == 5); 88} 89 90int main() 91{ 92 test01(); 93 return 0; 94} 95