Skip to content

Instantly share code, notes, and snippets.

@Rockncoder
Created July 26, 2020 22:38
Show Gist options
  • Save Rockncoder/c74054a10aea9ecd9e40570e6e4660b7 to your computer and use it in GitHub Desktop.
Save Rockncoder/c74054a10aea9ecd9e40570e6e4660b7 to your computer and use it in GitHub Desktop.
C++11 Things to explore further
#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