\hypertarget{variant_8cpp_source}{}\doxysection{variant.\+cpp}
\label{variant_8cpp_source}\index{tests/variant.cpp@{tests/variant.cpp}}
\mbox{\hyperlink{variant_8cpp}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00001}00001 \textcolor{preprocessor}{\#include "{}catch.hpp"{}}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00002}00002 \textcolor{preprocessor}{\#include <chrono>}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00003}00003 \textcolor{preprocessor}{\#include <iostream>}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00004}00004 \textcolor{preprocessor}{\#include <map>}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00005}00005 \textcolor{preprocessor}{\#include <string\_view>}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00006}00006 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00007}00007 \textcolor{preprocessor}{\#include "{}\mbox{\hyperlink{variant_8h}{kblib/variant.h}}"{}}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00008}00008 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00009}00009 \textcolor{preprocessor}{\#include "{}\mbox{\hyperlink{hash_8h}{kblib/hash.h}}"{}}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00010}00010 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00011}00011 \textcolor{preprocessor}{\#if KBLIB\_USE\_CXX17}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00012}00012 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00013}\mbox{\hyperlink{variant_8cpp_a0a93b8d4e264dcba26174dacf7057799}{00013}} \mbox{\hyperlink{variant_8cpp_a0a93b8d4e264dcba26174dacf7057799}{TEST\_CASE}}(\textcolor{stringliteral}{"{}visit"{}}) \{}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00014}00014    std::variant<std::monostate, int, std::string> var = 10;}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00015}00015 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00016}00016    \textcolor{comment}{// standard syntax (with visitor helper):}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00017}00017    \mbox{\hyperlink{namespacekblib_af1f6dd52b7ce14276ab5509700c6acf1}{std::visit}}(\mbox{\hyperlink{structkblib_1_1visitor}{kblib::visitor}}\{[](std::monostate) \{ REQUIRE(\textcolor{keyword}{false}); \},}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00018}00018                              [](int) \{ REQUIRE(\textcolor{keyword}{true}); \},}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00019}00019                              [](\textcolor{keyword}{const} std::string\&) \{ REQUIRE(\textcolor{keyword}{false}); \}\},}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00020}00020               var);}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00021}00021 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00022}00022    \textcolor{comment}{// Basic single-\/variant syntax:}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00023}00023    \mbox{\hyperlink{namespacekblib_af1f6dd52b7ce14276ab5509700c6acf1}{kblib::visit}}(}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00024}00024        var, [](std::monostate) \{ REQUIRE(\textcolor{keyword}{false}); \}, [](int) \{ REQUIRE(\textcolor{keyword}{true}); \},}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00025}00025        [](\textcolor{keyword}{const} std::string\&) \{ REQUIRE(\textcolor{keyword}{false}); \});}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00026}00026 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00027}00027    \textcolor{comment}{// Pattern-\/matching-\/like syntax:}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00028}00028    \mbox{\hyperlink{namespacekblib_af1f6dd52b7ce14276ab5509700c6acf1}{kblib::visit}}(var)([](std::monostate) \{ REQUIRE(\textcolor{keyword}{false}); \},}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00029}00029                      [](int) \{ REQUIRE(\textcolor{keyword}{true}); \},}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00030}00030                      [](\textcolor{keyword}{const} std::string\&) \{ REQUIRE(\textcolor{keyword}{false}); \});}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00031}00031 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00032}00032    \textcolor{comment}{// kblib::visit2(var, [](int) \{\});}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00033}00033 \}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00034}00034 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00035}\mbox{\hyperlink{variant_8cpp_a7b8aaf4c6bf90da57f4def3fce0a821e}{00035}} \mbox{\hyperlink{variant_8cpp_a0a93b8d4e264dcba26174dacf7057799}{TEST\_CASE}}(\textcolor{stringliteral}{"{}visit\_indexed"{}}) \{}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00036}00036    std::variant<std::monostate, int, std::string> var(std::in\_place\_type<int>,}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00037}00037                                                       10);}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00038}00038    \mbox{\hyperlink{namespacekblib_a7600c651ddd193dfeb5d294732ab1e69}{kblib::visit\_indexed}}(var, [](\textcolor{keyword}{auto} constant, \textcolor{keyword}{auto} val) \{}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00039}00039       REQUIRE(constant == 1);}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00040}00040       \textcolor{keyword}{static\_assert}(}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00041}00041           std::is\_same\_v<\textcolor{keyword}{decltype}(val),}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00042}00042                          std::variant\_alternative\_t<constant, \textcolor{keyword}{decltype}(var)>>);}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00043}00043    \});}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00044}00044 \}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00045}00045 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00046}\mbox{\hyperlink{variant_8cpp_ae21437c8356e20eaf36169a0c6601454}{00046}} \mbox{\hyperlink{variant_8cpp_a0a93b8d4e264dcba26174dacf7057799}{TEST\_CASE}}(\textcolor{stringliteral}{"{}variant\_cast"{}}) \{}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00047}00047    std::variant<int, std::string> from(std::in\_place\_type<int>, 10);}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00048}00048    \textcolor{keyword}{auto} to}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00049}00049        = kblib::variant\_cast<std::variant<std::monostate, int, std::string>>(}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00050}00050            from);}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00051}00051    REQUIRE(to.index() == 1);}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00052}00052 \}}
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00053}00053 }
\DoxyCodeLine{\Hypertarget{variant_8cpp_source_l00054}00054 \textcolor{preprocessor}{\#endif}}

\end{DoxyCode}
