summaryrefslogtreecommitdiff
path: root/modules/core
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core')
-rw-r--r--modules/core/c++/reduce_templates.hpp11
-rw-r--r--modules/core/tests/templates.cpp20
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");
+}
+}