13 #ifndef THRILL_COMMON_FUNCTIONAL_HEADER 14 #define THRILL_COMMON_FUNCTIONAL_HEADER 21 #include <type_traits> 30 template <
typename Type>
32 ->decltype(std::forward<Type>(v)) {
33 return std::forward<Type>(v);
39 constexpr
static inline const T&
min(
const T& a,
const T& b) {
45 constexpr
static inline const T&
max(
const T& a,
const T& b) {
54 class maximum :
public std::binary_function<T, T, T>
58 return std::max<T>(
x, y);
65 class minimum :
public std::binary_function<T, T, T>
69 return std::min<T>(
x, y);
77 template <
typename Type,
typename Functor>
78 inline auto MapVector(
const std::vector<Type>& input,
const Functor& f)
79 ->std::vector<
typename std::result_of<Functor(Type)>::type> {
80 std::vector<typename std::result_of<Functor(Type)>::type> output;
81 output.reserve(input.size());
82 for (
typename std::vector<Type>::const_iterator it = input.begin();
83 it != input.end(); ++it) {
84 output.emplace_back(f(*it));
92 template <
typename ArrayType,
93 typename Operation = std::plus<typename ArrayType::value_type> >
97 template <
typename Type,
size_t N,
typename Operation>
99 :
public std::binary_function<
100 std::array<Type, N>, std::array<Type, N>, std::array<Type, N> >
107 for (
size_t i = 0; i <
N; ++i) out[i] = op_(a[i], b[i]);
116 template <
typename Type,
typename Operation>
118 :
public std::binary_function<
119 std::vector<Type>, std::vector<Type>, std::vector<Type> >
125 assert(a.size() == b.size());
127 out.reserve(
std::min(a.size(), b.size()));
128 for (
size_t i = 0; i <
min(a.size(), b.size()); ++i)
129 out.emplace_back(op_(a[i], b[i]));
138 template <
typename Type>
140 :
public std::binary_function<
141 std::vector<Type>, std::vector<Type>, std::vector<Type> >
147 out.reserve(a.size() + b.size());
148 out.insert(out.end(), a.begin(), a.end());
149 out.insert(out.end(), b.begin(), b.end());
157 #endif // !THRILL_COMMON_FUNCTIONAL_HEADER
constexpr auto operator()(Type &&v) const noexcept -> decltype(std::forward< Type >(v))
Identity functor, very useful for default parameters.
std::vector< Type > VectorType
ComponentSum(const Operation &op=Operation())
Compute the concatenation of two std::vector<T>s.
auto MapVector(const std::vector< Type > &input, const Functor &f) -> std::vector< typename std::result_of< Functor(Type)>::type >
std::vector< Type > VectorType
std::array< Type, N > ArrayType
template for computing the component-wise sum of std::array or std::vector.
std::vector< T, Allocator< T > > vector
vector with Manager tracking
static uint_pair min()
return an uint_pair instance containing the smallest value possible
ComponentSum(const Operation &op=Operation())
static constexpr const T & min(const T &a, const T &b)
template for constexpr min, because std::min is not good enough.
static constexpr const T & max(const T &a, const T &b)
template for constexpr max, because std::max is not good enough.