Polymath/include/internal/StdAdapters.h

347 lines
11 KiB
C++

#ifndef STDADAPTERS_H
#define STDADAPTERS_H
#include <functional>
#include <algorithm>
namespace Poly
{
template <typename T, int M>
class Matrix;
}
namespace std
{
#ifndef _CONCAT
#define _CONCAT(A, B) A ## B
#endif
#define _UNARY_STD_ADAPTER(func_name) \
template <typename T, int M> \
Poly::Matrix<T,M> func_name(const Poly::Matrix<T,M>& mat) \
{ \
Poly::Matrix<T,M> res(mat.rows(), mat.columns()); \
std::transform(mat.begin(),mat.end(),res.begin(),std::pointer_to_unary_function<T,T>(std::func_name)); \
return res; \
}
#define _UNARY_STD_ADAPTER_INPLACE(func_name) \
template <typename T, int M> \
void _CONCAT(func_name, _inplace)(Poly::Matrix<T,M>& mat) \
{ \
std::transform(mat.begin(),mat.end(),mat.begin(),std::pointer_to_unary_function<T,T>(std::func_name)); \
}
#define _BINARY_STD_ADAPTER(func_name) \
template <typename T, typename U, int M> \
Poly::Matrix<T,M> func_name(const Poly::Matrix<T,M>& mat1st, const Poly::Matrix<U,M>& mat2nd) \
{ \
Poly::Matrix<T,M> res(mat1st.rows(), mat2nd.columns()); \
std::transform(mat1st.begin(),mat1st.end(),mat2nd.begin(),res.begin(),(T(*)(T,U)) std::func_name); \
return res; \
}
#define _BINARY_STD_ADAPTER_BIND1ST(func_name) \
template <typename T, typename U, int M> \
Poly::Matrix<T,M> func_name(T val, const Poly::Matrix<U,M>& mat2nd) \
{ \
Poly::Matrix<T,M> res(mat2nd.rows(), mat2nd.columns()); \
std::transform(mat2nd.begin(),mat2nd.end(),res.begin(),[&val](const U& y) { return std::func_name(val,y); }); \
return res; \
}
#define _BINARY_STD_ADAPTER_BIND2ND(func_name) \
template <typename T, typename U, int M> \
Poly::Matrix<T,M> func_name(const Poly::Matrix<T,M>& mat1st, U val) \
{ \
Poly::Matrix<T,M> res(mat1st.rows(), mat1st.columns()); \
std::transform(mat1st.begin(),mat1st.end(),res.begin(),[&val](const T& x) { return std::func_name(x,val); }); \
return res; \
}
#define _BINARY_STD_ADAPTER_BIND1ST_INPLACE(func_name) \
template <typename T, typename U, int M> \
void _CONCAT(func_name, _inplace)(T val, Poly::Matrix<U,M>& mat2nd) \
{ \
std::transform(mat2nd.begin(),mat2nd.end(),mat2nd.begin(),[&val](const U& y) { return std::func_name(val,y); }); \
}
#define _BINARY_STD_ADAPTER_BIND2ND_INPLACE(func_name) \
template <typename T, typename U, int M> \
void _CONCAT(func_name, _inplace)(Poly::Matrix<T,M>& mat1st, U val) \
{ \
std::transform(mat1st.begin(),mat1st.end(),mat1st.begin(),[&val](const T& x) { return std::func_name(x,val); }); \
}
#define _BINARY_STD_ADAPTER_INPLACE_1ST(func_name) \
template <typename T, typename U, int M> \
void _CONCAT(func_name, _inplace1st)(Poly::Matrix<T,M>& mat1st_and_out, const Poly::Matrix<U,M>& mat2nd) \
{ \
std::transform(mat1st_and_out.begin(),mat1st_and_out.end(),mat2nd.begin(),mat1st_and_out.begin(),(T(*)(T,U)) std::func_name); \
}
#define _BINARY_STD_ADAPTER_INPLACE_2ND(func_name) \
template <typename T, typename U, int M> \
void _CONCAT(func_name, _inplace2nd)(const Poly::Matrix<T,M>& mat1st, Poly::Matrix<U,M>& mat2nd_and_out) \
{ \
std::transform(mat1st.begin(),mat1st.end(),mat2nd_and_out.begin(),mat2nd_and_out.begin(),(T(*)(T,U)) std::func_name); \
}
_UNARY_STD_ADAPTER(abs)
_UNARY_STD_ADAPTER(acos)
_UNARY_STD_ADAPTER(acosh)
_UNARY_STD_ADAPTER(asin)
_UNARY_STD_ADAPTER(asinh)
_UNARY_STD_ADAPTER(atan)
_UNARY_STD_ADAPTER(atanh)
_UNARY_STD_ADAPTER(cbrt)
_UNARY_STD_ADAPTER(ceil)
_UNARY_STD_ADAPTER(cos)
_UNARY_STD_ADAPTER(cosh)
_UNARY_STD_ADAPTER(erf)
_UNARY_STD_ADAPTER(erfc)
_UNARY_STD_ADAPTER(exp)
_UNARY_STD_ADAPTER(exp2)
_UNARY_STD_ADAPTER(expm1)
_UNARY_STD_ADAPTER(fabs)
_UNARY_STD_ADAPTER(floor)
_UNARY_STD_ADAPTER(ilogb)
_UNARY_STD_ADAPTER(isalnum)
_UNARY_STD_ADAPTER(isalpha)
_UNARY_STD_ADAPTER(isblank)
_UNARY_STD_ADAPTER(iscntrl)
_UNARY_STD_ADAPTER(isdigit)
_UNARY_STD_ADAPTER(isgraph)
_UNARY_STD_ADAPTER(islower)
_UNARY_STD_ADAPTER(isnan)
_UNARY_STD_ADAPTER(isprint)
_UNARY_STD_ADAPTER(ispunct)
_UNARY_STD_ADAPTER(isspace)
_UNARY_STD_ADAPTER(isupper)
_UNARY_STD_ADAPTER(iswalnum)
_UNARY_STD_ADAPTER(iswalpha)
_UNARY_STD_ADAPTER(iswblank)
_UNARY_STD_ADAPTER(iswcntrl)
_UNARY_STD_ADAPTER(iswdigit)
_UNARY_STD_ADAPTER(iswgraph)
_UNARY_STD_ADAPTER(iswlower)
_UNARY_STD_ADAPTER(iswprint)
_UNARY_STD_ADAPTER(iswpunct)
_UNARY_STD_ADAPTER(iswspace)
_UNARY_STD_ADAPTER(iswupper)
_UNARY_STD_ADAPTER(iswxdigit)
_UNARY_STD_ADAPTER(isxdigit)
_UNARY_STD_ADAPTER(labs)
_UNARY_STD_ADAPTER(lgamma)
_UNARY_STD_ADAPTER(log)
_UNARY_STD_ADAPTER(log2)
_UNARY_STD_ADAPTER(log10)
_UNARY_STD_ADAPTER(nearbyint)
_UNARY_STD_ADAPTER(round)
_UNARY_STD_ADAPTER(sin)
_UNARY_STD_ADAPTER(sinh)
_UNARY_STD_ADAPTER(srand)
_UNARY_STD_ADAPTER(sqrt)
_UNARY_STD_ADAPTER(tan)
_UNARY_STD_ADAPTER(tanh)
_UNARY_STD_ADAPTER(tgamma)
_UNARY_STD_ADAPTER(tolower)
_UNARY_STD_ADAPTER(toupper)
_UNARY_STD_ADAPTER(towctrans)
_UNARY_STD_ADAPTER(towlower)
_UNARY_STD_ADAPTER(towupper)
_UNARY_STD_ADAPTER(trunc)
_UNARY_STD_ADAPTER(to_string)
_UNARY_STD_ADAPTER(to_wstring)
_UNARY_STD_ADAPTER(rint)
_UNARY_STD_ADAPTER(isfinite)
_UNARY_STD_ADAPTER(isinf)
_UNARY_STD_ADAPTER(isnormal)
_UNARY_STD_ADAPTER(signbit)
_UNARY_STD_ADAPTER_INPLACE(abs)
_UNARY_STD_ADAPTER_INPLACE(acos)
_UNARY_STD_ADAPTER_INPLACE(acosh)
_UNARY_STD_ADAPTER_INPLACE(asin)
_UNARY_STD_ADAPTER_INPLACE(asinh)
_UNARY_STD_ADAPTER_INPLACE(atan)
_UNARY_STD_ADAPTER_INPLACE(atanh)
_UNARY_STD_ADAPTER_INPLACE(cbrt)
_UNARY_STD_ADAPTER_INPLACE(ceil)
_UNARY_STD_ADAPTER_INPLACE(cos)
_UNARY_STD_ADAPTER_INPLACE(cosh)
_UNARY_STD_ADAPTER_INPLACE(erf)
_UNARY_STD_ADAPTER_INPLACE(erfc)
_UNARY_STD_ADAPTER_INPLACE(exp)
_UNARY_STD_ADAPTER_INPLACE(exp2)
_UNARY_STD_ADAPTER_INPLACE(expm1)
_UNARY_STD_ADAPTER_INPLACE(fabs)
_UNARY_STD_ADAPTER_INPLACE(ilogb)
_UNARY_STD_ADAPTER_INPLACE(isalnum)
_UNARY_STD_ADAPTER_INPLACE(isalpha)
_UNARY_STD_ADAPTER_INPLACE(isblank)
_UNARY_STD_ADAPTER_INPLACE(iscntrl)
_UNARY_STD_ADAPTER_INPLACE(isdigit)
_UNARY_STD_ADAPTER_INPLACE(isgraph)
_UNARY_STD_ADAPTER_INPLACE(islower)
_UNARY_STD_ADAPTER_INPLACE(isnan)
_UNARY_STD_ADAPTER_INPLACE(isprint)
_UNARY_STD_ADAPTER_INPLACE(ispunct)
_UNARY_STD_ADAPTER_INPLACE(isspace)
_UNARY_STD_ADAPTER_INPLACE(isupper)
_UNARY_STD_ADAPTER_INPLACE(iswalnum)
_UNARY_STD_ADAPTER_INPLACE(iswalpha)
_UNARY_STD_ADAPTER_INPLACE(iswblank)
_UNARY_STD_ADAPTER_INPLACE(iswcntrl)
_UNARY_STD_ADAPTER_INPLACE(iswdigit)
_UNARY_STD_ADAPTER_INPLACE(iswgraph)
_UNARY_STD_ADAPTER_INPLACE(iswlower)
_UNARY_STD_ADAPTER_INPLACE(iswprint)
_UNARY_STD_ADAPTER_INPLACE(iswpunct)
_UNARY_STD_ADAPTER_INPLACE(iswspace)
_UNARY_STD_ADAPTER_INPLACE(iswupper)
_UNARY_STD_ADAPTER_INPLACE(iswxdigit)
_UNARY_STD_ADAPTER_INPLACE(isxdigit)
_UNARY_STD_ADAPTER_INPLACE(labs)
_UNARY_STD_ADAPTER_INPLACE(lgamma)
_UNARY_STD_ADAPTER_INPLACE(log)
_UNARY_STD_ADAPTER_INPLACE(log2)
_UNARY_STD_ADAPTER_INPLACE(log10)
_UNARY_STD_ADAPTER_INPLACE(nearbyint)
_UNARY_STD_ADAPTER_INPLACE(sin)
_UNARY_STD_ADAPTER_INPLACE(sinh)
_UNARY_STD_ADAPTER_INPLACE(srand)
_UNARY_STD_ADAPTER_INPLACE(sqrt)
_UNARY_STD_ADAPTER_INPLACE(tan)
_UNARY_STD_ADAPTER_INPLACE(tanh)
_UNARY_STD_ADAPTER_INPLACE(tgamma)
_UNARY_STD_ADAPTER_INPLACE(tolower)
_UNARY_STD_ADAPTER_INPLACE(toupper)
_UNARY_STD_ADAPTER_INPLACE(towctrans)
_UNARY_STD_ADAPTER_INPLACE(towlower)
_UNARY_STD_ADAPTER_INPLACE(towupper)
_UNARY_STD_ADAPTER_INPLACE(trunc)
_UNARY_STD_ADAPTER_INPLACE(to_string)
_UNARY_STD_ADAPTER_INPLACE(to_wstring)
_UNARY_STD_ADAPTER_INPLACE(rint)
_UNARY_STD_ADAPTER_INPLACE(isfinite)
_UNARY_STD_ADAPTER_INPLACE(isinf)
_UNARY_STD_ADAPTER_INPLACE(isnormal)
_UNARY_STD_ADAPTER_INPLACE(signbit)
_BINARY_STD_ADAPTER(atan2)
_BINARY_STD_ADAPTER(remainder)
_BINARY_STD_ADAPTER(remquo)
_BINARY_STD_ADAPTER(fmax)
_BINARY_STD_ADAPTER(fmin)
_BINARY_STD_ADAPTER(fmod)
_BINARY_STD_ADAPTER(fdim)
_BINARY_STD_ADAPTER(hypot)
_BINARY_STD_ADAPTER(isgreater)
_BINARY_STD_ADAPTER(isgreaterequal)
_BINARY_STD_ADAPTER(isless)
_BINARY_STD_ADAPTER(islessequal)
_BINARY_STD_ADAPTER(islessgreater)
_BINARY_STD_ADAPTER(isunordered)
_BINARY_STD_ADAPTER(pow)
_BINARY_STD_ADAPTER_BIND1ST(atan2)
_BINARY_STD_ADAPTER_BIND1ST(remainder)
_BINARY_STD_ADAPTER_BIND1ST(remquo)
_BINARY_STD_ADAPTER_BIND1ST(fmax)
_BINARY_STD_ADAPTER_BIND1ST(fmin)
_BINARY_STD_ADAPTER_BIND1ST(fmod)
_BINARY_STD_ADAPTER_BIND1ST(fdim)
_BINARY_STD_ADAPTER_BIND1ST(hypot)
_BINARY_STD_ADAPTER_BIND1ST(isgreater)
_BINARY_STD_ADAPTER_BIND1ST(isgreaterequal)
_BINARY_STD_ADAPTER_BIND1ST(isless)
_BINARY_STD_ADAPTER_BIND1ST(islessequal)
_BINARY_STD_ADAPTER_BIND1ST(islessgreater)
_BINARY_STD_ADAPTER_BIND1ST(isunordered)
_BINARY_STD_ADAPTER_BIND1ST(pow)
_BINARY_STD_ADAPTER_BIND2ND(atan2)
_BINARY_STD_ADAPTER_BIND2ND(remainder)
_BINARY_STD_ADAPTER_BIND2ND(remquo)
_BINARY_STD_ADAPTER_BIND2ND(fmax)
_BINARY_STD_ADAPTER_BIND2ND(fmin)
_BINARY_STD_ADAPTER_BIND2ND(fmod)
_BINARY_STD_ADAPTER_BIND2ND(fdim)
_BINARY_STD_ADAPTER_BIND2ND(hypot)
_BINARY_STD_ADAPTER_BIND2ND(isgreater)
_BINARY_STD_ADAPTER_BIND2ND(isgreaterequal)
_BINARY_STD_ADAPTER_BIND2ND(isless)
_BINARY_STD_ADAPTER_BIND2ND(islessequal)
_BINARY_STD_ADAPTER_BIND2ND(islessgreater)
_BINARY_STD_ADAPTER_BIND2ND(isunordered)
_BINARY_STD_ADAPTER_BIND2ND(pow)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(atan2)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(remainder)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(remquo)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(fmax)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(fmin)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(fmod)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(fdim)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(hypot)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(isgreater)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(isgreaterequal)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(isless)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(islessequal)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(islessgreater)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(isunordered)
_BINARY_STD_ADAPTER_BIND1ST_INPLACE(pow)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(atan2)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(remainder)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(remquo)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(fmax)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(fmin)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(fmod)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(fdim)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(hypot)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(isgreater)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(isgreaterequal)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(isless)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(islessequal)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(islessgreater)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(isunordered)
_BINARY_STD_ADAPTER_BIND2ND_INPLACE(pow)
_BINARY_STD_ADAPTER_INPLACE_1ST(atan2)
_BINARY_STD_ADAPTER_INPLACE_1ST(remainder)
_BINARY_STD_ADAPTER_INPLACE_1ST(remquo)
_BINARY_STD_ADAPTER_INPLACE_1ST(fmax)
_BINARY_STD_ADAPTER_INPLACE_1ST(fmin)
_BINARY_STD_ADAPTER_INPLACE_1ST(fmod)
_BINARY_STD_ADAPTER_INPLACE_1ST(fdim)
_BINARY_STD_ADAPTER_INPLACE_1ST(hypot)
_BINARY_STD_ADAPTER_INPLACE_1ST(isgreater)
_BINARY_STD_ADAPTER_INPLACE_1ST(isgreaterequal)
_BINARY_STD_ADAPTER_INPLACE_1ST(isless)
_BINARY_STD_ADAPTER_INPLACE_1ST(islessequal)
_BINARY_STD_ADAPTER_INPLACE_1ST(islessgreater)
_BINARY_STD_ADAPTER_INPLACE_1ST(isunordered)
_BINARY_STD_ADAPTER_INPLACE_1ST(pow)
_BINARY_STD_ADAPTER_INPLACE_2ND(atan2)
_BINARY_STD_ADAPTER_INPLACE_2ND(remainder)
_BINARY_STD_ADAPTER_INPLACE_2ND(remquo)
_BINARY_STD_ADAPTER_INPLACE_2ND(fmax)
_BINARY_STD_ADAPTER_INPLACE_2ND(fmin)
_BINARY_STD_ADAPTER_INPLACE_2ND(fmod)
_BINARY_STD_ADAPTER_INPLACE_2ND(fdim)
_BINARY_STD_ADAPTER_INPLACE_2ND(hypot)
_BINARY_STD_ADAPTER_INPLACE_2ND(isgreater)
_BINARY_STD_ADAPTER_INPLACE_2ND(isgreaterequal)
_BINARY_STD_ADAPTER_INPLACE_2ND(isless)
_BINARY_STD_ADAPTER_INPLACE_2ND(islessequal)
_BINARY_STD_ADAPTER_INPLACE_2ND(islessgreater)
_BINARY_STD_ADAPTER_INPLACE_2ND(isunordered)
_BINARY_STD_ADAPTER_INPLACE_2ND(pow)
}
#endif // STDADAPTERS_H