Something went wrong. Try again.
A Tour of C++ for experienced programmers, as if C++26 is the only version that ever existed.
Something went wrong. Try again.
123456789101112131415161718192021222324252627#include <iostream>
// Structural non‑type template parameter.// The type must be a structural type: all members are public, no mutable, no user‑declared constructor.
struct Config { int a; double b;};
// The template takes a Config as a compile‑time value.
template<Config C>struct UseConfig { static constexpr int val_a = C.a; static constexpr double val_b = C.b;};
int main() { // Instantiate with a concrete Config value. using My = UseConfig<Config{3, 4.5}>; static_assert(My::val_a == 3); static_assert(My::val_b == 4.5); std::cout << "config a=" << My::val_a << " b=" << My::val_b << std::endl; return 0;}