diff options
author | Claudius 'keldu' Holeksa <mail@keldu.de> | 2024-10-09 17:43:08 +0200 |
---|---|---|
committer | Claudius 'keldu' Holeksa <mail@keldu.de> | 2024-10-09 17:43:08 +0200 |
commit | 535498274de9aec26b7baad3df6a9720e9370ede (patch) | |
tree | 6576469d9728b9e96e6b4945ed47b3b7dce9f2b9 /modules/core | |
parent | e18bf6a68e81d870fb507b28f03172a60e3504d9 (diff) |
Dangling changes for language things
Diffstat (limited to 'modules/core')
-rw-r--r-- | modules/core/c++/reduce_templates.hpp | 11 | ||||
-rw-r--r-- | modules/core/tests/templates.cpp | 20 |
2 files changed, 28 insertions, 3 deletions
diff --git a/modules/core/c++/reduce_templates.hpp b/modules/core/c++/reduce_templates.hpp index ef5fa4c..fb643df 100644 --- a/modules/core/c++/reduce_templates.hpp +++ b/modules/core/c++/reduce_templates.hpp @@ -13,23 +13,28 @@ struct tmpl_group_reduce_match { template<typename T0, typename TL0, typename... TL> struct tmpl_group_reduce_match<T0, tmpl_group<TL0,TL...>> { + /** + * Check if type already exists in list + */ static constexpr bool has_type = std::is_same_v<T0,TL0> or tmpl_group_reduce_match<T0, tmpl_group<TL...>>::has_type; using type = typename std::conditional<has_type, tmpl_group<TL0,TL...>, tmpl_group<T0, TL0, TL...>>::type; }; +/** + * Reducing in outer loop + */ template<typename T> struct tmpl_group_reduce { using reduced_type = T; }; -/** - * Reducing in outer loop - */ template<typename... TL, typename T0> struct tmpl_group_reduce<tmpl_group<T0,TL...>> { + // Compile Time outer iteration using reduced_inner_list = typename tmpl_group_reduce<tmpl_group<TL...>>::reduced_type; + // Actual reduction. Basically an inner loop call using reduced_type = typename tmpl_group_reduce_match<T0,reduced_inner_list>::type; }; } diff --git a/modules/core/tests/templates.cpp b/modules/core/tests/templates.cpp new file mode 100644 index 0000000..2a069a6 --- /dev/null +++ b/modules/core/tests/templates.cpp @@ -0,0 +1,20 @@ +#include "../c++/reduce_templates.hpp" + +#include "../c++/test/suite.hpp" + +namespace { +struct Foo{}; + +struct Bar{}; +struct Baz{}; + +SAW_TEST("Templates/Reduce tmpl_group<T...>"){ + using namespace saw; + + using DuplGrp = tmpl_group<Bar,Baz,Baz,Bar,Foo,Bar,Baz,Bar,Bar>; + + using UniqGrp = tmpl_group<Foo,Baz,Bar>; + + SAW_EXPECT((std::is_same_v<DuplGrp,UniqGrp>), "Expected Uniquess Reduction"); +} +} |