<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>The reason you methods is not working is because C++ can't deduce the template parameters from the argument types passed to the function. That is to say since T is only used for the return type, and not as an argument to the function, so you should explicitly specify it as a template parameters. Something like this should work:</div><div><br></div><div>r = this->EnableIfTest<OutputType>( 3 );</div><div><br></div><div>Brad</div><div><div><br></div><div><br><div><div>On Aug 22, 2012, at 4:08 PM, M Stauffer -V- wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta content="text/html; charset=us-ascii" http-equiv="Content-Type">
<meta name="GENERATOR" content="MSHTML 8.00.6001.19258">
<div style="WORD-WRAP: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space">
<div dir="ltr" align="left"><span class="656050320-22082012"><font size="2" face="Verdana">Great, thanks Brad.</font></span></div>
<div dir="ltr" align="left"><span class="656050320-22082012"><font size="2" face="Verdana"></font></span> </div>
<div dir="ltr" align="left"><span class="656050320-22082012"><font size="2" face="Verdana">I can reproduce what you explain below, but it's not working when I
rely on only the return parameter type for the template parameter deduction.
That is, the following won't compile</font></span></div>
<div dir="ltr" align="left"><span class="656050320-22082012"><font size="2" face="Verdana"></font></span> </div>
<div dir="ltr" align="left"><span class="656050320-22082012"><font size="2" face="Verdana">template< typename T ><br>typename EnableIfC< IsSame<
T, ScalarDerivativeType >::Value, T >::Type<br>EnableIfTest(int
val)<br>{<br> std::cout << "Output == ScalarDerivativeType. val "
<< val << "\n" << std::endl;<br> T o;<br>
o.Fill(1);<br> return o;<br>}<br></font></span></div>
<div dir="ltr" align="left"><span class="656050320-22082012"><font size="2" face="Verdana">(and similarly with DisableIfC...)</font></span></div>
<div dir="ltr" align="left"><span class="656050320-22082012"><font size="2" face="Verdana"> </font></span></div>
<div dir="ltr" align="left"><span class="656050320-22082012"><font size="2" face="Verdana">In implementation:</font></span></div>
<div dir="ltr" align="left"><span class="656050320-22082012"><font size="2" face="Verdana"></font></span> </div>
<div dir="ltr" align="left"><span class="656050320-22082012"><font size="2" face="Verdana"> OutputType r;<br></font></span><span class="656050320-22082012"><font size="2" face="Verdana"> r =
this->EnableIfTest(3);<br></font></span></div>
<div><span class="656050320-22082012"><font size="2" face="Verdana">I think
I'll skip this for now because I have a working implementation and the extra
overhead it has, because it requires a nested function call, is only a few
%.</font></span></div>
<div><span class="656050320-22082012"><font size="2" face="Verdana"></font></span> </div>
<div><span class="656050320-22082012"><font size="2" face="Verdana">I'll put up a
patch soon and hopefully you could take a look at it, Brad. I'll let you
know.</font></span></div>
<div><span class="656050320-22082012"><font size="2" face="Verdana"></font></span> </div>
<div><span class="656050320-22082012"><font size="2" face="Verdana">-M</font></span></div>
<div><font size="2" face="Verdana"></font> </div>
<div><font size="2" face="Verdana"></font> </div>
<div><font size="2" face="Verdana"></font> </div>
<div><br></div>
<blockquote style="border-left-color: rgb(0, 0, 0); border-left-width: 2px; border-left-style: solid; padding-left: 5px; margin-left: 5px; margin-right: 0px; position: static; z-index: auto; " dir="ltr">
<div dir="ltr" lang="en-us" class="OutlookMessageHeader" align="left">
<hr tabindex="-1">
<font size="2" face="Tahoma"><b>From:</b> Bradley Lowekamp
[mailto:blowekamp@mail.nih.gov] <br><b>Sent:</b> Tuesday, August 21, 2012 3:37
PM<br><b>To:</b> Michael Stauffer<br><b>Cc:</b>
<a href="mailto:Insight-developers@itk.org">Insight-developers@itk.org</a><br><b>Subject:</b> Re: [Insight-developers]
Overloading methods<br></font><br></div>
<div></div>Hello Michael,
<div><br></div>
<div>Here is the declaration of one of the GetComponent methods:</div>
<div><br></div>
<div>
<div>template< typename T></div>
<div> typename EnableIfC<</div>
<div> IsSame<T, typename
NumericTraits<T>::ValueType>::Value,</div>
<div> T >::Type</div>
<div> GetComponent(const T pix,</div>
<div> unsigned int
itkNotUsed( idx ) ) const;</div></div>
<div><br></div>
<div>This uses the EnableIf idom to answer lets look at a simplification of
function:</div>
<div><br></div>
<div>
<div>template< typename T> T GetComponent(const T
pix, unsigned int idx ) const;</div></div>
<div><br></div>
<div>So I just simplified it some. So for function C++ has the ability to
implicitly deduce the template parameters from the arguments passed to a
function. So if you did the following:</div>
<div><br></div>
<div>int i;</div>
<div>GetComponent( i, 10 )</div>
<div><br></div>
<div>C++ can deduce the template parameter T, based on the function argument i
being of type int.</div>
<div><br></div>
<div><br></div>
<div>There are a couple C++ tricks to overloading functions that should
be considered before the EnableIf idiom should be considered. Using the
EnableIf idom is really a last resort when simpler more understandable
techniques can not be used.</div>
<div><br></div>
<div><br></div>
<div>Brad</div>
<div><br>
<div>
<div>On Aug 17, 2012, at 6:17 PM, Michael Stauffer wrote:</div>
<blockquote type="cite">
<div>I'm using the new EnableIfC and DisableIfC routines, to try and
optimize itkCentralDifferenceImageFunction::Evaluate* methods by
specializing for scalar and vector pixel types. I have it working using my
own SFINAE method I pulled off the web. But this, requires calling templated
subfunctions, which cost about 2% in overhead.<br><br></div></blockquote>
<blockquote type="cite">
<div><br>Looking at itkEnableIf.h and its usage in
PatchBasedDenoisingImageFilter, I was hoping to be able to call the
specialized Evalute* methods directly.<br><br><br>The method
PatchBasedDenoisingImageFilter::GetComponent is are template-specialized to
use one of two versions depending on whether the pixel is scalar or not. The
method is templated.<br>But in
PatchBasedDenoisingImageFilter::ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(),
GetComponent is called without any template parameters. How does this work?
I must be missing something.<br><br><br><br><br>template
<br>void<br>PatchBasedDenoisingImageFilter<br>::ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(const
PixelType& a, const PixelType& b,<br>const RealArrayType&
weight,<br>bool itkNotUsed(useCachedComputations),<br>SizeValueType
itkNotUsed(cacheIndex),<br>EigenValuesCacheType&
itkNotUsed(eigenValsCache),<br>EigenVectorsCacheType&
itkNotUsed(eigenVecsCache),<br>RealType& diff, RealArrayType&
norm)<br>{<br>for (unsigned int pc = 0; pc < m_NumPixelComponents;
++pc)<br>{<br>RealValueType tmpDiff = GetComponent(b, pc) - GetComponent(a,
pc);<br>RealValueType tmpWeight = weight[pc];<br>SetComponent(diff, pc,
tmpDiff);<br>norm[pc] = tmpWeight * tmpWeight * tmpDiff *
tmpDiff;<br>}<br>}<br><br></div></blockquote></div><br>
<div>
<div style="WORD-WRAP: break-word; FONT-SIZE: 12px; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space"><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: normal normal normal 12px/normal Helvetica; white-space: normal; orphans: 2; letter-spacing: normal; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; " class="Apple-style-span"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font style="FONT: 12px Helvetica" size="3" face="Helvetica">========================================================</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font style="FONT: 12px Helvetica" size="3" face="Helvetica">Bradley Lowekamp<span class="Apple-converted-space"> </span><span class="Apple-converted-space"> </span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font style="FONT: 12px Helvetica" size="3" face="Helvetica">Medical Science and Computing for</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font style="FONT: 12px Helvetica" size="3" face="Helvetica">Office of High Performance Computing and
Communications</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font style="FONT: 12px Helvetica" size="3" face="Helvetica">National Library of Medicine<span class="Apple-converted-space"> </span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font style="FONT: 12px Helvetica" size="3" face="Helvetica"><a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a></font></div><br class="Apple-interchange-newline"></span></div><br class="Apple-interchange-newline"></div><br></div></blockquote></div>
</blockquote></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">========================================================</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">Bradley Lowekamp<span class="Apple-converted-space"> </span><span class="Apple-converted-space"> </span></font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">Medical Science and Computing for</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">Office of High Performance Computing and Communications</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">National Library of Medicine<span class="Apple-converted-space"> </span></font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; "><a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a></font></p><br class="Apple-interchange-newline"></span></div></span></span><br class="Apple-interchange-newline">
</div>
<br></div></div></body></html>