Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's unfortunate this question didn't draw more attention, but I guess the large chunk of code didn't help much (that and the fact that template metaprogramming is not so popular).</p> <p>Anyway, you're right, it's a similar issue.</p> <p>The problem is that the <em>views</em> in fusion do not copy the arguments, they only keep references to them. This allows you to modify the original arguments by their intermediate.</p> <p>The trouble is that in C++ you are authorized to bind a temporary to a const-reference, and the temporary lifetime is extended to that of the reference. However this behavior is not transitive, which has caused a heapload of troubles. (Clang will attempt to diagnose those situations, unfortunately the first patch failed :p)</p> <p>So here your problem is located in one single line:</p> <pre><code>return boost::fusion::zip(fieldNames &lt; T &gt;(), constRefFields(obj)); </code></pre> <ul> <li><code>fieldNames&lt;T&gt;()</code> creates a temporary, that is bound to a const-reference, it's lifetime is extended until the end of the expression: <code>;</code></li> <li>when you return the view, the temporary lifetime has expired, you're holding onto a dangling reference</li> </ul> <p>Quick fix: make <code>fieldNames&lt;T&gt;()</code> have a local static variable and return a reference to this variable, this will fix the lifetime issue.</p> <p>I still haven't understood what you were attempting though, so I can't really give "more sensible" advice :)</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.
    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