Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can write a <em>transform iterator</em> to convert the <code>weak_ptr&lt;T&gt;</code> to a <code>weak_ptr&lt;const T&gt;</code>. Since you're already using Boost, you can use <code>boost::transform_iterator</code>:</p> <pre><code>#include &lt;boost/iterator/transform_iterator.hpp&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/weak_ptr.hpp&gt; #include &lt;set&gt; // Functor to transform a weak_ptr&lt;T&gt; to a weak_ptr&lt;const T&gt; template &lt;typename T&gt; struct make_weak_ptr_const : std::unary_function&lt;boost::weak_ptr&lt;T&gt;, boost::weak_ptr&lt;const T&gt; &gt; { boost::weak_ptr&lt;const T&gt; operator()(const boost::weak_ptr&lt;T&gt;&amp; p) const { return p; } }; struct S { }; // Container demonstrating use of make_weak_ptr_const: struct my_awesome_container { typedef std::set&lt;boost::weak_ptr&lt;S&gt; &gt; BaseSet; typedef BaseSet::const_iterator BaseIterator; typedef boost::transform_iterator&lt; make_weak_ptr_const&lt;S&gt;, BaseIterator &gt; iterator; iterator begin() const { return TransformedIterator(data.begin()); } iterator end() const { return TransformedIterator(data.end()); } std::set&lt;boost::weak_ptr&lt;S&gt; &gt; data; }; </code></pre> <p>If you don't want to use <code>boost::transform_iterator</code>, it is a straightforward task to write your own. I showed how to do this in <a href="https://stackoverflow.com/questions/2467000/is-there-a-java-map-keyset-equivalent-for-cs-stdmap/5099345#5099345">an answer to another question</a>.</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