S
Steven T. Hatton
This code works for dividing each element of a boost::array<> by a value of
its element type:
template <typename T, size_t S>
inline boost::array<T, S>& operator/=( boost::array<T, S>& lhs, const T&
rhs ) {
std::transform( lhs.begin()
, lhs.end()
, lhs.begin()
, std::bind2nd( std::divides<T>(), rhs ) );
return lhs;
}
I want to use std::transform in a similar fashion to set each element of a
boost::array<> to the result of applying std::abs() to it.
The result can easily be obtained with this code:
template <typename T, size_t Order_S>
inline boost::array<T, Order_S>& abs( boost::array<T, Order_S>& v ) {
for ( size_t i = 0; i < v.size(); i++ ) {
v[ i ] = std::abs( v[ i ] );
}
return v;
}
I would like to know how to apply a function such as std::abs in a way
similar to the use of std::bind2nd ( std::divides<T>(), rhs ) in the above
example. How can this be done?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
its element type:
template <typename T, size_t S>
inline boost::array<T, S>& operator/=( boost::array<T, S>& lhs, const T&
rhs ) {
std::transform( lhs.begin()
, lhs.end()
, lhs.begin()
, std::bind2nd( std::divides<T>(), rhs ) );
return lhs;
}
I want to use std::transform in a similar fashion to set each element of a
boost::array<> to the result of applying std::abs() to it.
The result can easily be obtained with this code:
template <typename T, size_t Order_S>
inline boost::array<T, Order_S>& abs( boost::array<T, Order_S>& v ) {
for ( size_t i = 0; i < v.size(); i++ ) {
v[ i ] = std::abs( v[ i ] );
}
return v;
}
I would like to know how to apply a function such as std::abs in a way
similar to the use of std::bind2nd ( std::divides<T>(), rhs ) in the above
example. How can this be done?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell