OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc2/] [gcc/] [testsuite/] [g++.dg/] [cpp0x/] [variadic-mem_fn.C] - Diff between revs 301 and 384

Only display areas with differences | Details | Blame | View Log

Rev 301 Rev 384
// { dg-options "-std=gnu++0x" }
// { dg-options "-std=gnu++0x" }
// { dg-do "run" }
// { dg-do "run" }
// A basic implementation of TR1's mem_fn using variadic teplates
// A basic implementation of TR1's mem_fn using variadic teplates
// Contributed by Douglas Gregor 
// Contributed by Douglas Gregor 
#include 
#include 
template
template
class Mem_fn
class Mem_fn
{
{
 public:
 public:
  explicit Mem_fn(R (Class::*pmf)(Args...)) : pmf(pmf) { }
  explicit Mem_fn(R (Class::*pmf)(Args...)) : pmf(pmf) { }
  R operator()(Class& object, Args... args)
  R operator()(Class& object, Args... args)
  {
  {
    return (object.*pmf)(args...);
    return (object.*pmf)(args...);
  }
  }
  R operator()(Class* object, Args... args)
  R operator()(Class* object, Args... args)
  {
  {
    return (object->*pmf)(args...);
    return (object->*pmf)(args...);
  }
  }
  R (Class::*pmf)(Args...);
  R (Class::*pmf)(Args...);
};
};
template
template
inline Mem_fn
inline Mem_fn
mem_fn(R (Class::* pmf)(Args...))
mem_fn(R (Class::* pmf)(Args...))
{
{
  return Mem_fn(pmf);
  return Mem_fn(pmf);
}
}
class X {
class X {
 public:
 public:
  int negate(int x) { return -x; }
  int negate(int x) { return -x; }
  int plus(int x, int y) { return x + y; }
  int plus(int x, int y) { return x + y; }
};
};
int main()
int main()
{
{
  X x;
  X x;
  X* xp = &x;
  X* xp = &x;
  assert(mem_fn(&X::negate)(x, 17) == -17);
  assert(mem_fn(&X::negate)(x, 17) == -17);
  assert(mem_fn(&X::negate)(xp, 17) == -17);
  assert(mem_fn(&X::negate)(xp, 17) == -17);
  assert(mem_fn(&X::plus)(x, 17, 25) == 42);
  assert(mem_fn(&X::plus)(x, 17, 25) == 42);
  assert(mem_fn(&X::plus)(xp, 17, 25) == 42);
  assert(mem_fn(&X::plus)(xp, 17, 25) == 42);
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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