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

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

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

      从 C++ (STL) 中的(它的)迭代器类型获取容器类型

      Obtain container type from (its) iterator type in C++ (STL)(从 C++ (STL) 中的(它的)迭代器类型获取容器类型)

    2. <tfoot id='42Jae'></tfoot>
        <bdo id='42Jae'></bdo><ul id='42Jae'></ul>
          <tbody id='42Jae'></tbody>

        <small id='42Jae'></small><noframes id='42Jae'>

            <legend id='42Jae'><style id='42Jae'><dir id='42Jae'><q id='42Jae'></q></dir></style></legend>

            <i id='42Jae'><tr id='42Jae'><dt id='42Jae'><q id='42Jae'><span id='42Jae'><b id='42Jae'><form id='42Jae'><ins id='42Jae'></ins><ul id='42Jae'></ul><sub id='42Jae'></sub></form><legend id='42Jae'></legend><bdo id='42Jae'><pre id='42Jae'><center id='42Jae'></center></pre></bdo></b><th id='42Jae'></th></span></q></dt></tr></i><div id='42Jae'><tfoot id='42Jae'></tfoot><dl id='42Jae'><fieldset id='42Jae'></fieldset></dl></div>
              • 本文介绍了从 C++ (STL) 中的(它的)迭代器类型获取容器类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                给定一个容器来获取相关的迭代器很容易,例如:

                It is easy given a container to get the associated iterators, example:

                std::vector<double>::iterator i; //An iterator to a std::vector<double>
                

                我想知道是否有可能,给定一个迭代器类型,推导出对应容器"的类型(这里我假设每个容器只有一个(非常量)迭代器).

                I was wondering if it is possible, given an iterator type, to deduce the type of the "corresponding container" (here I am assuming that for each container there is one and only one (non-const) iterator).

                更准确地说,我想要一个适用于所有 STL 容器的模板元函数(无需为每个容器手动专门化它),例如:

                More precisely, I would like a template metafunction that works with all STL containers (without having to specialize it manually for each single container) such that, for example:

                ContainerOf< std::vector<double>::iterator >::type 
                

                评估为

                std::vector<double>
                

                有可能吗?如果没有,为什么?

                Is it possible? If not, why?

                在此先感谢您的帮助!

                推荐答案

                我认为这不可能.在某些 STL 库中,您实际上有一个向量迭代器作为指针类型,即std::vector<T>::iterator 是一个 T* 所以我想不出有什么方法可以让你从那里回到容器类型.

                I don't think this would be possible. On some STL libraries you actually have a vector iterator as a pointer type, i.e. std::vector<T>::iterator is a T* so I can't think of any way you could get back to the container type from that.

                这篇关于从 C++ (STL) 中的(它的)迭代器类型获取容器类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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 中将列表元素移动到末尾)

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

                        <tbody id='86Ae6'></tbody>

                          <small id='86Ae6'></small><noframes id='86Ae6'>

                          <legend id='86Ae6'><style id='86Ae6'><dir id='86Ae6'><q id='86Ae6'></q></dir></style></legend>