Skip to content

Instantly share code, notes, and snippets.

@yifu
Created September 21, 2012 14:33
Show Gist options
  • Select an option

  • Save yifu/3761809 to your computer and use it in GitHub Desktop.

Select an option

Save yifu/3761809 to your computer and use it in GitHub Desktop.
c++11 tests.
#include <iostream>
using namespace std;
/* Test the decltype feature from c++11 */
/* /Soft/mag/dev/tools/gcc-4.7.1/bin/g++ --std=c++11 lambdas.cpp && ./a.out */
// You can't use decltype operator in the return declaration part (why??).
// You need to use it in a special form. After the arrow...
template <typename T1, typename T2>
auto add(T1 x, T2 y) -> decltype (x+y) { return x + y; }
int main()
{
cout << "hello world." << endl;
cout << "add() result is [" << add( 2 , 4 ) << "]." << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment