<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) 中的(它的)迭代器类型获取容器类型

      时间:2024-08-14

    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) 中的(它的)迭代器类型获取容器类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:为什么 C++ 不能从赋值推导出模板类型? 下一篇:为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?

                相关文章

                • <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>

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

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