diff --git a/module-1/homework/TypeList/typelist/append.h b/module-1/homework/TypeList/typelist/append.h index ac395d4b..e5d4665d 100644 --- a/module-1/homework/TypeList/typelist/append.h +++ b/module-1/homework/TypeList/typelist/append.h @@ -3,4 +3,19 @@ #include "typelist.h" template -struct Append; \ No newline at end of file +struct Append { + typedef TypeList< + typename TList::H, + typename Append::NewTypeList + > NewTypeList; +}; + +template +struct Append { + typedef TypeList NewTypeList; +}; + +template<> +struct Append { + typedef NullType NewTypeList; +}; \ No newline at end of file diff --git a/module-1/homework/TypeList/typelist/erase.h b/module-1/homework/TypeList/typelist/erase.h index 7f33b81c..5bbe81b2 100644 --- a/module-1/homework/TypeList/typelist/erase.h +++ b/module-1/homework/TypeList/typelist/erase.h @@ -3,4 +3,19 @@ #include "typelist.h" template -struct Erase; \ No newline at end of file +struct Erase{ + typedef TypeList< + typename TList::H, + typename Erase::NewTypeList + > NewTypeList; +}; + +template +struct Erase{ + typedef typename TList::T NewTypeList; +}; + +template +struct Erase{ + typedef NullType NewTypeList; +}; \ No newline at end of file diff --git a/module-1/homework/TypeList/typelist/eraseall.h b/module-1/homework/TypeList/typelist/eraseall.h index e395227c..2dcf6206 100644 --- a/module-1/homework/TypeList/typelist/eraseall.h +++ b/module-1/homework/TypeList/typelist/eraseall.h @@ -3,4 +3,22 @@ #include "typelist.h" template -struct EraseAll; \ No newline at end of file +struct EraseAll{ + typedef TypeList< + typename TList::H, + typename EraseAll::NewTypeList + > NewTypeList; +}; + +template +struct EraseAll { + typedef typename EraseAll< + typename TList::T, + typename TList::H + >::NewTypeList NewTypeList; +}; + +template +struct EraseAll { + typedef NullType NewTypeList; +}; \ No newline at end of file diff --git a/module-1/homework/TypeList/typelist/indexof.h b/module-1/homework/TypeList/typelist/indexof.h index e1c34184..c5dc0154 100644 --- a/module-1/homework/TypeList/typelist/indexof.h +++ b/module-1/homework/TypeList/typelist/indexof.h @@ -3,4 +3,19 @@ #include "typelist.h" template -struct IndexOf; \ No newline at end of file +struct IndexOf{ +private: + enum { temp = IndexOf::pos }; +public: + enum { pos = temp == -1 ? -1 : temp + 1 }; +}; + +template +struct IndexOf{ + enum { pos = 0 }; +}; + +template +struct IndexOf { + enum { pos = -1 }; +}; \ No newline at end of file diff --git a/module-1/homework/TypeList/typelist/length.h b/module-1/homework/TypeList/typelist/length.h index 2f45c74b..4659fe36 100644 --- a/module-1/homework/TypeList/typelist/length.h +++ b/module-1/homework/TypeList/typelist/length.h @@ -2,5 +2,12 @@ #include "typelist.h" -template -struct Length; \ No newline at end of file +template +struct Length { + enum { length = 1 + Length::length }; +}; + +template<> +struct Length { + enum { length = 0 }; +}; \ No newline at end of file diff --git a/module-1/homework/TypeList/typelist/noduplicates.h b/module-1/homework/TypeList/typelist/noduplicates.h index c0c696b2..1be86132 100644 --- a/module-1/homework/TypeList/typelist/noduplicates.h +++ b/module-1/homework/TypeList/typelist/noduplicates.h @@ -4,4 +4,19 @@ #include "typelist.h" template -struct NoDuplicates; \ No newline at end of file +struct NoDuplicates { + typedef TypeList< + typename TList::H, + typename NoDuplicates< + typename EraseAll< + typename TList::T, + typename TList::H + >::NewTypeList + >::NewTypeList + > NewTypeList; +}; + +template<> +struct NoDuplicates { + typedef NullType NewTypeList; +}; \ No newline at end of file diff --git a/module-1/homework/TypeList/typelist/replace.h b/module-1/homework/TypeList/typelist/replace.h index 392595b7..4f8f6e31 100644 --- a/module-1/homework/TypeList/typelist/replace.h +++ b/module-1/homework/TypeList/typelist/replace.h @@ -2,5 +2,26 @@ #include "typelist.h" -template -struct Replace; \ No newline at end of file +template +struct Replace { + typedef TypeList< + typename TList::H, + typename Replace::NewTypeList + > NewTypeList; +}; + +template +struct Replace { + typedef TypeList< + NewType, + typename Replace< + typename TList::T, + typename TList::H, NewType + >::NewTypeList + > NewTypeList; +}; + +template +struct Replace { + typedef NullType NewTypeList; +}; \ No newline at end of file diff --git a/module-1/homework/TypeList/typelist/typeat.h b/module-1/homework/TypeList/typelist/typeat.h index 805f391c..343bdc09 100644 --- a/module-1/homework/TypeList/typelist/typeat.h +++ b/module-1/homework/TypeList/typelist/typeat.h @@ -3,4 +3,11 @@ #include "typelist.h" template -struct TypeAt; \ No newline at end of file +struct TypeAt { + typedef typename TypeAt::TargetType TargetType; +}; + +template +struct TypeAt { + typedef typename TList::H TargetType; +}; \ No newline at end of file diff --git a/module-1/homework/TypeList/typelist/typelist.h b/module-1/homework/TypeList/typelist/typelist.h index aeb91be8..de661308 100644 --- a/module-1/homework/TypeList/typelist/typelist.h +++ b/module-1/homework/TypeList/typelist/typelist.h @@ -1,6 +1,9 @@ #pragma once -template -struct TypeList; +template +struct TypeList { + typedef Head H; + typedef Tail T; +}; struct NullType {}; \ No newline at end of file