C++Guns – RoboBlog

11.02.2015

replace templates with c++14 auto

Filed under: Allgemein — Tags: — Thomas @ 21:02

#include < iostream >

template< class T >
T func1(T t) { return t; }

auto func2(auto t) { return t; }

int main() {
  std::cout << func1(1) << func1(2.2) << func2(3) << func2(4.4);
}

autoauto.cpp:6:18: note: deduced return type only available with -std=c++1y or -std=gnu++1y

g++ --std=c++14 autoauto.cpp 
./a.out 
12.234.4

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress