From 246cb31c1e20cdcc21a6a607de4b0095c71315d6 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Thu, 12 Feb 2015 14:32:33 +0100 Subject: Implemented `Cond` conditional * returns the `CDR` of the first true `CAR` in a given list of pairs * reimplemented `Apply` base class selection in terms of `Cond` --- src/conditional/cond.h | 29 +++++++++++++++++++++++++++++ src/function/apply.h | 26 ++++++++++++++++++-------- src/function/detail/apply.h | 8 ++++++++ src/type.h | 3 +++ 4 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/conditional/cond.h (limited to 'src') diff --git a/src/conditional/cond.h b/src/conditional/cond.h new file mode 100644 index 0000000..0c2b1a8 --- /dev/null +++ b/src/conditional/cond.h @@ -0,0 +1,29 @@ +#ifndef TYPEASVALUE_SRC_CONDITIONAL_COND_H_ +#define TYPEASVALUE_SRC_CONDITIONAL_COND_H_ + +#include + +#include "list/list.h" +#include "list/operation/higher/find.h" + +namespace tav { + +template +class Cond { + private: + template + using predicate = IsTrue::type::type>; + + public: + typedef typename Cdr< + typename Find< + predicate, + typename List::type + >::type + >::type type; + +}; + +} + +#endif // TYPEASVALUE_SRC_CONDITIONAL_COND_H_ diff --git a/src/function/apply.h b/src/function/apply.h index 21364a8..5a2105c 100644 --- a/src/function/apply.h +++ b/src/function/apply.h @@ -1,7 +1,8 @@ #ifndef TYPEASVALUE_SRC_FUNCTION_APPLY_H_ #define TYPEASVALUE_SRC_FUNCTION_APPLY_H_ -#include "conditional/if.h" +#include "operation/math.h" +#include "conditional/cond.h" #include "detail/apply.h" @@ -16,14 +17,23 @@ template < template class Function, typename... Arguments > -struct Apply : If< - (detail::count_placeholders::type::value > 2), - detail::apply_variadic, - typename If< - detail::count_placeholders::type::value == 2, - detail::apply_pair, +struct Apply : Cond< + Pair< + GreaterThan::type, Size<2>>, + detail::apply_variadic + >, + Pair< + IsEqualValue::type, Size<2>>, + detail::apply_pair + >, + Pair< + IsEqualValue::type, Size<1>>, detail::apply_single - >::type + >, + Pair< + Boolean, + detail::apply_none + > >::type { }; } diff --git a/src/function/detail/apply.h b/src/function/detail/apply.h index bf60be1..d9f058a 100644 --- a/src/function/detail/apply.h +++ b/src/function/detail/apply.h @@ -42,6 +42,14 @@ using count_placeholders = Count< typename List::type >; +template < + template class Function, + typename... Arguments +> +struct apply_none { + using type = Function; +}; + template < template class Function, typename... Arguments diff --git a/src/type.h b/src/type.h index c175c36..15ba2f8 100644 --- a/src/type.h +++ b/src/type.h @@ -32,6 +32,9 @@ template < > using IsEqualValue = Boolean; +template +using IsTrue = IsEqualValue>; + } #endif // TYPEASVALUE_SRC_TYPE_H_ -- cgit v1.2.3