template<>
ROKeyIndex2 updateIndex<ROKeyIndex2, ROKeyIndex>(const ROKeyIndex& keyIndex)
{
ROKeyIndex2 index2(keyIndex, 0);
return index2;
}
template<>
ROKeyIndex2 updateIndex<ROKeyIndex2, ROUnIndex>(const ROUnIndex& keyIndex)
{
ROKeyIndex2 index2(0, keyIndex);
return index2;
}
It uses template specialization to differentiate two kinds of implementation.
However, since they are in the same type int,
typedef int ROKeyIndex;
typedef int ROUnIndex;
In VS2010, it will report duplicated implementations in linking phase.
But they are really in different meaning in application level except they are defined in the same type.
How to solve?
by using strong_typedef, it will force them to be in different types, which makes those template specialization functions be different.
#include <boost/strong_typedef.hpp>
BOOST_STRONG_TYPEDEF(int, ROVarIndex);
BOOST_STRONG_TYPEDEF(int, ROUnIndex);
In the boost header file,
explicit D(const T t_) : t(t_) {};
Good post!
ReplyDelete