diff options
author | Adrian Kummerlaender | 2015-01-17 20:34:11 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-01-17 20:34:11 +0100 |
commit | ec52d63d3caca690e822e1a07ba9c2f47710b4d5 (patch) | |
tree | 32ee250989596b786a55f5a6bc55f42bf6321dd8 /src/list | |
parent | 123ce87e66013bc11bf0d9ca01776a60cf47c89b (diff) | |
download | TypeAsValue-ec52d63d3caca690e822e1a07ba9c2f47710b4d5.tar TypeAsValue-ec52d63d3caca690e822e1a07ba9c2f47710b4d5.tar.gz TypeAsValue-ec52d63d3caca690e822e1a07ba9c2f47710b4d5.tar.bz2 TypeAsValue-ec52d63d3caca690e822e1a07ba9c2f47710b4d5.tar.lz TypeAsValue-ec52d63d3caca690e822e1a07ba9c2f47710b4d5.tar.xz TypeAsValue-ec52d63d3caca690e822e1a07ba9c2f47710b4d5.tar.zst TypeAsValue-ec52d63d3caca690e822e1a07ba9c2f47710b4d5.zip |
Implemented `Nth` function
* as its name implies this function returns the _nth_ value of a given _Cons_ structure
* added appropriate test case
Diffstat (limited to 'src/list')
-rw-r--r-- | src/list/operation/basic.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/list/operation/basic.h b/src/list/operation/basic.h index 1e05a50..cee4cbc 100644 --- a/src/list/operation/basic.h +++ b/src/list/operation/basic.h @@ -1,6 +1,8 @@ #ifndef TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_ #define TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_ +#include "operation/math.h" + namespace tav { template <typename Cons> @@ -16,6 +18,23 @@ struct Length<void> { typedef Size<0> type; }; +template < + typename Index, + typename Cons +> +struct Nth { + typedef If< + equal_value<Index, Size<0>>::value, + Head<Cons>, + typename Nth<Substract<Index, Size<1>>, Tail<Cons>>::type + > type; +}; + +template <typename Index> +struct Nth<Index, void> { + typedef void type; +}; + } #endif // TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_ |