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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [cpp0x/] [variadic-mem_fn.C] - Blame information for rev 774

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

Line No. Rev Author Line
1 693 jeremybenn
// { dg-options "-std=gnu++0x" }
2
// { dg-do run }
3
// A basic implementation of TR1's mem_fn using variadic teplates
4
// Contributed by Douglas Gregor 
5
#include 
6
 
7
template
8
class Mem_fn
9
{
10
 public:
11
  explicit Mem_fn(R (Class::*pmf)(Args...)) : pmf(pmf) { }
12
 
13
  R operator()(Class& object, Args... args)
14
  {
15
    return (object.*pmf)(args...);
16
  }
17
 
18
  R operator()(Class* object, Args... args)
19
  {
20
    return (object->*pmf)(args...);
21
  }
22
 
23
  R (Class::*pmf)(Args...);
24
};
25
 
26
template
27
inline Mem_fn
28
mem_fn(R (Class::* pmf)(Args...))
29
{
30
  return Mem_fn(pmf);
31
}
32
 
33
class X {
34
 public:
35
  int negate(int x) { return -x; }
36
  int plus(int x, int y) { return x + y; }
37
};
38
 
39
int main()
40
{
41
  X x;
42
  X* xp = &x;
43
 
44
  assert(mem_fn(&X::negate)(x, 17) == -17);
45
  assert(mem_fn(&X::negate)(xp, 17) == -17);
46
  assert(mem_fn(&X::plus)(x, 17, 25) == 42);
47
  assert(mem_fn(&X::plus)(xp, 17, 25) == 42);
48
 
49
  return 0;
50
}

powered by: WebSVN 2.1.0

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