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

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

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

      1. 为什么在 C++11 中使用非成员开始和结束函数?

        Why use non-member begin and end functions in C++11?(为什么在 C++11 中使用非成员开始和结束函数?)
      2. <legend id='TLpNi'><style id='TLpNi'><dir id='TLpNi'><q id='TLpNi'></q></dir></style></legend>
      3. <i id='TLpNi'><tr id='TLpNi'><dt id='TLpNi'><q id='TLpNi'><span id='TLpNi'><b id='TLpNi'><form id='TLpNi'><ins id='TLpNi'></ins><ul id='TLpNi'></ul><sub id='TLpNi'></sub></form><legend id='TLpNi'></legend><bdo id='TLpNi'><pre id='TLpNi'><center id='TLpNi'></center></pre></bdo></b><th id='TLpNi'></th></span></q></dt></tr></i><div id='TLpNi'><tfoot id='TLpNi'></tfoot><dl id='TLpNi'><fieldset id='TLpNi'></fieldset></dl></div>

                  <tbody id='TLpNi'></tbody>
              • <tfoot id='TLpNi'></tfoot>

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

                  <bdo id='TLpNi'></bdo><ul id='TLpNi'></ul>
                  本文介绍了为什么在 C++11 中使用非成员开始和结束函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  每个标准容器都有一个 beginend 方法,用于返回该容器的迭代器.但是,C++11 显然引入了名为 std::beginstd::end 调用 beginend 成员函数.所以,而不是写

                  Every standard container has a begin and end method for returning iterators for that container. However, C++11 has apparently introduced free functions called std::begin and std::end which call the begin and end member functions. So, instead of writing

                  auto i = v.begin();
                  auto e = v.end();
                  

                  你会写

                  auto i = std::begin(v);
                  auto e = std::end(v);
                  

                  在编写现代 C++ 的演讲中,Herb Sutter 说当您想要容器的开始或结束迭代器时,您现在应该始终使用自由函数.但是,他没有详细说明为什么你会想要.查看代码,它为您节省了一个字符.因此,就标准容器而言,免费功能似乎完全无用.Herb Sutter 表示非标准容器有好处,但同样,他没有详细说明.

                  In his talk, Writing Modern C++, Herb Sutter says that you should always use the free functions now when you want the begin or end iterator for a container. However, he does not go into detail as to why you would want to. Looking at the code, it saves you all of one character. So, as far as the standard containers go, the free functions seem to be completely useless. Herb Sutter indicated that there were benefits for non-standard containers, but again, he didn't go into detail.

                  那么,问题是 std::beginstd::end 的自由函数版本除了调用它们对应的成员函数版本之外究竟做了什么,以及为什么你想使用它们吗?

                  So, the question is what exactly do the free function versions of std::begin and std::end do beyond calling their corresponding member function versions, and why would you want to use them?

                  推荐答案

                  你如何在 C 数组上调用 .begin().end() ?

                  How do you call .begin() and .end() on a C-array ?

                  自由函数允许更通用的编程,因为它们可以在之后添加到您无法更改的数据结构上.

                  Free-functions allow for more generic programming because they can be added afterwards, on a data-structure you cannot alter.

                  这篇关于为什么在 C++11 中使用非成员开始和结束函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 与自定义类对象的向量一起使用?)
                    <tbody id='W0KuB'></tbody>
                  <legend id='W0KuB'><style id='W0KuB'><dir id='W0KuB'><q id='W0KuB'></q></dir></style></legend>

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

                        1. <small id='W0KuB'></small><noframes id='W0KuB'>

                          <tfoot id='W0KuB'></tfoot>