headmyshoulder / odeint-v2

odeint - solving ordinary differential equations in c++ v2
http://headmyshoulder.github.com/odeint-v2/
Other
340 stars 101 forks source link

Switch <iterator>-1 for --<iterator> in integrate_times() to allow use with bidirectional iterators #158

Closed ds283 closed 9 years ago

ds283 commented 9 years ago

The dense-output stepper version of integrate_times() uses

Time last_time_point = static_cast<time_type>(*(end_time-1));

to deduce the last time in the range it is given, but this works only if the range is delimited by random access steppers which support addition and subtraction of integers.

For my purposes I'd like to use integrate_times with a range inherited from std::map, which supports only bidirectional iterators. This doesn't seem a big change; it can be done just by copying the end-point iterator and decrementing it.

ds283 commented 9 years ago

Thanks for the helpful comments. The most recent commit should have the changes you suggested.

mariomulansky commented 9 years ago

Thanks for the contribution! Did you by any chance check if a similar change needs to be done in any of the other integrate routines?

ds283 commented 9 years ago

I haven't checked in the sense of getting code to compile, but I believe only integrate_times() expects a range delimited by TimeIterator - so I hope the other functions are OK.

I wondered whether the iterator interface might also expect an underlying random-access TimeIterator, but I didn't spot anything on quickly looking through this part of the library.