1#ifndef _RHEO_MSG_UTIL_H
2#define _RHEO_MSG_UTIL_H
31# include "rheolef/communicator.h"
35template <
class T1,
class T2>
36struct select1st : std::unary_function<std::pair<T1,T2>, T1> {
37 T1
operator() (
const std::pair<T1,T2>& x)
const {
return x.first; }
39template <
class T1,
class T2>
40struct select2nd : std::unary_function<std::pair<T1,T2>, T2> {
41 T2
operator() (
const std::pair<T1,T2>& x)
const {
return x.second; }
50template <
class Size,
class Distance = std::ptrdiff_t>
51class index_iterator :
public std::iterator<std::input_iterator_tag, Size, Distance, const Size*, const Size&> {
60 const Size&
operator[](
const Size& i)
const {
return i; }
64 return !(x.
_i ==
_i); }
73:
public std::unary_function<Pair,typename Pair::first_type> {
74 typename std::unary_function<Pair,typename Pair::first_type>::result_type
81 :
public std::unary_function<Pair, typename Pair::second_type> {
82 typename std::unary_function<Pair,typename Pair::second_type>::result_type
88template<
class Pair1,
class Pair2>
91 return Pair2(x.first, x.second); }
94template <
class Iterator,
class Operator>
111template <
class Iterator,
class Operator>
118template <
class InputIterator,
class OutputIterator>
121OutputIterator result) {
122 while (input != last) {
123 (*result).first = (*input).first;
124 (*result++).second = (*input++).second;
134namespace rheolef {
namespace details {
149#define _RHEOLEF_generic_set_xxx_op(NAME,OP) \
151 template <class T1, class T2> \
152 typename std::enable_if< \
153 std::is_convertible<T1,T2>::value \
155 operator() (T2& x, const T1& y) const { x OP y; return x; } \
157 template <class T, class Reference> \
158 typename std::enable_if< \
159 !std::is_convertible<T,Reference>::value && \
160 is_class_reference<Reference>::value && \
161 std::is_member_function_pointer< \
162 decltype(static_cast<Reference& (Reference::*)(T)> \
163 (&Reference::operator OP)) \
166 operator() (Reference x, const T& y) const { x OP y; return x; } \
168 template <class T, class Reference> \
169 typename std::enable_if< \
170 !std::is_convertible<T,Reference>::value && \
171 std::is_class<Reference>::value && \
172 std::is_member_function_pointer< \
173 decltype(static_cast<Reference& (Reference::*)(const T&)> \
174 (&Reference::operator OP)) \
177 operator() (Reference x, const T& y) const { x OP y; return x; } \
179 template <class T, class IndexSet> \
180 typename std::enable_if< \
181 std::is_convertible<T,size_t>::value && \
182 std::is_class<IndexSet>::value && \
183 std::is_member_function_pointer< \
184 decltype(static_cast<IndexSet& (IndexSet::*)(size_t)> \
185 (&IndexSet::operator OP)) \
188 operator() (IndexSet& x, const T& y) const { x OP y; return x; } \
190 template <class T, class PairSet, class Size> \
191 typename std::enable_if< \
192 std::is_convertible<Size,size_t>::value && \
193 std::is_class<PairSet>::value \
195 operator() (PairSet& x, const std::pair<Size,T>& y) const { x OP y; return x; } \
201#undef _RHEOLEF_generic_set_xxx_op
203#define _RHEOLEF_generic_set_xxx_op(NAME,FUN) \
205 template <class T1, class T2> \
206 typename std::enable_if< \
207 std::is_convertible<T1,T2>::value \
209 operator() (T2& x, const T1& y) const { return x = FUN(x,T2(y)); } \
214#undef _RHEOLEF_generic_set_xxx_op
219struct default_set_op_traits {
220 using type = generic_set_op;
227#include <boost/serialization/utility.hpp>
228#ifdef _RHEOLEF_HAVE_MPI
229#include <boost/mpi/datatype.hpp>
232namespace rheolef {
namespace details {
238#ifdef _RHEOLEF_HAVE_MPI
bool operator==(apply_iterator< Iterator, Operator > b) const
apply_iterator & operator++()
bool operator!=(apply_iterator< Iterator, Operator > b) const
apply_iterator(Iterator i1, Operator op1)
value_type operator*() const
apply_iterator operator++(int)
Operator::result_type value_type
index_iterator & operator++()
bool operator!=(const index_iterator< Size, Distance > &x) const
const Size & operator*() const
bool operator==(const index_iterator< Size, Distance > &x) const
index_iterator(Size i0=0)
const Size & operator[](const Size &i) const
index_iterator operator++(int)
#define _RHEOLEF_generic_set_xxx_op(NAME, OP)
This file is part of Rheolef.
OutputIterator msg_pair_copy(InputIterator input, InputIterator last, OutputIterator result)
apply_iterator< Iterator, Operator > make_apply_iterator(Iterator i, Operator op)
bool operator()(const T &x) const
std::unary_function< Pair, typenamePair::first_type >::result_type operator()(const Pair &x) const
Pair2 operator()(const Pair1 &x) const
std::unary_function< Pair, typenamePair::second_type >::result_type operator()(const Pair &x) const
T1 operator()(const std::pair< T1, T2 > &x) const
T2 operator()(const std::pair< T1, T2 > &x) const