gpt4 book ai didi

c++ - 如何让 : map>?

转载 作者:太空狗 更新时间:2023-10-29 21:23:17 25 4
gpt4 key购买 nike

我需要一个 map,它的键是某种复合类型 Tmap 本身的迭代器的 vector 。
(例如,想象一个图,其中每个节点都包含指向其父节点的迭代器。)

我避免将 parent 的存储为值的原因是键是昂贵的对象,所以我想改为存储迭代器。

这样的事情可能吗?
如果没有,最好的选择是什么?

(我知道我可以使用多态性和类型删除作为一种强力方法来解决这个问题,但我想知道是否有更好的方法。)

最佳答案

由于 23.2.1 一般容器要求:

Containers are objects that store other objects. They control allocation
and deallocation of these objects through constructors, destructors,
insert and erase operations.

因此有可能:

struct Key;
struct Value;
typedef std::map<Key, Value> Map;

struct Key {};
struct Value {
std::vector<Map::iterator> parents;
};

(所有类型和尺寸都是已知的)

关于c++ - 如何让 : map<T, vector<iterator to map itself>>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18609977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com