Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.
Scope and conventions
TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.
int has implementation-defined width; double is floating point. std::string owns text; string_view borrows character storage, which must outlive the view. char[N] is a fixed-size array.
Fragment
Headers plus local fragments; name outlives view.
main.cpp
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
#include <string>#include <string_view>std::string name = "north";std::string_view view = name;char buffer[3]{};
:: qualifies a name. T& is a reference; &value takes an address. const T& is a read-only access path, not a promise that no one can mutate T. << and >> are stream operators here.
optional<T> contains a value or no value; an engaged optional holding 0 is still present. nullptr is a null pointer literal, not a general missing-value sentinel. Dereference an optional only when engaged.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
main.cpp
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
#include <optional>std::optional<int> score = 0;if (score.has_value()) { int value = *score;}int fallback = score.value_or(10);
struct members default to public. A simple aggregate can initialize fields in declaration order with braces. const on the object prevents ordinary field mutation through it.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
main.cpp
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
struct Point { int x; int y;};Point point{2, 5};point.y = 8;
tuple/pair group values; a structured binding introduces names for their elements. auto [a, b] copies here; auto& [a, b] binds to the original tuple’s elements.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
enum class names scoped constants. std::variant holds one alternative type at a time, including payloads; it is a different facility from an enum. Query or visit it before extracting the expected alternative.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
main.cpp
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
#include <variant>#include <string>enum class Mode { Read, Write };std::variant<int, std::string> reply = 24;if (auto* value = std::get_if<int>(&reply)) { int count = *value;}
A template generates definitions for type arguments. Function calls can deduce T; explicit arguments use <T>. C++20 concepts/requires can constrain templates without a shared virtual base class.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
An abstract base with pure virtual methods is one runtime-polymorphic contract. override verifies that a derived method overrides a base method. A virtual destructor permits safe deletion through this base.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
main.cpp
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
struct Named { virtual const char* name() const = 0; virtual ~Named() = default;};struct Place : Named { const char* name() const override { return "north"; }};
static_cast explicitly requests a permitted conversion, not a range check. Brace initialization rejects many narrowing conversions. dynamic_cast performs a checked down/cross-cast in a suitable polymorphic hierarchy.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
main.cpp
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
double ratio = 2.5;int truncated = static_cast<int>(ratio);// int rejected{ratio}; // narrowing: compile error