OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [20_util/] [function/] [1.cc] - Blame information for rev 749

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// { dg-options "-std=gnu++0x" }
2
// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu>
3
//
4
// Copyright (C) 2005, 2009 Free Software Foundation, Inc.
5
//
6
// This file is part of the GNU ISO C++ Library.  This library is free
7
// software; you can redistribute it and/or modify it under the
8
// terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 3, or (at your option)
10
// any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU General Public License along
18
// with this library; see the file COPYING3.  If not see
19
// <http://www.gnu.org/licenses/>.
20
 
21
// 20.7.15 polymorphic function object wrapper
22
#include <functional>
23
#include <testsuite_hooks.h>
24
 
25
using namespace __gnu_test;
26
 
27
bool test __attribute__((unused)) = true;
28
 
29
// Operations on empty function<> objects
30
void test01()
31
{
32
  using std::function;
33
  using std::bad_function_call;
34
 
35
  // Default-construction
36
  function<int(float)> f1;
37
  VERIFY( ((bool)f1 == false) );
38
  VERIFY( !f1 );
39
  VERIFY( f1 == 0 );
40
  VERIFY( 0 == f1 );
41
  VERIFY( !(f1 != 0) );
42
  VERIFY( !(0 != f1) );
43
 
44
  // Copy-construction
45
  function<int(float)> f2(f1);
46
  VERIFY( !f2 );
47
 
48
  // Construct with NULL pointer
49
  function<int(float)> f3(0);
50
  VERIFY( !f3 );
51
 
52
  // Assignment
53
  f1 = f2;
54
  VERIFY( !f1);
55
 
56
  // Assignment to NULL pointer
57
  f1 = 0;
58
  VERIFY( !f1 );
59
 
60
  // Swap
61
  swap(f1, f2);
62
  VERIFY( !f1 );
63
  VERIFY( !f2 );
64
 
65
  // Invocation should throw bad_function_call
66
  bool thrown = false;
67
  try
68
    {
69
      f1(3.14159f);
70
      VERIFY( false );
71
    }
72
  catch (bad_function_call)
73
    {
74
      thrown = true;
75
    }
76
  VERIFY( thrown );
77
 
78
  // target_type returns typeid(void)
79
  VERIFY( f1.target_type() == typeid(void) );
80
 
81
  // target() always returns a NULL pointer
82
  VERIFY( f1.target<int (*)(float)>() == 0);
83
 
84
  // Check const version
85
  const function<int(float)>& f1c = f1;
86
  VERIFY( f1c.target<int (*)(float)>() == 0 );
87
  VERIFY( !f1c );
88
}
89
 
90
int main()
91
{
92
  test01();
93
  return 0;
94
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.