CoCalc Public Filesxeus-cling-cpp17.ipynbOpen with one click!
Author: Harald Schilly
Views : 108
Description: c++ 17 via xeus-cling
Compute Environment: Ubuntu 18.04 (Deprecated)

Does it work?

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

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

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

Range-based for loop

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