Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>to_...</code> member functions all take an argument solely for the purpose of assisting with template argument deduction, so yes, passing a value-initialized<sup>&#8224;</sup> instance of the same type you want as the return type is safe, though needlessly inefficient.</p> <p>However, the <code>to_...</code> member functions only exist to assist broken compilers that don't properly support templated conversion operators -- why are you using them in the first place? The clean syntax would be simply:</p> <pre><code>boost::array&lt;int, 3&gt; OneTwoThree() { return boost::assign::list_of(1)(2)(3); } </code></pre> <p>Note that I've used <code>boost::array&lt;&gt;</code> here rather than <code>std::tr1::array&lt;&gt;</code>; the reason is that the Boost.Assign library has no knowledge (yet) of TR1/C++11 standard libraries, and thus is not properly specialized for <code>std::array&lt;&gt;</code> or <code>std::tr1::array&lt;&gt;</code>. To add this specialization yourself, and consequently make the above code work with <code>std::tr1::array&lt;&gt;</code>, add the following code <strong>after</strong> including the Boost.Assign headers:</p> <pre><code>namespace boost { namespace assign_detail { template&lt;typename T, std::size_t sz&gt; type_traits::yes_type assign_is_array(std::tr1::array&lt;T, sz&gt; const*); }} </code></pre> <p>(Note: only tested with Boost 1.48; earlier versions may need a different specialization.)</p> <hr> <p><sup>&#8224;</sup> The syntax in your question is not default-construction, it's value-initialization.</p>
 

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