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

        <legend id='REIgq'><style id='REIgq'><dir id='REIgq'><q id='REIgq'></q></dir></style></legend>

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

        <tfoot id='REIgq'></tfoot>

        为什么在 C++11 或 C++14 中没有定位迭代器?

        Why no emplacement iterators in C++11 or C++14?(为什么在 C++11 或 C++14 中没有定位迭代器?)
      1. <i id='wEDzW'><tr id='wEDzW'><dt id='wEDzW'><q id='wEDzW'><span id='wEDzW'><b id='wEDzW'><form id='wEDzW'><ins id='wEDzW'></ins><ul id='wEDzW'></ul><sub id='wEDzW'></sub></form><legend id='wEDzW'></legend><bdo id='wEDzW'><pre id='wEDzW'><center id='wEDzW'></center></pre></bdo></b><th id='wEDzW'></th></span></q></dt></tr></i><div id='wEDzW'><tfoot id='wEDzW'></tfoot><dl id='wEDzW'><fieldset id='wEDzW'></fieldset></dl></div>
          <tbody id='wEDzW'></tbody>

            <bdo id='wEDzW'></bdo><ul id='wEDzW'></ul>
          • <small id='wEDzW'></small><noframes id='wEDzW'>

          • <legend id='wEDzW'><style id='wEDzW'><dir id='wEDzW'><q id='wEDzW'></q></dir></style></legend>
            • <tfoot id='wEDzW'></tfoot>

                  本文介绍了为什么在 C++11 或 C++14 中没有定位迭代器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  C++98 有 front_inserterback_inserterinserter,但在C++11 或 C++14 草案.是否有任何技术原因我们不能拥有 front_emplacerback_emplaceremplacer?

                  C++98 has front_inserter, back_inserter, and inserter, but there don't seem to be any emplacement versions of these in C++11 or draft C++14. Is there any technical reason we couldn't have front_emplacer, back_emplacer, and emplacer?

                  推荐答案

                  是否有任何技术原因我们不能拥有 front_emplacer、back_emplacer 和 emplacer?

                  Is there any technical reason we couldn't have front_emplacer, back_emplacer, and emplacer?

                  不,没有技术原因.作为证明,这里是 back_emplacer 的完整实现以及您的用例 1 的演示...

                  No, there is no technical reason. As proof, here is a complete implementation of back_emplacer with a demo of your Use Case 1...

                  #include <iterator>
                  #include <vector>
                  #include <iostream>
                  
                  template<class Container>
                  class back_emplace_iterator : public std::iterator< std::output_iterator_tag,
                                                                     void, void, void, void >
                  {
                  protected:
                      Container* container;
                  public:
                      typedef Container container_type;
                  
                      explicit back_emplace_iterator(Container& x) : container(&x) {}
                  
                      template<class T>
                      back_emplace_iterator<Container>&
                      operator=(T&& t)
                      {
                          container->emplace_back(std::forward<T>(t));
                          return *this;
                      }
                  
                      back_emplace_iterator& operator*() { return *this; }
                      back_emplace_iterator& operator++() { return *this; }
                      back_emplace_iterator& operator++(int) { return *this; }
                  };
                  
                  template< class Container >
                  inline back_emplace_iterator<Container>
                  back_emplacer( Container& c )
                  {
                      return back_emplace_iterator<Container>(c);
                  }
                  
                  struct Demo
                  {
                      int i;
                      Demo(int i) : i(i) {}
                  };
                  
                  int main()
                  {
                      std::vector<int> x = {1,2,3,4,5};
                  
                      std::vector<Demo> y;
                  
                      std::copy(x.begin(), x.end(), back_emplacer(y));
                  
                      for (auto d : y)
                          std::cout << d.i << std::endl;
                  }
                  

                  可能的已知问题:operator= 的通用引用是否隐藏了隐式生成的复制/移动 operator=?如果是这样,则需要以在重载解析中击败通用引用的方式明确定义这些.

                  Possible Known Issue: Does the universal reference of operator= hide an implicitly generated copy/move operator=? If so these need to be explicitly defined in a way that beats the universal reference in overload resolution.

                  这篇关于为什么在 C++11 或 C++14 中没有定位迭代器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

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

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

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

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

                            <tfoot id='WX2PT'></tfoot>
                            <legend id='WX2PT'><style id='WX2PT'><dir id='WX2PT'><q id='WX2PT'></q></dir></style></legend>