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

        <bdo id='XlB2M'></bdo><ul id='XlB2M'></ul>

        <small id='XlB2M'></small><noframes id='XlB2M'>

      1. <tfoot id='XlB2M'></tfoot>

        C++中向量的通用向量

        Generic vector of vectors in C++(C++中向量的通用向量)

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

            <tbody id='AU8Hu'></tbody>

                <bdo id='AU8Hu'></bdo><ul id='AU8Hu'></ul>

                <small id='AU8Hu'></small><noframes id='AU8Hu'>

                • <legend id='AU8Hu'><style id='AU8Hu'><dir id='AU8Hu'><q id='AU8Hu'></q></dir></style></legend>

                  <tfoot id='AU8Hu'></tfoot>
                  本文介绍了C++中向量的通用向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 C++ 中是否有一种好方法来实现(或伪造)通用向量向量的类型?

                  Is there a good way in C++ to implement (or fake) a type for a generic vector of vectors?

                  忽略向量向量何时是一个好主意的问题(除非有一些等效的东西总是更好).假设它确实准确地对问题建模,而矩阵不能准确地对问题建模.还假设将这些东西作为参数的模板化函数确实需要操作结构(例如调用 push_back),因此它们不能只采用支持 [][] 的泛型类型.

                  Ignore the issue of when a vector of vectors is a good idea (unless there's something equivalent which is always better). Assume that it does accurately model the problem, and that a matrix does not accurately model the problem. Assume also that templated functions taking these things as parameters do need to manipulate the structure (e.g. calling push_back), so they can't just take a generic type supporting [][].

                  我想做的是:

                  template<typename T>
                  typedef vector< vector<T> > vecvec;
                  
                  vecvec<int> intSequences;
                  vecvec<string> stringSequences;
                  

                  当然这是不可能的,因为 typedef 不能被模板化.

                  but of course that's not possible, since typedef can't be templated.

                  #define vecvec(T) vector< vector<T> >
                  

                  很接近,并且可以避免在对 vecvecs 进行操作的每个模板化函数中重复类型,但不会受到大多数 C++ 程序员的欢迎.

                  is close, and would save duplicating the type across every templated function which operates on vecvecs, but would not be popular with most C++ programmers.

                  推荐答案

                  您想要模板类型定义.目前的 C++ 尚不支持 .解决方法是做

                  You want to have template-typedefs. That is not yet supported in the current C++. A workaround is to do

                  template<typename T>
                  struct vecvec {
                       typedef std::vector< std::vector<T> > type;
                  };
                  
                  int main() {
                      vecvec<int>::type intSequences;
                      vecvec<std::string>::type stringSequences;
                  }
                  

                  在下一个 C++(由于 2010 年称为 c++0x、c++1x)中,这将是可能的:

                  In the next C++ (called c++0x, c++1x due to 2010), this would be possible:

                  template<typename T>
                  using vecvec = std::vector< std::vector<T> >;
                  

                  这篇关于C++中向量的通用向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  How should a size-limited stl-like container be implemented?(应该如何实现大小受限的 stl 类容器?)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)

                • <small id='wqL1n'></small><noframes id='wqL1n'>

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

                          <tbody id='wqL1n'></tbody>
                          <bdo id='wqL1n'></bdo><ul id='wqL1n'></ul>

                          <tfoot id='wqL1n'></tfoot>