我可以将定义的 std::map/typedef 作为模板传递吗?

问题描述 投票:0回答:0

这是我的实际代码:

struct BiquadFilterType : ParamQuantity {
    std::string getDisplayValueString() override {
        float value = getDisplayValue();

        return getDropDownLabel(gBiquadFilterDropDownDictionary, (int)std::round(value));
    }
    void setDisplayValueString(std::string s) override {
        float value = getDropDownValue(gBiquadFilterDropDownDictionary, s);

        setDisplayValue(value);
    }
};

typedef std::map<int, std::array<std::string, 2>> DropDownDictionary;
const DropDownDictionary gBiquadFilterDropDownDictionary{
    {BiquadFilterType::OFF, {"-", "Off"}},
    {BiquadFilterType::LOW_PASS, {"LP", "Low Pass"}},
    {BiquadFilterType::HIGH_PASS, {"HP", "High Pass"}},
    {BiquadFilterType::BAND_PASS, {"BP", "Band Pass"}},
    {BiquadFilterType::NOTCH, {"NT", "Notch"}},
    {BiquadFilterType::PEAK, {"PK", "Peak"}},
    {BiquadFilterType::LOW_SHELF, {"LS", "Low Shelf"}},
    {BiquadFilterType::HIGH_SHELF, {"HS", "High Shelf"}},
    {BiquadFilterType::ALL_PASS, {"AP", "All Pass"}}};

我想让这段代码更通用,所以“通过”任何类型的

typedef std::map<int, std::array<std::string, 2>>
都应该有效。

当然我不能将它作为方法参数“传递”,因为函数正在被覆盖,因此无法编辑。

在这种情况下可以使用模板做同样的事情吗?例如

getDropDownValue(T, s)
getDropDownValue(T, s);

c++ c++11 templates typedef
© www.soinside.com 2019 - 2024. All rights reserved.