Note that there are some explanatory texts on larger screens.

plurals
  1. PO<functional> (nested bind) problems with MSVC 2010
    primarykey
    data
    text
    <p>I have the following code (I'm sorry for the lengthiness):</p> <pre><code>double primeValue( const func1D &amp;func, const double lowerBound, const double upperBound, const double pole ) { // check bounds if( lowerBound &gt;= upperBound ) throw runtime_error( "lowerBound must be smaller than upperBound!" ); // C++0x way of writing: fullFunc(x) = func(x)/(x-a) func1D fullFunc = bind( divides&lt;double&gt;(), // division of bind(func, _1), // f(x), with _1 = x bind(minus&lt;double&gt;(), _1, pole) ); // by x-a, with _1 = x // pole not in domain if( pole&lt;lowerBound || pole&gt;upperBound) { cout &lt;&lt; "Case 1" &lt;&lt; endl; return integrateSimpson( fullFunc, 1000, lowerBound, upperBound ); } // pole closer to upper bound else if( upperBound-pole &lt; pole-lowerBound ) { cout &lt;&lt; "Case 2" &lt;&lt; endl; // C++0x way of writing g(x) := [f(x)-f(2a-x)]/(x-a) func1D specialFirstFunc = bind( std::divides&lt;double&gt;(), // division of bind(minus&lt;double&gt;(), // numerator: bind(func, _1), // f(x) minus bind(func, bind(minus&lt;double&gt;(), 2.*pole, _1))), //f(2a-x) bind(minus&lt;double&gt;(), _1, pole) ); // denominator: x-a const double trickyPart = integrateSimpson( specialFirstFunc, 1000, pole+.000001, upperBound ); const double normalPart = integrateSimpson( fullFunc, 1000, lowerBound, 2.*pole-upperBound ); cout &lt;&lt; "Tricky part: " &lt;&lt; trickyPart &lt;&lt; endl; cout &lt;&lt; "Normal part: " &lt;&lt; normalPart &lt;&lt; endl; return trickyPart + normalPart; } else // pole closer to lower bound { cout &lt;&lt; "Case 3" &lt;&lt; endl; // C++0x way of writing g(x) := [f(x)-f(2a-x)]/(x-a) func1D specialFirstFunc = bind( std::divides&lt;double&gt;(), // division of bind(minus&lt;double&gt;(), // numerator: bind(func, _1), // f(x) minus bind(func, bind(minus&lt;double&gt;(), 2.*pole, _1))), //f(2a-x) bind(minus&lt;double&gt;(), _1, pole) ); // denominator: x-a const double trickyPart = integrateSimpson( specialFirstFunc, 1000, lowerBound, pole-.00001 ); const double normalPart = integrateSimpson( fullFunc, 1000, 2.*pole-lowerBound, upperBound ); cout &lt;&lt; "Tricky part: " &lt;&lt; trickyPart &lt;&lt; endl; cout &lt;&lt; "Normal part: " &lt;&lt; normalPart &lt;&lt; endl; return trickyPart + normalPart; } } </code></pre> <p>It integrates functions over the real axis that contain a singularity (pole) using the principal values concept from the math domain of Complex Analysis. The <code>bind</code> and <code>function</code> parts modify the original function f(x) to </p> <blockquote> <p>(f(x)-f(2*pole-x))/(x-a)</p> </blockquote> <p>It even gives he correct result for my simple test case function. Additional details I can provide if requested:</p> <pre><code>typedef std::function&lt;double (double)&gt; func1D; double integrateSimpson( func1D, const size_t nSteps, const double lowerBound, const double upperBound); </code></pre> <p>The latter integrates using the simple Simpson integration rule. Code can be provided, but isn't very relevant to the problem at hand.</p> <p>This compiles fine with GCC 4.4+ (tested with 4.4.5 and 4.5.2 prerelease, CFLAGS="-O2 -std=c++0x -pedantic -Wall -Wextra"), but produces internal header errors (C2664) on MSVC 2010. (I can provide error output if needed, there are no references at all to my code (!)).</p> <p>Have I found a bug in MSVC?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload