\hypertarget{simple_8cpp_source}{}\doxysection{simple.\+cpp} \label{simple_8cpp_source}\index{tests/simple.cpp@{tests/simple.cpp}} \mbox{\hyperlink{simple_8cpp}{Go to the documentation of this file.}} \begin{DoxyCode}{0} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00001}00001 \textcolor{preprocessor}{\#include "{}\mbox{\hyperlink{simple_8h}{kblib/simple.h}}"{}}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00002}00002 \textcolor{preprocessor}{\#include "{}catch.hpp"{}}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00003}00003 \textcolor{preprocessor}{\#include "{}\mbox{\hyperlink{stats_8h}{kblib/stats.h}}"{}}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00004}00004 } \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00005}00005 \textcolor{keyword}{template} <\textcolor{keyword}{typename}>} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00006}00006 \textcolor{keyword}{struct }\mbox{\hyperlink{structprint}{print}};} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00007}00007 } \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00008}\mbox{\hyperlink{simple_8cpp_a6e41b794c3fdf91f9046ef538245e798}{00008}} \mbox{\hyperlink{simple_8cpp_a6e41b794c3fdf91f9046ef538245e798}{TEST\_CASE}}(\textcolor{stringliteral}{"{}enumerate"{}}) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00009}00009 std::vector persistent\{0, 1, 1, 2, 3, 5, 8\};} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00010}00010 SECTION(\textcolor{stringliteral}{"{}lvalue"{}}) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00011}00011 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} t : \mbox{\hyperlink{namespacekblib_af60faf67d8fc0ac030f8a2cb27514eed}{kblib::enumerate}}(persistent)) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00012}00012 \textcolor{keyword}{auto}\& v = std::get<0>(t);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00013}00013 \textcolor{keyword}{auto} i = \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{int}\textcolor{keyword}{>}(std::get<1>(t));} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00014}00014 REQUIRE(v == \mbox{\hyperlink{namespacekblib_a23d97429c2ea683b83b8223699b30c68}{kblib::fibonacci}}(i));} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00015}00015 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00016}00016 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00017}00017 SECTION(\textcolor{stringliteral}{"{}const lvalue"{}}) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00018}00018 \textcolor{keyword}{const} \textcolor{keyword}{auto}\& cp = persistent;} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00019}00019 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} t : \mbox{\hyperlink{namespacekblib_af60faf67d8fc0ac030f8a2cb27514eed}{kblib::enumerate}}(cp)) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00020}00020 \textcolor{keyword}{auto}\& v = std::get<0>(t);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00021}00021 \textcolor{keyword}{auto} i = \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{int}\textcolor{keyword}{>}(std::get<1>(t));} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00022}00022 REQUIRE(v == \mbox{\hyperlink{namespacekblib_a23d97429c2ea683b83b8223699b30c68}{kblib::fibonacci}}(i));} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00023}00023 \textcolor{keyword}{static\_assert}(} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00024}00024 std::is\_const<} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00025}00025 \textcolor{keyword}{typename} std::remove\_reference<\textcolor{keyword}{decltype}(v)>::type>::value,} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00026}00026 \textcolor{stringliteral}{"{}v must refer to const when the range is const"{}});} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00027}00027 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00028}00028 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00029}00029 } \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00030}00030 SECTION(\textcolor{stringliteral}{"{}iterators"{}}) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00031}00031 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} t : \mbox{\hyperlink{namespacekblib_af60faf67d8fc0ac030f8a2cb27514eed}{kblib::enumerate}}(persistent.cbegin(), persistent.cend())) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00032}00032 \textcolor{keyword}{auto}\& v = std::get<0>(t);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00033}00033 \textcolor{keyword}{auto} i = \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{int}\textcolor{keyword}{>}(std::get<1>(t));} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00034}00034 REQUIRE(v == \mbox{\hyperlink{namespacekblib_a23d97429c2ea683b83b8223699b30c68}{kblib::fibonacci}}(i));} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00035}00035 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00036}00036 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00037}00037 SECTION(\textcolor{stringliteral}{"{}mutable iterators"{}}) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00038}00038 std::vector \mbox{\hyperlink{namespacekblib_a72690688922a2d4ae9a3e46ff0c1a9a9}{range}}\{0, 1, 2, 3, 4, 5, 6, 7\};} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00039}00039 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} t : \mbox{\hyperlink{namespacekblib_af60faf67d8fc0ac030f8a2cb27514eed}{kblib::enumerate}}(\mbox{\hyperlink{namespacekblib_a72690688922a2d4ae9a3e46ff0c1a9a9}{range}}.begin(), \mbox{\hyperlink{namespacekblib_a72690688922a2d4ae9a3e46ff0c1a9a9}{range}}.end())) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00040}00040 \textcolor{keyword}{auto}\& v = std::get<0>(t);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00041}00041 [[gnu::unused]] \textcolor{keyword}{auto}\& i = std::get<1>(t);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00042}00042 v = 0;} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00043}00043 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00044}00044 REQUIRE(\mbox{\hyperlink{namespacekblib_ab437bea5ac232c0a681f8bb1d3754170}{std::all\_of}}(\mbox{\hyperlink{namespacekblib_a72690688922a2d4ae9a3e46ff0c1a9a9}{range}}.begin(), \mbox{\hyperlink{namespacekblib_a72690688922a2d4ae9a3e46ff0c1a9a9}{range}}.end(),} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00045}00045 [](\textcolor{keywordtype}{int} v) \{ return v == 0; \}));} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00046}00046 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00047}00047 SECTION(\textcolor{stringliteral}{"{}reverse iterators"{}}) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00048}00048 std::vector reversed\{7, 6, 5, 4, 3, 2, 1, 0\};} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00049}00049 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} t : \mbox{\hyperlink{namespacekblib_af60faf67d8fc0ac030f8a2cb27514eed}{kblib::enumerate}}(reversed.rbegin(), reversed.rend())) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00050}00050 \textcolor{keyword}{auto}\& v = std::get<0>(t);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00051}00051 \textcolor{keyword}{auto}\& i = std::get<1>(t);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00052}00052 REQUIRE(v == i);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00053}00053 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00054}00054 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00055}00055 } \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00056}00056 SECTION(\textcolor{stringliteral}{"{}temporary"{}}) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00057}00057 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} t : \mbox{\hyperlink{namespacekblib_af60faf67d8fc0ac030f8a2cb27514eed}{kblib::enumerate}}(} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00058}00058 std::vector\{0, 1, 1, 2, 3, 5, 8\})) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00059}00059 \textcolor{keyword}{auto}\& v = std::get<0>(t);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00060}00060 \textcolor{keyword}{auto} i = \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{int}\textcolor{keyword}{>}(std::get<1>(t));} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00061}00061 REQUIRE(v == \mbox{\hyperlink{namespacekblib_a23d97429c2ea683b83b8223699b30c68}{kblib::fibonacci}}(i));} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00062}00062 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00063}00063 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00064}00064 SECTION(\textcolor{stringliteral}{"{}vector"{}}) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00065}00065 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} t : \mbox{\hyperlink{namespacekblib_af60faf67d8fc0ac030f8a2cb27514eed}{kblib::enumerate}}(} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00066}00066 std::vector\{\textcolor{keyword}{false}, \textcolor{keyword}{true}, \textcolor{keyword}{false}, \textcolor{keyword}{true}, \textcolor{keyword}{false}\})) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00067}00067 \textcolor{keyword}{auto}\& v = std::get<0>(t);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00068}00068 \textcolor{keyword}{auto}\& i = std::get<1>(t);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00069}00069 REQUIRE(v == i \% 2);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00070}00070 \textcolor{comment}{// print\{\};}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00071}00071 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00072}00072 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00073}00073 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00074}00074 } \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00075}\mbox{\hyperlink{simple_8cpp_a6aa20242e66495075c94178062a11a0c}{00075}} \mbox{\hyperlink{simple_8cpp_a6e41b794c3fdf91f9046ef538245e798}{TEST\_CASE}}(\textcolor{stringliteral}{"{}safe\_auto"{}}) \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00076}00076 \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00077}00077 \mbox{\hyperlink{tdecl_8h_a607cffc585fe3bfcb06b63be2948de4a}{KBLIB\_UNUSED}} \textcolor{keyword}{decltype}(\textcolor{keyword}{auto}) dangling = \mbox{\hyperlink{namespacekblib_1_1nums_a24555c4b07301e176bf192adf4e80499}{kblib::min}}(1, 2);} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00078}00078 \textcolor{keyword}{static\_assert}(std::is\_same<\textcolor{keyword}{decltype}(dangling), \textcolor{keywordtype}{int}\&\&>::value, \textcolor{stringliteral}{"{}"{}});} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00079}00079 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00080}00080 \{} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00081}00081 \mbox{\hyperlink{tdecl_8h_a607cffc585fe3bfcb06b63be2948de4a}{KBLIB\_UNUSED}} \textcolor{keyword}{decltype}(\textcolor{keyword}{auto}) safe = \mbox{\hyperlink{namespacekblib_a535ff4e383fdfe8e07c637d574b68008}{kblib::safe\_auto}}(\mbox{\hyperlink{namespacekblib_1_1nums_a24555c4b07301e176bf192adf4e80499}{kblib::min}}(1, 2));} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00082}00082 \textcolor{keyword}{static\_assert}(std::is\_same<\textcolor{keyword}{decltype}(safe), \textcolor{keywordtype}{int}>::value, \textcolor{stringliteral}{"{}"{}});} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00083}00083 \}} \DoxyCodeLine{\Hypertarget{simple_8cpp_source_l00084}00084 \}} \end{DoxyCode}