【发布时间】:2020-05-25 17:22:55
【问题描述】:
我正在实现我自己的两个无序映射,一个接受一个键,它是一个带有 3 个参数的元组,另一个是一个带有 2 个参数的元组。以下是我的代码:
#pragma once
#include <boost/functional/hash.hpp>
#include <unordered_map>
#include <tuple>
namespace Valk::ExchangeGateway::TupleMap
{
using boost::hash_value;
using boost::hash_combine;
template <typename T, typename U>
auto hashTuple = [](const std::tuple<T, U>& singleTuple) -> size_t
{
size_t seed{};
hash_combine(seed, hash_value(std::get<0>(singleTuple)));
hash_combine(seed, hash_value(std::get<1>(singleTuple)));
return seed;
};
template <typename T, typename U>
auto equalTuple = [](const std::tuple<T, U>& firstTuple, const std::tuple<T, U>& secondTuple) -> bool
{
return std::get<0>(firstTuple) == std::get<0>(secondTuple)
&& std::get<1>(firstTuple) == std::get<1>(secondTuple);
};
template <typename T, typename U, typename D>
auto hashTripleTuple = [](const std::tuple<T, U, D>& singleTuple) -> size_t
{
size_t seed{};
hash_combine(seed, hash_value(std::get<0>(singleTuple)));
hash_combine(seed, hash_value(std::get<1>(singleTuple)));
hash_combine(seed, hash_value(std::get<2>(singleTuple)));
return seed;
};
template <typename T, typename U, typename D>
auto equalTripleTuple =
[](const std::tuple<T, U, D>& firstTuple, const std::tuple<T, U, D>& secondTuple) -> bool
{
return std::get<0>(firstTuple) == std::get<0>(secondTuple)
&& std::get<1>(firstTuple) == std::get<1>(secondTuple)
&& std::get<2>(firstTuple) == std::get<2>(secondTuple);
};
using InstrumentFrequency = int;
using TotalDelta = double;
using FutureTupleUnorderedMap = std::unordered_map<std::tuple<TotalDelta, Instrument::InstrumentID, Platform::Price>,
InstrumentFrequency, decltype(hashTripleTuple<TotalDelta, Instrument::InstrumentID, Platform::Price>),
decltype(equalTripleTuple<TotalDelta, Instrument::InstrumentID, Platform::Price>)>;
using OptionTupleUnorderedMap = std::unordered_map<std::tuple<Platform::Quantity, Instrument::InstrumentID>,
InstrumentFrequency, decltype(hashTuple<Platform::Quantity, Instrument::InstrumentID>),
decltype(equalTuple<Platform::Quantity, Instrument::InstrumentID>)>;
}
您看到的所有 typedef,例如 Platform::Quantity 和 Platform::Price 都是原始类型的 typedef,例如 long long 或 int。
由于某种原因,我收到以下错误(屏幕截图比在此处复制和粘贴更容易),我不知道为什么。这里没有一个类的复制构造函数被删除或没有生成。
感谢您的帮助。
【问题讨论】:
-
您可以从“输出”选项卡复制完整的错误消息——包括来自编译器的附加信息。
-
是的。屏幕截图难以辨认,而不是“更容易”。此外,让它独立coliru.stacked-crooked.com/a/f1b89eb824406927 也没有什么坏处
标签: c++ boost unordered-map stdtuple