top of page
c++ 2017

C++ 2017 [OFFICIAL]

std::optional<int> parse_int(const std::string& s) try return std::stoi(s); catch(...) return std::nullopt;

template<auto N> struct Foo ; Foo<42> f1; Foo<'c'> f2; 3.1 std::optional<T> A type-safe wrapper that may or may not hold a value.

template <typename T> auto to_string(const T& t) if constexpr (std::is_integral_v<T>) return std::to_string(t); else return std::string(t); // only instantiated if T is not integral c++ 2017

Compile-time conditional compilation inside templates, discarding non-taken branches entirely.

std::variant<int, float, std::string> v = "hello"; std::visit([](auto&& arg) std::cout << arg; , v); Type-erased container for any copyable type. if (auto it = m

if (auto it = m.find(key); it != m.end()) // use it here // it goes out of scope Permits defining variables in header files without violating the One Definition Rule (ODR). Essential for header-only libraries.

// in a header inline int global_counter = 0; Mandates copy elision for prvalues, making certain moves/constructors unnecessary even conceptually. std::any a = 42; int value = std::any_cast&lt;int&gt;(a);

std::any a = 42; int value = std::any_cast<int>(a); Non-owning reference to a string-like sequence. Ideal for function parameters.

© 2026 Daily Lantern. All rights reserved.. All Rights Reserved.

bottom of page