-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchain.h
54 lines (48 loc) · 1.25 KB
/
chain.h
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
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef CHAIN_H
#define CHAIN_H
#include <type_traits>
#include "id_func.h"
#include "array_id_func.h"
// chain(IDIDFunc, IDFunc)
template<class L, class R>
typename std::enable_if<
is_id_id_func<L>::value
&& is_id_func<R>::value
&& !is_id_id_func<R>::value,
ArrayIDFunc<typename id_func_image_type<R>::type>
>::type
chain(const L&l, const R&r){
ArrayIDFunc<typename id_func_image_type<R>::type>result(l.preimage_count());
for(int i=0; i<l.preimage_count(); ++i)
result[i] = r(l(i));
return result; // NVRO
}
// chain(IDIDFunc, IDIDFunc)
template<class L, class R>
typename std::enable_if<
is_mutable_id_id_func<L>::value
&& is_id_id_func<R>::value,
L
>::type
chain(L l, const R&r){
assert(l.image_count() == r.preimage_count());
for(int i=0; i<l.preimage_count(); ++i)
l.set(i, r(l(i)));
l.set_image_count(r.image_count());
return std::move(l);
}
template<class L, class R>
typename std::enable_if<
is_id_id_func<L>::value
&& !is_mutable_id_id_func<L>::value
&& is_id_id_func<R>::value,
ArrayIDIDFunc
>::type
chain(const L&l, const R&r){
assert(l.image_count() == r.preimage_count());
ArrayIDIDFunc result(l.preimage_count(), r.image_count());
for(int i=0; i<l.preimage_count(); ++i)
result[i] = r(l(i));
return result; // NVRO
}
#endif