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

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

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

      1. std::tuple get() 成员函数

        时间:2023-07-20

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

              <tbody id='xSYJA'></tbody>

          1. <legend id='xSYJA'><style id='xSYJA'><dir id='xSYJA'><q id='xSYJA'></q></dir></style></legend>

            • <bdo id='xSYJA'></bdo><ul id='xSYJA'></ul>

                  <i id='xSYJA'><tr id='xSYJA'><dt id='xSYJA'><q id='xSYJA'><span id='xSYJA'><b id='xSYJA'><form id='xSYJA'><ins id='xSYJA'></ins><ul id='xSYJA'></ul><sub id='xSYJA'></sub></form><legend id='xSYJA'></legend><bdo id='xSYJA'><pre id='xSYJA'><center id='xSYJA'></center></pre></bdo></b><th id='xSYJA'></th></span></q></dt></tr></i><div id='xSYJA'><tfoot id='xSYJA'></tfoot><dl id='xSYJA'><fieldset id='xSYJA'></fieldset></dl></div>
                  <tfoot id='xSYJA'></tfoot>
                • 本文介绍了std::tuple get() 成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  boost::tuple 有一个 get() 成员函数,像这样使用:

                  boost::tuple has a get() member function used like this:

                  tuple<int, string, string> t(5, "foo", "bar");
                  cout << t.get<1>();  // outputs "foo"
                  

                  似乎C++0x std::tuple 没有这个成员函数,你必须改用非成员函数形式:

                  It seems the C++0x std::tuple does not have this member function, and you have to instead use the non-member function form:

                  std::get<1>(t);
                  

                  在我看来哪个更丑.

                  std::tuple 没有成员函数有什么特别的原因吗?还是只是我的实现(GCC 4.4)?

                  Is there any particular reason why std::tuple doesn't have the member function? Or is it just my implementation (GCC 4.4)?

                  推荐答案

                  来自 C++0x 草案:

                  From C++0x draft:

                  [ 注意:get 是非成员函数的原因是,如果此功能已作为成员函数提供,则类型依赖于模板参数的代码将需要使用模板关键字.— 尾注 ]

                  [ Note: The reason get is a nonmember function is that if this functionality had been provided as a member function, code where the type depended on a template parameter would have required using the template keyword. — end note ]

                  这可以用以下代码说明:

                  This can be illustrated with this code:

                  template <typename T>
                  struct test
                  {
                    T value;
                    template <int ignored>
                    T&  member_get ()
                    {  return value;  }
                  };
                  
                  template <int ignored, typename T>
                  T&  free_get (test <T>& x)
                  {  return x.value;  }
                  
                  template <typename T>
                  void
                  bar ()
                  {
                    test <T>  x;
                    x.template member_get <0> ();  // template is required here
                    free_get <0> (x);
                  };
                  

                  这篇关于std::tuple get() 成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 boost multi_index 数组中移动元素 下一篇:如何使用 Boost 扩展 .ini 文件中的环境变量

                  相关文章

                  <tfoot id='OQji5'></tfoot>

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

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

                  • <bdo id='OQji5'></bdo><ul id='OQji5'></ul>
                  <legend id='OQji5'><style id='OQji5'><dir id='OQji5'><q id='OQji5'></q></dir></style></legend>