#include <iostream>
using namespace std;

template <typename Fnc, typename Args>
void t (Fnc f, Args arg) {
  f (arg);
}

void foo (int x) {
  cout<<x;
}
void bar (int& x) {
  cout << ++x;
}

template <typename T>
struct refholder {
  T *ptr;
  refholder(T& x):ptr(&x){}
  operator T& () { return *ptr; }
};

template <typename T>
refholder<T> makeref (T& x) {
  return refholder<T>(x);
}

int main () {
  int x=2;
  t (foo, x);
  t (bar, makeref(x));
  cout << x;
}
