<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数组

        how-to initialize #39;const std::vectorlt;Tgt;#39; like a c array(如何初始化“const std::vectorlt;Tgt;像一个c数组)
        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数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is the past-the-end iterator in STL C++?(STL C++ 中的最后迭代器是什么?)
                  vector::at vs. vector::operator[](vector::at 与 vector::operator[])
                  C++ equivalent of StringBuffer/StringBuilder?(C++ 等效于 StringBuffer/StringBuilder?)
                  Adding types to the std namespace(将类型添加到 std 命名空间)
                  Is the C++ std::set thread-safe?(C++ std::set 线程安全吗?)
                  How to use std::find/std::find_if with a vector of custom class objects?(如何将 std::find/std::find_if 与自定义类对象的向量一起使用?)
                • <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>

                      <tbody id='hUjj1'></tbody>

                  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>