It's time for another 'how do i do this in c++ without loosing my grip'-question!
This time:
Considering the following code taken from cplusplus.com:
template<class InputIterator, class OutputIterator>
OutputIterator copy ( InputIterator first, InputIterator last, OutputIterator result )
{
while (first!=last) *result++ = *first++;
return result;
}
Is there a way to cast *first to the type of *result?
In other words: is there a way to determine (at compiletime) the type of result?
yes, the type of *result is ('cause the type of result is OutputIterator )
typename std::iterator_traits<OutputIterator>::value_type
of course, if OutputIterator is a pointer or a correctly written STL-compatible iterator. Otherwise, no, I think there is no way. In the upcoming C++0x, it would be much easier, that is,
decltype(*result)
HTH,
Armen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With