I am working in a C++03 project. And I'm taking an iterator into a template. I need to assert that this iterator references a specific type. Does C++ provide me a way to do this beyond writing my own struct for validation?
What I want is the equivalent of this C++14 functionality:
static_assert(is_same<iterator_traits<InputIterator>::value_type, int>(), "Not an int iterator");
Since it's C++03 I assume that I'll have to use an assert
and that's fine if it's a runtime only debug check I just need the check to be there.
Since the parameters of the question are:
A way to do this beyond writing my own struct for validation
And it is assumed:
I'll have to use an
assert
and that's fine if it's a runtime only debug check
You can use typeid
in C++03:
assert(typeid(iterator_traits<InputIterator>::value_type) == typeid(int));