Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, in C++0x you can...</p> <p>In C++03, there is a paragraph 23.1[lib.containers.requirements]/3, which says</p> <blockquote> <p>The type of objects stored in these components must meet the requirements of <code>CopyConstructible</code> types (20.1.3), and the additional requirements of <code>Assignable</code> types.</p> </blockquote> <p>This is what's currently preventing you from using <code>const int</code> as a type argument to <code>std::vector</code>.</p> <p>However, in C++0x, this paragraph is missing, instead, <code>T</code> is required to be <a href="http://en.cppreference.com/w/cpp/concept/Destructible" rel="nofollow noreferrer"><code>Destructible</code></a> and additional requirements on <code>T</code> are specified per-expression, e.g. <code>v = u</code> on <code>std::vector</code> is only valid if <code>T</code> is <a href="http://en.cppreference.com/w/cpp/concept/MoveConstructible" rel="nofollow noreferrer"><code>MoveConstructible</code></a> and <a href="http://en.cppreference.com/w/cpp/concept/MoveAssignable" rel="nofollow noreferrer"><code>MoveAssignable</code></a>.</p> <p>If I interpret those requirements correctly, it should be possible to instantiate <code>std::vector&lt;const int&gt;</code>, you'll just be missing some of its functionality (which I guess is what you wanted). You can fill it by passing a pair of iterators to the constructor. I think <code>emplace_back()</code> should work as well, though I failed to find explicit requirements on <code>T</code> for it.</p> <p>You still won't be able to sort the vector in-place though.</p>
    singulars
    1. This table or related slice is empty.
    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