| Hosted by CoCalc | Download
Kernel: C++17

Does it work?

#include <iostream> auto hello = "Hello World!"; std::cout << hello;
Hello World!
// or just hello
"Hello World!"
auto num = 1+1; num
2

Lambda-capture not only by reference, but also by value!

struct MyObj { int value{ 123 }; auto getValueCopy() { return [*this] { return value; }; } auto getValueRef() { return [this] { return value; }; } };
MyObj mo; auto valueCopy = mo.getValueCopy(); auto valueRef = mo.getValueRef();
mo.value = 321; valueCopy(); // 123
123
valueRef(); // 321
321

Range-based for loop

std::array<int, 5> a{ 1, 2, 3, 4, 5 }; for (int& x : a) { x = 2*x + 1; }
#include <iostream> for(auto const& x: a) { std::cout << x << " "; }
3 5 7 9 11