aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-03 16:26:43 +0100
committerAdrian Kummerlaender2015-02-03 16:26:43 +0100
commit6d150b7d5a2c65a54203608e398ed38e48ed36e3 (patch)
tree3412a5fd0d471ccc5c88fec17bd77f527932206a /src
parentd86aac04e5225e705af0dd7749fdc1c0454088a8 (diff)
downloadTypeAsValue-6d150b7d5a2c65a54203608e398ed38e48ed36e3.tar
TypeAsValue-6d150b7d5a2c65a54203608e398ed38e48ed36e3.tar.gz
TypeAsValue-6d150b7d5a2c65a54203608e398ed38e48ed36e3.tar.bz2
TypeAsValue-6d150b7d5a2c65a54203608e398ed38e48ed36e3.tar.lz
TypeAsValue-6d150b7d5a2c65a54203608e398ed38e48ed36e3.tar.xz
TypeAsValue-6d150b7d5a2c65a54203608e398ed38e48ed36e3.tar.zst
TypeAsValue-6d150b7d5a2c65a54203608e398ed38e48ed36e3.zip
Added special `for_each` function for iterating lists at runtime
* i.e. we probably will want to access our compile time computed values at runtime sooner or later * runtime iteration using e.g. a normal _for-loop_ is not possible as we obviously can't dynamically insert new types into our templates
Diffstat (limited to 'src')
-rw-r--r--src/runtime/list/for_each.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/runtime/list/for_each.h b/src/runtime/list/for_each.h
new file mode 100644
index 0000000..74f038f
--- /dev/null
+++ b/src/runtime/list/for_each.h
@@ -0,0 +1,32 @@
+#ifndef TYPEASVALUE_SRC_RUNTIME_LIST_FOR_EACH_H_
+#define TYPEASVALUE_SRC_RUNTIME_LIST_FOR_EACH_H_
+
+#include <type_traits>
+
+#include "list/list.h"
+
+namespace tav {
+namespace runtime {
+
+template <
+ typename Current,
+ typename Function,
+ typename std::enable_if<std::is_void<Current>::value, std::size_t>::type = 0
+>
+constexpr void for_each(const Function&) { }
+
+template <
+ typename Current,
+ typename Function,
+ typename std::enable_if<!std::is_void<Current>::value, std::size_t>::type = 0
+>
+constexpr void for_each(const Function& function) {
+ function(Head<Current>::value);
+
+ for_each<Tail<Current>, Function>(function);
+}
+
+}
+}
+
+#endif // TYPEASVALUE_SRC_RUNTIME_LIST_FOR_EACH_H_