9 #ifndef MLIR_SUPPORT_FUNCTIONAL_H_ 10 #define MLIR_SUPPORT_FUNCTIONAL_H_ 13 #include "llvm/ADT/STLExtras.h" 14 #include "llvm/ADT/SmallVector.h" 15 #include "llvm/Support/Casting.h" 24 namespace functional {
27 template <
typename Fn,
typename IterType>
30 using R =
typename std::result_of<Fn(decltype(*begin))>::type;
34 for (
auto i = begin; i != end; ++i) {
35 res.push_back(fun(*i));
41 template <
typename Fn,
typename ContainerType>
42 auto map(Fn fun, ContainerType input)
43 -> decltype(
map(fun, std::begin(input), std::end(input))) {
44 return map(fun, std::begin(input), std::end(input));
50 template <
typename Fn,
typename ContainerType1,
typename ContainerType2>
51 auto zipMap(Fn fun, ContainerType1 input1, ContainerType2 input2)
52 ->
SmallVector<
typename std::result_of<Fn(decltype(*input1.begin()),
53 decltype(*input2.begin()))>::type,
55 using R =
typename std::result_of<Fn(decltype(*input1.begin()),
56 decltype(*input2.begin()))>::type;
58 auto zipIter = llvm::zip(input1, input2);
59 for (
auto it : zipIter) {
60 res.push_back(fun(std::get<0>(it), std::get<1>(it)));
66 template <
typename Fn,
typename IterType>
70 for (
auto i = begin; i != end; ++i) {
76 template <
typename Fn,
typename ContainerType>
77 void apply(Fn fun, ContainerType input) {
78 return apply(fun, std::begin(input), std::end(input));
84 template <
typename Fn,
typename ContainerType1,
typename ContainerType2>
85 void zipApply(Fn fun, ContainerType1 input1, ContainerType2 input2) {
86 auto zipIter = llvm::zip(input1, input2);
87 for (
auto it : zipIter) {
88 fun(std::get<0>(it), std::get<1>(it));
95 template <
typename T,
typename ToType = T>
97 return [](T *val) {
return dyn_cast<ToType>(val); };
103 : destruct(destruct) {}
107 std::function<void(void)> destruct;
113 #endif // MLIR_SUPPORT_FUNCTIONAL_H_ Definition: InferTypeOpInterface.cpp:20
void zipApply(Fn fun, ContainerType1 input1, ContainerType2 input2)
Definition: Functional.h:85
IterType
Definition: Builders.h:27
~ScopeGuard()
Definition: Functional.h:104
ScopeGuard(std::function< void(void)> destruct)
Definition: Functional.h:102
auto map(Fn fun, IterType begin, IterType end) -> SmallVector< typename std::result_of< Fn(decltype(*begin))>::type, 8 >
Map with iterators.
Definition: Functional.h:28
auto zipMap(Fn fun, ContainerType1 input1, ContainerType2 input2) -> SmallVector< typename std::result_of< Fn(decltype(*input1.begin()), decltype(*input2.begin()))>::type, 8 >
Definition: Functional.h:51
void apply(Fn fun, IterType begin, IterType end)
Apply with iterators.
Definition: Functional.h:67
Simple ScopeGuard.
Definition: Functional.h:101
std::function< ToType *(T *)> makePtrDynCaster()
Definition: Functional.h:96