P
Patrick Guio
Dear all,
I am trying to use the std::transform algorithm to to the following
vector< vector<char> >::iterator ik = keys.begin(); // key list iterator
vector< vector<char> >::iterator is = ik; // save begin
[snip]
vector<char>::const_iterator i = ik->begin();
vector<char>::const_iterator e = ik->end();
vector<char>::iterator s = is->begin();
for ( ; i != e; i++, s++) { // xor the key s = s ^ k
*s ^= *i;
}
I wrote the binary operator xor
template <class _Tp>
struct logical_xor : public std::binary_function<_Tp, _Tp, bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{
return __x ^ __y;
}
};
and call it into the transform algorithm
// run through the ik iterator (input1) and is iterator (input2) and
// return into is (output)
std::transform(ik->begin(), ik->end(), is->begin(), is->begin(), logical_xor<byte>());
But it does not seem to work correctly.
Can input2 and output iterator be the same? (i.e. perform the operation
(output =) input2 = op(input1, input2)
Is there a way to perform operation and assignement ^= operator instead?
(i.e. perform the operation (output =) input2 op= input1
Sincerely,
Patrick
I am trying to use the std::transform algorithm to to the following
vector< vector<char> >::iterator ik = keys.begin(); // key list iterator
vector< vector<char> >::iterator is = ik; // save begin
[snip]
vector<char>::const_iterator i = ik->begin();
vector<char>::const_iterator e = ik->end();
vector<char>::iterator s = is->begin();
for ( ; i != e; i++, s++) { // xor the key s = s ^ k
*s ^= *i;
}
I wrote the binary operator xor
template <class _Tp>
struct logical_xor : public std::binary_function<_Tp, _Tp, bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{
return __x ^ __y;
}
};
and call it into the transform algorithm
// run through the ik iterator (input1) and is iterator (input2) and
// return into is (output)
std::transform(ik->begin(), ik->end(), is->begin(), is->begin(), logical_xor<byte>());
But it does not seem to work correctly.
Can input2 and output iterator be the same? (i.e. perform the operation
(output =) input2 = op(input1, input2)
Is there a way to perform operation and assignement ^= operator instead?
(i.e. perform the operation (output =) input2 op= input1
Sincerely,
Patrick