From 6d150b7d5a2c65a54203608e398ed38e48ed36e3 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 3 Feb 2015 16:26:43 +0100 Subject: 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 --- src/runtime/list/for_each.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/runtime/list/for_each.h (limited to 'src/runtime') 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 + +#include "list/list.h" + +namespace tav { +namespace runtime { + +template < + typename Current, + typename Function, + typename std::enable_if::value, std::size_t>::type = 0 +> +constexpr void for_each(const Function&) { } + +template < + typename Current, + typename Function, + typename std::enable_if::value, std::size_t>::type = 0 +> +constexpr void for_each(const Function& function) { + function(Head::value); + + for_each, Function>(function); +} + +} +} + +#endif // TYPEASVALUE_SRC_RUNTIME_LIST_FOR_EACH_H_ -- cgit v1.2.3