Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding vectors within typedef map<set,vectors>
    text
    copied!<p>I've a data structure as follows</p> <pre><code>typedef vector&lt;double&gt; v_t; typedef set&lt;int&gt; s_t; typedef map&lt;s_t, v_t&gt; m_t; </code></pre> <p>Lets say the map <code>m1</code> that has following values :</p> <pre><code>&lt; &lt;1&gt;,&lt;1,1,1,1&gt; &gt; &lt; &lt;2&gt;,&lt;2,2,2,2&gt; &gt; &lt; &lt;3&gt;,&lt;3,3,3,3&gt; &gt; &lt; &lt;4&gt;,&lt;4,4,4,4&gt; &gt; </code></pre> <p>and I've a separate vector <code>v1</code> that has values like </p> <pre><code>&lt;1,3,4&gt; </code></pre> <p>Now what I want to do is to add the vectors the first, third and fourth vectors in the map and the result should be stored in a new map say <code>mtot</code> as</p> <pre><code>&lt; &lt;1,3,4&gt;,&lt;8,8,8,8&gt; &gt; </code></pre> <p>Here is my following try that results in a segmentation fault: Any help, improvement or even your idea of implementation is greatly appreciated.</p> <pre><code> s_t stemp,stemp1; v_t vtot(4); //I know the size typedef v_t::iterator v_it; typedef m_t::iterator m_it; // Assume I've v1 and m1 in hand for(v_it it(v1.begin());it != v1.end();++it) { stemp1.insert(stemp1.end(),*it); m_it mit = m1.find(stemp1); copy(mit-&gt;second.begin(),mit-&gt;second.end(),ostream_iterator&lt;int&gt;(cout," ")); cout &lt;&lt; endl; // Debug not working. There is some problem with the iterator I guess transform(mit-&gt;second.begin(),mit-&gt;second.end(),vtot.begin(),vtot.begin(),plus&lt;double&gt;()); stemp1.clear(); } stemp.insert(v1.begin(),v1.end()); mtot.insert(mtot.end(),make_pair(stemp,vtot)); } </code></pre> <p>Thanks.</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