Create another function template which is designed to only work with uint8_t and/or int8_t, and have your specializations of dump
call that other function template.
Alternately, just create overloads of functions called from the function template dump
. Here's an example demonstrating how that works: http://ideone.com/Z88DU6
I believe doing that to your code would look something like the following, but I'm not entirely positive this works given that I have never used Objective-C (or Objective-C++).
// Note: I believe this works but am not a template wizard and have not tried
namespace {
using namespace Eigen;
using namespace std;
using namespace vMAT;
template <typename T>
inline Eigen::Map<Matrix<T, Dynamic, Dynamic>> get_printable_eigen(Eigen::Map<Matrix<T, Dynamic, Dynamic>> const& in)
{
return in;
}
// No specialization; simple overloads!
inline Eigen::Map<Matrix<int32_t, Dynamic, Dynamic>> get_printable_eigen(Eigen::Map<Matrix<int8_t, Dynamic, Dynamic>> const& in)
{
return in.cast<int32_t>();
}
inline Eigen::Map<Matrix<uint32_t, Dynamic, Dynamic>> get_printable_eigen(Eigen::Map<Matrix<uint8_t, Dynamic, Dynamic>> const& in)
{
return in.cast<uint32_t>();
}
template <typename T>
NSString *
dump(NSString * prefix, T * A, vMAT_Size sizeA)
{
NSMutableString * dump = [NSMutableString stringWithString:prefix];
[dump appendString:@" = \n"];
Eigen::Map<Matrix<T, Dynamic, Dynamic>> DATA(A, sizeA[0], sizeA[1]);
stringstream out;
out << get_printable_eigen(DATA) << endl;
[dump appendFormat:@"%s", out.str().c_str()];
return dump;
}
}
(There are probably other solutions using enable_if
and type traits but SFINAE should be reserved for cases which cannot otherwise be accomplished through simpler means because it produces poor error messages)