aboutsummaryrefslogtreecommitdiff
path: root/src/list/operation/append.h
blob: 77f72d9c254d0d389d609f90b0adb7e4e63708c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_APPEND_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_APPEND_H_

#include "higher/fold.h"

namespace tav {

namespace detail {

template <typename Replacement>
struct replace_void_cdr {
	template <typename CAR, typename CDR>
	using function = Cons<
		CAR,
		If<
			Eval<std::is_void<CDR>>,
			Replacement,
			CDR
		>
	>;
};

}

template <
	typename Primary,
	typename Secondary
>
using Append = If<
	Eval<std::is_void<Primary>>,
	Secondary,
	Fold<
		detail::replace_void_cdr<Secondary>::template function,
		void,
		Primary
	>
>;

}

#endif  // TYPEASVALUE_SRC_LIST_OPERATION_APPEND_H_