Created
July 26, 2020 22:38
-
-
Save Rockncoder/c74054a10aea9ecd9e40570e6e4660b7 to your computer and use it in GitHub Desktop.
C++11 Things to explore further
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; | |
int main() { | |
int array[] = {1, 2, 3, 4, 5}; | |
long sum = 0; | |
for (const int x: array) { | |
sum += x; | |
} | |
// items in the range for loop can be dynamic | |
for (auto elem : {sum, sum * 2, sum * 3}) { | |
cout << elem << '\n'; | |
} | |
// using a raw string | |
cout << R"(\\\n)" << '\n'; | |
// IIFE in C++ (immediately invoked function expression) | |
[] { | |
std::cout << "hello lambda" << std::endl; | |
}(); | |
// using IIFE to initialize a variable and give it a type | |
auto myType = []() -> double { return 42; }(); | |
cout << "myType = " << myType << " : " << typeid(myType).name() << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment