SigUtil  0.95
Utility modules for modern C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
high_order.hpp
Go to the documentation of this file.
1 /*
2 Copyright© 2014 Akihiro Nishimura
3 
4 This software is released under the MIT License.
5 http://opensource.org/licenses/mit-license.php
6 */
7 
8 #ifndef SIG_UTIL_HIGH_ORDER_HPP
9 #define SIG_UTIL_HIGH_ORDER_HPP
10 
11 #include "../helper/helper_modules.hpp"
12 #include "../helper/container_helper.hpp"
13 
15 
16 namespace sig
17 {
19 
22 template <class F, class C1, class... Cs>
23 auto variadicZipWith(F&& func, C1&& list1, Cs&&... lists)
24 {
25  using CR1 = typename impl::remove_const_reference<C1>::type;
26  using R = typename impl::container_traits<CR1>::template rebind<decltype(impl::eval(
27  std::forward<F>(func),
28  std::declval<typename impl::forward_element<C1>::type>(),
29  std::declval<typename impl::forward_element<Cs>::type>()...
30  ))>;
31 
32  const uint length = min(list1.size(), lists.size()...);
33  R result = impl::container_traits<R>::make(length);
34 
35  iterative_make(length, result, std::forward<F>(func), impl::begin(std::forward<C1>(list1)), impl::begin(std::forward<Cs>(lists))...);
36 
37  return result;
38 }
39 
41 
61 template <class F, class C>
62 auto map(F&& func, C&& list)
63 {
64  return variadicZipWith(std::forward<F>(func), std::forward<C>(list));
65 }
66 
68 
87 template <class F, class C1, class C2>
88 auto zipWith(F&& func, C1&& list1, C2&& list2)
89 {
90  return variadicZipWith(std::forward<F>(func), std::forward<C1>(list1), std::forward<C2>(list2));
91 }
92 
93 }
94 #endif
typename std::remove_const< typename std::remove_reference< T >::type >::type type
auto variadicZipWith(F &&func, C1 &&list1, Cs &&...lists)
n引数高階関数
Definition: high_order.hpp:23
auto min(T v) -> T
auto zipWith(F &&func, C1 &&list1, C2 &&list2)
2引数高階関数
Definition: high_order.hpp:88
auto eval(F &&f, Args &&...args) -> decltype(f(std::forward< Args >(args)...))
Definition: eval.hpp:37
auto map(F &&func, C &&list)
1引数高階関数
Definition: high_order.hpp:62
Definition: array.hpp:15
auto begin(C &&c) -> std::move_iterator< typename RC::iterator >
void iterative_make(uint loop, C &dest, F &&func, Its...iterators)