c++ - Converting arrays in stl like copy -
it's time 'how do in c++ without loosing grip'-question!
this time:
considering following code taken cplusplus.com:
template<class inputiterator, class outputiterator> outputiterator copy ( inputiterator first, inputiterator last, outputiterator result ) { while (first!=last) *result++ = *first++; return result; }
is there way cast *first
type of *result
?
in other words: there way determine (at compiletime) type of result?
yes, type of *result
('cause type of result
outputiterator
)
typename std::iterator_traits<outputiterator>::value_type
of course, if outputiterator pointer or correctly written stl-compatible iterator. otherwise, no, think there no way. in upcoming c++0x, easier, is,
decltype(*result)
hth,
armen
Comments
Post a Comment