Skip to main content

Checkpoint: Describe a variant

Challenge on lesson: Checkpoint: One Function, Three Types

Implement std::string describe(const std::variant<int, double, std::string>& v) returning exactly "int: 42", "double: 3.50" (always two decimals), or "string: hi" depending on the held alternative. Use std::visit with a generic lambda and if constexpr — no manual index() branching.

Difficulty: intermediate

Back to lesson: Checkpoint: One Function, Three Types