Created
September 21, 2012 14:33
-
-
Save yifu/3761809 to your computer and use it in GitHub Desktop.
c++11 tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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