Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
None
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <iostream> #include <random> #include <vector> #include <string> #include <algorithm> #include <variant> #include <iomanip> template<typename ... Lambdas> struct Visitor : Lambdas... { Visitor(Lambdas... lambdas) : Lambdas(std::forward<Lambdas>(lambdas))... { } using Lambdas::operator()...; }; using var_t = std::variant<int, double, std::string>; int main(){ std::vector<var_t> vec = {10, 1.5, "hello"}; std::for_each(vec.begin(), vec.end(), [](const auto& v) { std::visit(Visitor{ [](int arg) { std::cout << arg << ' '; }, [](double arg) { std::cout << std::fixed << arg << ' '; }, [](const std::string& arg) { std::cout << std::quoted(arg) << ' '; } } , v); }); }
Insight:
Console: