diff options
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/runtime/list/for_each.h')
-rw-r--r-- | src/runtime/list/for_each.h | 32 |
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_ |