Copy and Cast a List
-
Is there a standard vectorized way to copy a list of doubles to a list of int8 values? I would like to code the following:
typedef __uint8 unsigned __int8;
double *const srcList = new double [ARRAY_SIZE];
__uint8 *const dstList = new __uint8[ARRAY_SIZE];
for (size_t i = 0; i < ARRAY_SIZE; ++i)
dstList[i] = static_cast<__uint8>(max<double>(0, min<double>(255, srcList[i])));I would like to code this more like the following:
__uint8 ToUint8(double const inVal) {
return static_cast<__uint8>(max<double>(0, min<double>(255, srcList[i])));
}
std::???(srcList, srcList + ARRAY_SIZE, dstList, &ToUint8);Is there some existing function that will make the above work, or do I need to just make the iterator myself? Thanks,
Sounds like somebody's got a case of the Mondays -Jeff
-
Is there a standard vectorized way to copy a list of doubles to a list of int8 values? I would like to code the following:
typedef __uint8 unsigned __int8;
double *const srcList = new double [ARRAY_SIZE];
__uint8 *const dstList = new __uint8[ARRAY_SIZE];
for (size_t i = 0; i < ARRAY_SIZE; ++i)
dstList[i] = static_cast<__uint8>(max<double>(0, min<double>(255, srcList[i])));I would like to code this more like the following:
__uint8 ToUint8(double const inVal) {
return static_cast<__uint8>(max<double>(0, min<double>(255, srcList[i])));
}
std::???(srcList, srcList + ARRAY_SIZE, dstList, &ToUint8);Is there some existing function that will make the above work, or do I need to just make the iterator myself? Thanks,
Sounds like somebody's got a case of the Mondays -Jeff
you or the build in functions have to parse the entire list. try stl's
for_each
-
Is there a standard vectorized way to copy a list of doubles to a list of int8 values? I would like to code the following:
typedef __uint8 unsigned __int8;
double *const srcList = new double [ARRAY_SIZE];
__uint8 *const dstList = new __uint8[ARRAY_SIZE];
for (size_t i = 0; i < ARRAY_SIZE; ++i)
dstList[i] = static_cast<__uint8>(max<double>(0, min<double>(255, srcList[i])));I would like to code this more like the following:
__uint8 ToUint8(double const inVal) {
return static_cast<__uint8>(max<double>(0, min<double>(255, srcList[i])));
}
std::???(srcList, srcList + ARRAY_SIZE, dstList, &ToUint8);Is there some existing function that will make the above work, or do I need to just make the iterator myself? Thanks,
Sounds like somebody's got a case of the Mondays -Jeff
std::transform(src.begin(), src.end(),
dst.begin(), // or std::back_inserter(dst)
[] (double v)->(__uint8) {
return (__uint8)v;
});... if you're on vc++10, define trivial
std::unary_function
converter otherwise. You could also try one of the selectors or projectors from<algorithm>
, with the other overload oftransform
then. Cheers, Paul