Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have started using <a href="http://www.boost.org/doc/libs/1_38_0/libs/assign/doc/index.html" rel="noreferrer"><code>boost::assign</code></a> for cases that I want to statically assign specific values (examples lifted from link above).</p> <pre><code>#include &lt;boost/assign/std/vector.hpp&gt; using namespace boost::assign; // bring 'operator+()' into scope { vector&lt;int&gt; values; values += 1,2,3,4,5,6,7,8,9; } </code></pre> <p>You can also use <code>boost::assign</code> for maps.</p> <pre><code>#include &lt;boost/assign/list_inserter.hpp&gt; #include &lt;string&gt; using boost::assign; std::map&lt;std::string, int&gt; months; insert( months ) ( "january", 31 )( "february", 28 ) ( "march", 31 )( "april", 30 ) ( "may", 31 )( "june", 30 ) ( "july", 31 )( "august", 31 ) ( "september", 30 )( "october", 31 ) ( "november", 30 )( "december", 31 ); </code></pre> <p>You can allow do direct assignment with <code>list_of()</code> and <code>map_list_of()</code></p> <pre><code>#include &lt;boost/assign/list_of.hpp&gt; // for 'list_of()' #include &lt;list&gt; #include &lt;stack&gt; #include &lt;string&gt; #include &lt;map&gt; using namespace std; using namespace boost::assign; // bring 'list_of()' into scope { const list&lt;int&gt; primes = list_of(2)(3)(5)(7)(11); const stack&lt;string&gt; names = list_of( "Mr. Foo" )( "Mr. Bar") ( "Mrs. FooBar" ).to_adapter(); map&lt;int,int&gt; next = map_list_of(1,2)(2,3)(3,4)(4,5)(5,6); // or we can use 'list_of()' by specifying what type // the list consists of next = list_of&lt; pair&lt;int,int&gt; &gt;(6,7)(7,8)(8,9); } </code></pre> <p>There are also functions for <code>repeat()</code>, <code>repeat_fun()</code>, and <code>range()</code> which allows you to add repeating values or ranges of values.</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