S
Steffen Brinkmann
Hi!
I tried to modify the transform algorithm in a way that it doesn't
take iterators, but a reference to a container class and a value,
because Mostly I need to do an operation of a container and a single
number (e.g. multiply all the values in a vector by 3 or so).
So, this is my intent:
#ifndef ALGORITHM_EXT_HH
#define ALGORITHM_EXT_HH
#include<iterator>
namespace std
{
template<typename _Tp, template<typename> class _Container,
typename _Tpval, typename _BinaryOperation>
_Container<_Tp>&
transform(_Container<_Tp>& __cont, const _Tpval& __val,
_BinaryOperation __binary_op)
{
_Container<_Tp>::iterator __iter=__cont.begin();
_Container<_Tp>::iterator __end=__cont.end();
for ( ; __iter != __end; ++__iter)
*__iter = __binary_op(*__iter, __val);
return __cont;
}
} //namespace std
#endif //ALGORITHM_EXT_HH
The error message I get from g++ (GCC) 3.3 20030226 (prerelease) (SuSE
Linux) is:
linux@earth:~/> g++ mod2pnm.cc -o mod2pnm
In file included from mod2pnm.cc:16:
algorithm_ext.hh: In function `_Container<_Tp>&
std::transform(_Container<_Tp>&, const _Tpval&, _BinaryOperation)':
algorithm_ext.hh:32: error: parse error before `=' token
algorithm_ext.hh:33: error: parse error before `=' token
algorithm_ext.hh: In function `_Container<_Tp>&
std::transform(_Container<_Tp>&, const _Tpval&, _BinaryOperation)
[with _Tp
= double, _Container = std::vector, _Tpval = double,
_BinaryOperation =
std::minus<double>]':
mod2pnm.cc:144: instantiated from here
algorithm_ext.hh:34: error: `__end' undeclared (first use this
function)
algorithm_ext.hh:34: error: (Each undeclared identifier is reported
only once
for each function it appears in.)
algorithm_ext.hh:34: error: `__iter' undeclared (first use this
function)
Any ideas, what's wrong? I tried all night long!
Thanks, Steffen
I tried to modify the transform algorithm in a way that it doesn't
take iterators, but a reference to a container class and a value,
because Mostly I need to do an operation of a container and a single
number (e.g. multiply all the values in a vector by 3 or so).
So, this is my intent:
#ifndef ALGORITHM_EXT_HH
#define ALGORITHM_EXT_HH
#include<iterator>
namespace std
{
template<typename _Tp, template<typename> class _Container,
typename _Tpval, typename _BinaryOperation>
_Container<_Tp>&
transform(_Container<_Tp>& __cont, const _Tpval& __val,
_BinaryOperation __binary_op)
{
_Container<_Tp>::iterator __iter=__cont.begin();
_Container<_Tp>::iterator __end=__cont.end();
for ( ; __iter != __end; ++__iter)
*__iter = __binary_op(*__iter, __val);
return __cont;
}
} //namespace std
#endif //ALGORITHM_EXT_HH
The error message I get from g++ (GCC) 3.3 20030226 (prerelease) (SuSE
Linux) is:
linux@earth:~/> g++ mod2pnm.cc -o mod2pnm
In file included from mod2pnm.cc:16:
algorithm_ext.hh: In function `_Container<_Tp>&
std::transform(_Container<_Tp>&, const _Tpval&, _BinaryOperation)':
algorithm_ext.hh:32: error: parse error before `=' token
algorithm_ext.hh:33: error: parse error before `=' token
algorithm_ext.hh: In function `_Container<_Tp>&
std::transform(_Container<_Tp>&, const _Tpval&, _BinaryOperation)
[with _Tp
= double, _Container = std::vector, _Tpval = double,
_BinaryOperation =
std::minus<double>]':
mod2pnm.cc:144: instantiated from here
algorithm_ext.hh:34: error: `__end' undeclared (first use this
function)
algorithm_ext.hh:34: error: (Each undeclared identifier is reported
only once
for each function it appears in.)
algorithm_ext.hh:34: error: `__iter' undeclared (first use this
function)
Any ideas, what's wrong? I tried all night long!
Thanks, Steffen