<i id='vXyZc'><tr id='vXyZc'><dt id='vXyZc'><q id='vXyZc'><span id='vXyZc'><b id='vXyZc'><form id='vXyZc'><ins id='vXyZc'></ins><ul id='vXyZc'></ul><sub id='vXyZc'></sub></form><legend id='vXyZc'></legend><bdo id='vXyZc'><pre id='vXyZc'><center id='vXyZc'></center></pre></bdo></b><th id='vXyZc'></th></span></q></dt></tr></i><div id='vXyZc'><tfoot id='vXyZc'></tfoot><dl id='vXyZc'><fieldset id='vXyZc'></fieldset></dl></div>

    1. <legend id='vXyZc'><style id='vXyZc'><dir id='vXyZc'><q id='vXyZc'></q></dir></style></legend>
        <bdo id='vXyZc'></bdo><ul id='vXyZc'></ul>
      <tfoot id='vXyZc'></tfoot>

    2. <small id='vXyZc'></small><noframes id='vXyZc'>

        如何初始化“const std::vector&lt;T&gt;"像一个c数组

        时间:2024-05-12
        1. <small id='Ks50x'></small><noframes id='Ks50x'>

            <tbody id='Ks50x'></tbody>

        2. <legend id='Ks50x'><style id='Ks50x'><dir id='Ks50x'><q id='Ks50x'></q></dir></style></legend>
        3. <i id='Ks50x'><tr id='Ks50x'><dt id='Ks50x'><q id='Ks50x'><span id='Ks50x'><b id='Ks50x'><form id='Ks50x'><ins id='Ks50x'></ins><ul id='Ks50x'></ul><sub id='Ks50x'></sub></form><legend id='Ks50x'></legend><bdo id='Ks50x'><pre id='Ks50x'><center id='Ks50x'></center></pre></bdo></b><th id='Ks50x'></th></span></q></dt></tr></i><div id='Ks50x'><tfoot id='Ks50x'></tfoot><dl id='Ks50x'><fieldset id='Ks50x'></fieldset></dl></div>

              <tfoot id='Ks50x'></tfoot>

                • <bdo id='Ks50x'></bdo><ul id='Ks50x'></ul>
                  本文介绍了如何初始化“const std::vector&lt;T&gt;"像一个c数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Is there an elegant way to create and initialize a const std::vector<const T> like const T a[] = { ... } to a fixed (and small) number of values?
                  I need to call a function frequently which expects a vector<T>, but these values will never change in my case.

                  In principle I thought of something like

                  namespace {
                    const std::vector<const T> v(??);
                  }
                  

                  since v won't be used outside of this compilation unit.

                  解决方案

                  For C++11:

                  vector<int> luggage_combo = { 1, 2, 3, 4, 5 };
                  

                  Original answer:

                  You would either have to wait for C++0x or use something like Boost.Assign to do that.

                  e.g.:

                  #include <boost/assign/std/vector.hpp>
                  using namespace boost::assign; // bring 'operator+=()' into scope
                  
                  vector<int> v;
                  v += 1,2,3,4,5;
                  

                  这篇关于如何初始化“const std::vector&lt;T&gt;"像一个c数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C++ 异常:抛出 std::string 下一篇:hash_map 是 STL 的一部分吗?

                  相关文章

                • <legend id='hUjj1'><style id='hUjj1'><dir id='hUjj1'><q id='hUjj1'></q></dir></style></legend>
                • <small id='hUjj1'></small><noframes id='hUjj1'>

                  <tfoot id='hUjj1'></tfoot>

                  1. <i id='hUjj1'><tr id='hUjj1'><dt id='hUjj1'><q id='hUjj1'><span id='hUjj1'><b id='hUjj1'><form id='hUjj1'><ins id='hUjj1'></ins><ul id='hUjj1'></ul><sub id='hUjj1'></sub></form><legend id='hUjj1'></legend><bdo id='hUjj1'><pre id='hUjj1'><center id='hUjj1'></center></pre></bdo></b><th id='hUjj1'></th></span></q></dt></tr></i><div id='hUjj1'><tfoot id='hUjj1'></tfoot><dl id='hUjj1'><fieldset id='hUjj1'></fieldset></dl></div>
                      <bdo id='hUjj1'></bdo><ul id='hUjj1'></ul>