Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't need to use static function directly. Instead you can write a very general wrapper.</p> <p><a href="https://stackoverflow.com/questions/13074756/how-to-avoid-static-member-function-when-using-gsl-with-c">I believe this is a duplicate question</a>. <a href="https://stackoverflow.com/a/18181494/2472169">My answer</a> to the question I just linked is based on the wrapper presented <a href="https://stackoverflow.com/questions/10593726/a-function-pointer-issue-how-to-efficiently-interface-with-c-api-ie-gsl-from">here</a>. However, I generalized it using templates to avoid the <a href="https://stackoverflow.com/questions/14677997/stdfunction-vs-template/15015502#15015502">performance penalty of std::function</a> due to heap allocation of the functor that std::function holds (the original answer only warns the reader about the penalty that is caused by the multiple indirection involved in std::function implementation, and this is negligible in comparison to the problem caused by heap allocation).</p> <p>EDIT 1: This issue is also discussed <a href="https://stackoverflow.com/questions/13289311/c-function-pointers-with-c11-lambdas">here</a> </p> <p>EDIT 2 (to answer a question you raised in your first comment to my answer). The first caveat is that you have to make sure that whatever <code>std::function</code> holds is not deleted before GSL finish the calculation. Also, @Managu pointed out that the wrapper itself must not be out of scope while GSL works. This is not hard to enforce if you code carefully. Example of bad code:</p> <pre><code> // BAD PROGRAM - EXAMPLE OF WHAT YOU MUST NOT DO. DO NOT COPY THIS CODE // HERE THE WRAPPER GETS PREMATURELY OUT OF SCOPE =&gt; CRASH gsl_function *F auto ptr = [](double x)-&gt;double{return 2*x;}; std::function&lt;double(double)&gt; FF1(std::cref(ptr)) { gsl_function_pp Fp(FF1); F = static_cast&lt;gsl_function*&gt;(&amp;Fp); } (...) // CALL GSL </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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