S
silverburgh.meryl
Hi,
I am trying to write a transform_until template. It is bascially doing
what transform is doing except if UnaryOperation return NULL, it will
break out from the loop.
Here is the code, but it has compile error, can you please tell me what
did I do wrong?
template <class _InputIter, class _OutputIter, class _UnaryOperation>
_OutputIter
transform_until (_InputIter __first, _InputIter __last, _OutputIter
__res,
_UnaryOperation __unary_op)
{
for (; !(__first == __last); ++__res, ++__first) {
// this line does not compile:
_OutputIter::value_type obj = __unary_op (*__first);
if (obj != NULL) {
*__res = obj;
} else {
return __res;
}
}
return __res;
}
Here is the compile error:
.../Utils.h: In function '_OutputIter transform_until(_InputIter,
_InputIter, _OutputIter, _UnaryOperation)':
.../Utils.h:88: error: expected `;' before 'obj'
.../Utils.h:90: error: 'obj' was not declared in this scope
I am trying to write a transform_until template. It is bascially doing
what transform is doing except if UnaryOperation return NULL, it will
break out from the loop.
Here is the code, but it has compile error, can you please tell me what
did I do wrong?
template <class _InputIter, class _OutputIter, class _UnaryOperation>
_OutputIter
transform_until (_InputIter __first, _InputIter __last, _OutputIter
__res,
_UnaryOperation __unary_op)
{
for (; !(__first == __last); ++__res, ++__first) {
// this line does not compile:
_OutputIter::value_type obj = __unary_op (*__first);
if (obj != NULL) {
*__res = obj;
} else {
return __res;
}
}
return __res;
}
Here is the compile error:
.../Utils.h: In function '_OutputIter transform_until(_InputIter,
_InputIter, _OutputIter, _UnaryOperation)':
.../Utils.h:88: error: expected `;' before 'obj'
.../Utils.h:90: error: 'obj' was not declared in this scope