<bdo id='E7IHu'></bdo><ul id='E7IHu'></ul>
<tfoot id='E7IHu'></tfoot>
  • <small id='E7IHu'></small><noframes id='E7IHu'>

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

      1. stl::multimap - 如何获取数据组?

        stl::multimap - how do i get groups of data?(stl::multimap - 如何获取数据组?)
          <tbody id='iE8Sv'></tbody>

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

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

                  本文介绍了stl::multimap - 如何获取数据组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Multimap 本质上具有按键排序的数据组.我想要一种方法,通过它我可以访问这些单独的组并获取它们的聚合值.例如,在 std::multimapstring, int > 我存储的

                  Multimap essentially has groups of data sorted by the key. I want a method by which I could access these individual groups and get their aggregate values. For example, in a std::multimap< string, int > I store

                  {"Group1", 1}, 
                  {"Group1", 2}, 
                  {"Group1", 3}, 
                  
                  {"Group2", 10}, 
                  {"Group2", 11}, 
                  {"Group2", 12}
                  

                  存储这些值后,我应该能够迭代这个多重映射并获得每个组"的聚合值.问题是 STL 中没有定义任何函数来以这种方式访问 MultiMap.我可以使用 lower_boundupper_bound 手动迭代多图并汇总组的内容,但我希望 STL 中已经定义了更好的方法?任何人都可以提出一个解决方案,说明我如何在上面的例子中获得一个组的聚合值.

                  Having stored these values, I should be able to iterate this multimap and get the aggregate values of each "group". Problem is there aren't any functions defined in STL to access MultiMaps in such a way. I could use lower_bound, upper_bound to manually iterate the multimap and total the group's contents, but I am hoping there could be better ways already defined in STL ? Can anyone propose a solution as to how I could get the aggregate values for a group in the above example.

                  推荐答案

                  pair<Iter, Iter> range = my_multimap.equal_range("Group1");
                  int total = accumulate(range.first, range.second, 0);
                  

                  是一种方式.

                  如果您不知道要查找的组,而只是浏览每个组,则可以像这样获取下一组的范围:

                  If you don't know the group you are looking for, and are just going through each group, getting the next group's range can be done like so:

                  template <typename Pair>
                  struct Less : public std::binary_function<Pair, Pair, bool>
                  {
                      bool operator()(const Pair &x, const Pair &y) const
                      {
                          return x.first < y.first;
                      }
                  };
                  
                  Iter first = mmap.begin();
                  Iter last = adjacent_find(first, mmap.end(), Less<MultimapType::value_type>());
                  

                  这篇关于stl::multimap - 如何获取数据组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 与自定义类对象的向量一起使用?)

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

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

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