\hypertarget{logic_8cpp_source}{}\doxysection{logic.\+cpp} \label{logic_8cpp_source}\index{tests/logic.cpp@{tests/logic.cpp}} \mbox{\hyperlink{logic_8cpp}{Go to the documentation of this file.}} \begin{DoxyCode}{0} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00001}00001 \textcolor{preprocessor}{\#include "{}catch.hpp"{}}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00002}00002 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00003}00003 \textcolor{preprocessor}{\#include "{}\mbox{\hyperlink{logic_8h}{kblib/logic.h}}"{}}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00004}00004 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00005}00005 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00006}00006 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00007}00007 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00008}00008 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00009}00009 \textcolor{keyword}{template} <\textcolor{keywordtype}{int} I1, \textcolor{keywordtype}{int} I2>} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00010}\mbox{\hyperlink{logic_8cpp_a3a0a1ef4b637f7b37612b8e25385b7dc}{00010}} \textcolor{keyword}{auto} \mbox{\hyperlink{logic_8cpp_a3a0a1ef4b637f7b37612b8e25385b7dc}{multi\_template}}() -\/> \textcolor{keywordtype}{int} \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00011}00011 \textcolor{keywordflow}{return} I1 * I2;} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00012}00012 \}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00013}00013 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00014}00014 \textcolor{keyword}{template} <\textcolor{keywordtype}{int}... Is>} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00015}\mbox{\hyperlink{structtag}{00015}} \textcolor{keyword}{struct }\mbox{\hyperlink{structtag}{tag}} \{\};} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00016}00016 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00017}00017 \textcolor{keyword}{template} } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00019}\mbox{\hyperlink{logic_8cpp_a805bb6d31c9ec8c55eafeef1fcdb7883}{00019}} \textcolor{keyword}{constexpr} \textcolor{keyword}{auto} \mbox{\hyperlink{logic_8cpp_a805bb6d31c9ec8c55eafeef1fcdb7883}{get\_col}}(\textcolor{keyword}{const} std::array, rows>\& in,} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00020}00020 std::index\_sequence) -\/> std::array \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00021}00021 \textcolor{keyword}{static\_assert}(rows == \textcolor{keyword}{sizeof}...(row), \textcolor{stringliteral}{"{}"{}});} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00022}00022 \textcolor{keywordflow}{return} \{std::get(std::get(in))...\};} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00023}00023 \}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00024}00024 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00025}00025 \textcolor{keyword}{template} <\textcolor{keyword}{typename} T, std::size\_t rows, std::size\_t cols, std::size\_t... row,} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00026}00026 std::size\_t... col>} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00027}\mbox{\hyperlink{logic_8cpp_ab28114b9c9bb4301d0547e9aa909dfec}{00027}} \textcolor{keyword}{constexpr} \textcolor{keyword}{auto} \mbox{\hyperlink{logic_8cpp_ab28114b9c9bb4301d0547e9aa909dfec}{transpose\_arr\_impl}}(} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00028}00028 \textcolor{keyword}{const} std::array, rows>\& in,} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00029}00029 std::index\_sequence) -\/> std::array, cols> \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00030}00030 \textcolor{keywordflow}{return} \{get\_col(in, std::make\_index\_sequence\{\})...\};} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00031}00031 \}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00032}00032 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00033}00033 \textcolor{keyword}{template} <\textcolor{keyword}{typename} T, std::\textcolor{keywordtype}{size\_t} rows, std::\textcolor{keywordtype}{size\_t} cols>} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00034}\mbox{\hyperlink{logic_8cpp_afa0bc1c7d143daefbe4fd916f27e5942}{00034}} \textcolor{keyword}{constexpr} \textcolor{keyword}{auto} \mbox{\hyperlink{logic_8cpp_afa0bc1c7d143daefbe4fd916f27e5942}{transpose\_arr}}(std::array, rows> in)} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00035}00035 -\/> std::array, cols> \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00036}00036 \textcolor{keywordflow}{return} \mbox{\hyperlink{logic_8cpp_ab28114b9c9bb4301d0547e9aa909dfec}{transpose\_arr\_impl}}(in, std::make\_index\_sequence\{\});} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00037}00037 \textcolor{comment}{// C++17 version}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00038}00038 \textcolor{comment}{/*}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00039}00039 \textcolor{comment}{ std::array, rows> ret\{\};}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00040}00040 \textcolor{comment}{ for (std::size\_t C = 0; C != cols; ++C) \{}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00041}00041 \textcolor{comment}{ for (std::size\_t R = 0; R != rows; ++R) \{}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00042}00042 \textcolor{comment}{ ret[R][C] = in[C][R];}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00043}00043 \textcolor{comment}{ \}}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00044}00044 \textcolor{comment}{ \}}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00045}00045 \textcolor{comment}{ return ret;*/}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00046}00046 \}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00047}00047 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00048}\mbox{\hyperlink{logic_8cpp_ad16dc06d9e2eb754b0b8723f29893e24}{00048}} \mbox{\hyperlink{logic_8cpp_ad16dc06d9e2eb754b0b8723f29893e24}{TEST\_CASE}}(\textcolor{stringliteral}{"{}transpose"{}}) \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00049}00049 std::array, 3> input\{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00050}00050 \{\{0, 1, 2, 3\}, \{4, 5, 6, 7\}, \{8, 9, 10, 11\}\}\};} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00051}00051 std::array, 4> transposed\{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00052}00052 \{\{0, 4, 8\}, \{1, 5, 9\}, \{2, 6, 10\}, \{3, 7, 11\}\}\};} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00053}00053 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00054}00054 REQUIRE(\mbox{\hyperlink{logic_8cpp_afa0bc1c7d143daefbe4fd916f27e5942}{transpose\_arr}}(input) == transposed);} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00055}00055 \}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00056}00056 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00057}00057 \textcolor{keyword}{template} <\textcolor{keywordtype}{int} I2, \textcolor{keywordtype}{int}... Is1>} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00058}\mbox{\hyperlink{logic_8cpp_aaa064b9b6ece4f367f4d6125f79de658}{00058}} \textcolor{keyword}{constexpr} \textcolor{keyword}{auto} \mbox{\hyperlink{logic_8cpp_aaa064b9b6ece4f367f4d6125f79de658}{gen\_row}}(\mbox{\hyperlink{structtag}{tag}}) -\/> std::array \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00059}00059 \textcolor{keywordflow}{return} \{\&multi\_template...\};} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00060}00060 \}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00061}00061 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00062}00062 \textcolor{keyword}{template} <\textcolor{keyword}{typename} Tag1, \textcolor{keywordtype}{int}... Is2>} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00063}\mbox{\hyperlink{logic_8cpp_a8d6a1b8417cd0b02611f105d420cc55e}{00063}} \textcolor{keyword}{constexpr} \textcolor{keyword}{auto} \mbox{\hyperlink{logic_8cpp_a8d6a1b8417cd0b02611f105d420cc55e}{gen\_dispatch\_table}}() -\/> std::array, 8> \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00064}00064 std::array, 8> tmp = \{gen\_row(Tag1\{\})...\};} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00065}00065 \textcolor{keywordflow}{return} \mbox{\hyperlink{logic_8cpp_afa0bc1c7d143daefbe4fd916f27e5942}{transpose\_arr}}(tmp);} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00066}00066 \}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00067}00067 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00068}\mbox{\hyperlink{logic_8cpp_a0cf41a8e5759d8937331aa9fe0925b02}{00068}} \textcolor{keyword}{constexpr} std::array, 8> \mbox{\hyperlink{logic_8cpp_a0cf41a8e5759d8937331aa9fe0925b02}{dispatch\_table}}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00069}00069 = \mbox{\hyperlink{logic_8cpp_a8d6a1b8417cd0b02611f105d420cc55e}{gen\_dispatch\_table}}<\mbox{\hyperlink{structtag}{tag<6, 13, 14, 19, 22, 22, 24, 27>}}, 1, 3, 5, 6, 18, 21,} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00070}00070 25, 31>();} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00071}00071 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00072}\mbox{\hyperlink{logic_8cpp_a903c75c159dec31c7388c4a715087c00}{00072}} \textcolor{keyword}{auto} \mbox{\hyperlink{logic_8cpp_a903c75c159dec31c7388c4a715087c00}{multi\_dispatcher}}(\textcolor{keywordtype}{int} i1, \textcolor{keywordtype}{int} i2) -\/> \textcolor{keywordtype}{int} \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00073}00073 \textcolor{keyword}{constexpr} std::array i1\_lookup = \{6, 13, 14, 19, 22, 22, 24, 27\};} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00074}00074 \textcolor{keyword}{constexpr} std::array i2\_lookup = \{1, 3, 5, 6, 18, 21, 25, 31\};} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00075}00075 \textcolor{keyword}{auto} \mbox{\hyperlink{namespacekblib_abc7f2ec97efdee8640fe38e73fe1fdad}{find}} = [](\textcolor{keywordtype}{int} v, \textcolor{keyword}{const} std::array\& arr) \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00076}00076 \textcolor{keywordflow}{for} (std::size\_t i = 0; i != 8; ++i) \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00077}00077 \textcolor{keywordflow}{if} (arr[i] == v) \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00078}00078 \textcolor{keywordflow}{return} i;} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00079}00079 \}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00080}00080 \}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00081}00081 \textcolor{keywordflow}{throw} std::out\_of\_range(\mbox{\hyperlink{namespacekblib_a9d7e23caee89855a71fb84c7f245f977}{std::to\_string}}(v));} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00082}00082 \};} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00083}00083 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00084}00084 \textcolor{keywordflow}{return} \mbox{\hyperlink{logic_8cpp_a0cf41a8e5759d8937331aa9fe0925b02}{dispatch\_table}}[\mbox{\hyperlink{namespacekblib_abc7f2ec97efdee8640fe38e73fe1fdad}{find}}(i1, i1\_lookup)][\mbox{\hyperlink{namespacekblib_abc7f2ec97efdee8640fe38e73fe1fdad}{find}}(i2, i2\_lookup)]();} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00085}00085 \}} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00086}00086 } \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00087}\mbox{\hyperlink{logic_8cpp_a88f35363cda236fcadf3fd92bd50c06a}{00087}} \mbox{\hyperlink{logic_8cpp_ad16dc06d9e2eb754b0b8723f29893e24}{TEST\_CASE}}(\textcolor{stringliteral}{"{}run-\/time template dispatching"{}}) \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00088}00088 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} x : \{6, 13, 14, 19, 22, 22, 24, 27\}) \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00089}00089 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} y : \{1, 3, 5, 6, 18, 21, 25, 31\}) \{} \DoxyCodeLine{\Hypertarget{logic_8cpp_source_l00090}00090 \textcolor{comment}{// std::cout<