【发布时间】:2022-01-25 10:57:16
【问题描述】:
我有以下类似于std::pair 的简单结构。我想将两个指针keys 和Values 转换为pair 的指针。我该怎么做?
谢谢!
K* keys;
V* Values;
/*
length of keys = length of Values
goal: operation(keys, Values) ---> pair*
*/
template <typename K, typename V, K EmptyKey = K(-1)> struct pair {
K first;
V second;
static constexpr auto empty_key = EmptyKey;
bool empty() { return first == empty_key; }
};
【问题讨论】:
-
由于内存布局不同(两个数组与一个交错数组),您需要将键/值复制到一个新数组中。
标签: c++ pointers templates key-value reinterpret-cast