fork download
  1. #include <type_traits>
  2. #include <utility>
  3. #include <iostream>
  4.  
  5. template <class F, class A> auto Call(
  6. typename std::remove_reference<F>::type && f,
  7. typename std::remove_reference<A>::type && a
  8. ) -> decltype(f(std::forward<A>(a))) {
  9. return f(std::forward<A>(a));
  10. }
  11.  
  12. struct Hoge { };
  13.  
  14. struct Func {
  15. void operator () (Hoge const & hoge) const {
  16. std::cout << "Hoge const &" << std::endl;
  17. }
  18. void operator () (Hoge && hoge) const {
  19. std::cout << "Hoge &&" << std::endl;
  20. }
  21. };
  22.  
  23. int main(void) {
  24. Call<Func,Hoge>(Func(), Hoge());
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
Hoge &&