Is it possible to specialize an Iterator template parameter by its value_type
?
I have a function with the following prototype.
template<typename InputIterator>
void f(InputIterator first, InputIterator last);
And I want to handle specially if InputIterator::value_type
is SomeSpecificType.
Using SFINAE, assuming
enable_if[_c]
andis_same
are either from Boost or<type_traits>
(and are appropriately qualified with eitherboost::
orstd::
respectively):In the Boost case, use
boost::enable_if_c
for something similar to the above. You can useboost::enable_if
and get rid of the::value
but then must also use e.g.boost::disable_if
.This will work. This type of specialization only works with structs, so I can't do this with a function.
This shouldn't require you to set the type. It should be inferred automatically.
Call me naive, but why wouldn't the following suffice?
OK, forget that above, that was nonsense. Here's a way to do it, which is just Luc's correct answer from above, for C++0x:
How about:
You can use some intermediate structs to get the partial template specialisation that you need. Something like this should do the trick