问题标签 [std-pair]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
1414 浏览

c++ - 用一对索引 STL 映射是个好主意吗?

我只是想知道制作一个像这样的数据结构是否是个好主意

只是想知道如何在内部订购这些对......:S

谢谢!

0 投票
11 回答
152165 浏览

c++ - 在地图元素上使用 for_each

我有一张地图,我想在其中对每个数据类型对象成员函数执行调用。我还知道如何在任何序列上执行此操作,但是是否可以在关联容器上执行此操作?

我能找到的最接近的答案是:Boost.Bind to access std::map elements in std::for_each。但是我不能在我的项目中使用 boost 那么,是否有我缺少的 STL 替代方案来 boost::bind?

如果不可能,我想为指向数据对象的指针创建一个临时序列,然后在其上调用 for_each,如下所示:

它看起来太模糊了,我真的不喜欢它。有什么建议么?

0 投票
2 回答
7805 浏览

c++ - 如何使用绑定创建基于 ::second 对成员排序的 std::pair 集合

我知道我可以使用以下内容:

但想知道是否可以使用 boost::bind 来完成

0 投票
2 回答
896 浏览

c++ - c++ Sorting a vector based on values of other vector, or what's faster?

There are a couple of other posts about sorting a vector A based on values in another vector B. Most of the other answers tell to create a struct or a class to combine the values into one object and use std::sort.

Though I'm curious about the performance of such solutions as I need to optimize code which implements bubble sort to sort these two vectors. I'm thinking to use a vector<pair<int,int>> and sort that.

I'm working on a blob-tracking application (image analysis) where I try to match previously tracked blobs against newly detected blobs in video frames where I check each of the frames against a couple of previously tracked frames and of course the blobs I found in previous frames. I'm doing this at 60 times per second (speed of my webcam).

Any advice on optimizing this is appreciated. The code I'm trying to optimize can be shown here:

http://code.google.com/p/projectknave/source/browse/trunk/knaveAddons/ofxBlobTracker/ofCvBlobTracker.cpp?spec=svn313&r=313

important: I forgot to mention that the size of the vectors will never be bigger than 5, and mostly have only 3 items in it and will be unsorted (maybe I could even hardcode it for 3 items?)

Thanks

0 投票
1 回答
3060 浏览

c++ - 包含对的多图?

多图是否可以包含在它的对中?IE,而不是被定义multimap<char,int>为例如,它将被定义为multimap<pair, pair>?

然后如何对这个多图进行排序?另外,如何访问每一对的单独内容?

0 投票
4 回答
727 浏览

c++ - c++ 对模板结构声明歧义!

在 C++ 中对类的定义中有两个 typedef。它们是干什么用的?代码中没有使用它们!

0 投票
6 回答
79711 浏览

c++ - 在映射中使用对作为键 (C++ / STL)

我想使用 STL 中的一对作为地图的键。

但是编译器会抛出一堆不可读的信息,而且我对 C 和 C++ 很陌生。

如何在地图中使用一对作为键?一般来说,我如何使用任何类型的结构(对象、结构等)作为地图中的键?

谢谢!

0 投票
3 回答
886 浏览

c++ - 将整数转换为 std::pair 接受的 std::string

我有一个将整数转换为 std::string 的函数:

到目前为止它运行良好,但现在我正在尝试构造一个字符串以放入 std::pair,但我遇到了一些麻烦。

给定一个整数变量hp和一个返回整数的函数int maxHP(),我想构造一个如下所示的字符串:("5/10"如果hp为 5 并maxHP返回 10)。

这是我的尝试:

使用 g++ 编译失败,出现以下错误:

所以 std::pair 不喜欢我的字符串。我已经确认它不会OtherType导致问题,因为我有另一个编译好的对构造函数:

任何人都知道我该如何解决这个问题?


修复了它,尽管答案很奇怪。我的问题是,不知何故,比率没有得到定义,但 g++ 没有告诉我这件事。更改我的代码以make_pair按照 GMan 的建议使用,这突然让我知道了。有谁知道为什么会这样?

这里有更多的功能:

这是固定代码:

0 投票
8 回答
65605 浏览

c++ - 在 C++ 中将变量名转换为字符串

我想将一些数据输出到文件中。例如假设我有两个双精度向量:

有没有一种简单的方法可以将其输出到文件中,以便第一行包含标题“data1”和“data2”,然后是实际内容。输出数据的函数将传递各种不同的数组,因此无法对标题名称进行硬编码 - 理想情况下,我想将变量名称转换为某个字符串,然后输出该字符串,然后输出向量数组的内容。但是,我不确定如何将变量名 'data1' 转换为字符串,或者确实可以轻松完成(从阅读论坛我的猜测是它不能)如果这不可能,则可能是替代方案使用关联容器,例如 map 或更简单的“对”容器。

欢迎大家提出意见!

0 投票
7 回答
69305 浏览

c++ - std::list 和有什么区别和 C++ STL 中的 std::map ?

std::list<std::pair>和 和有什么不一样std::map?列表也有find方法吗?