The iota
function was formerly in the <algorithm>
header. It has been change to <numeric>
.
I need to keep the old way for backward compatibility so I would like to use preprocessor option to select the right header to include.
When does this changed and which preprocessor option should I use?
iota (from the Greek ι) was re-introduced in <numeric>
when c++11 arrived, as you can see in the ref. So you check if your in an environment without it, and include the old header, or else, include the new header.
Something like this might do the trick:
#if __cplusplus <= 199711L
#include <algorithm>
#else
#include <numeric>
#endif
c++11 sets the value of __cplusplus
to 201103L
. That asserts full conformance to the 2011 standard; it doesn't tell you about partial conformance or compiler extensions. If __cplusplus
is set to 201103L, then either the compiler fully conforms or it's lying to you. If it's not, then you can't really tell which features it supports.
Read more in this answer.
Moreover, this Quora post also agrees with the change (or to be honest; re-introduce) of std::iota
to have happened with c++11.
If you can afford it, just include both libraries.