tags:

views:

60

answers:

2

I'm getting a strange error. I have a function of the following signature:

 template <typename DATA, DATA max>
 static bool ConvertCbYCrYToRGB(const Characteristic space, const DATA *input, DATA *output, const int pixels) {

Which is later called like this:

 case kByte:
  return ConvertCbYCrYToRGB<U8, 0xFF>(space, (const U8 *)input, (U8 *)output, pixels);
 case kWord:
  return ConvertCbYCrYToRGB<U16, 0xFFFF>(space, (const U16 *)input, (U16 *)output, pixels);
 case kInt:
  return ConvertCbYCrYToRGB<U32, 0xFFFFFFFF>(space, (const U32 *)input, (U32 *)output, pixels);
 case kFloat:
  return ConvertCbYCrYToRGB<R32, FLT_MAX>(space, (const R32 *)input, (R32 *)output, pixels);
 case kDouble:
  return ConvertCbYCrYToRGB<R64, DBL_MAX>(space, (const R64 *)input, (R64 *)output, pixels);

The U* and R* are aliases for the unsigned integer and floating point types, respectively. What's weird is that all the integer ones work perfectly, while the floating point ones fail with a somewhat enigmatic error:

DPXColorConverter.cpp:171: error: no matching function for call to ‘ConvertCbYCrYToRGB(const dpx::Characteristic&, const dpx::R32*, dpx::R32*, const int&)’

Any thoughts?

+4  A: 

you can not use floating point numbers at template value parameters.

Template value parameters must be integral types, ICE to be exact: http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/template_non-type_arguments.htm

aaa
Ouch. Thanks, this explains things.
IneQuation
@inequation maybe you can derive small class which contains maximum values and use that as template parameter?
aaa
Actually, I just got feedback from a client that justifies the use of a totally separate pipeline for floating point ops, so I'm just going to design it a bit differently. Thanks for the suggestion, though. ;)
IneQuation
+2  A: 

As aaa pointed out, you can't use floating point numbers as template value parameters. But in this instance you don't need to. Get rid of the second parameter entirely, and then in the definition of ConvertCbYCrYToRGB instead of using 'max' use std::numeric_limits<DATA>::max(). Documentation on numeric_limits is here: http://www.cplusplus.com/reference/std/limits/numeric_limits/

Joseph Garvin
Whoa, thanks! This indeed solves the issue entirely. :)
IneQuation