I’m working on optimization of some settings code. This is a large array of predefined values groupped in three nested structures. It is defined as
struct PerId
{
const Id m_Id;
const uint32_t m_Flags;
};
struct PerSeverity
{
const Severity m_Severity;
const std::vector<PerId> m_PerId;
};
struct PerTask
{
const Task m_Task;
const std::vector<PerSeverity> m_PerSeverity;
};
static const std::array rawSettingsPerTask
{
PerTask{
eTASK1,
{{Severity::Critical, {{Violated, 0x22}, {Expired, 0x33}}},
{Severity::Error, {{CantBeExecuted, 0x44}}}},
},
PerTask{
eTASK2,{....}
},
};
And I want to make this settings definition compile time. I made constexpr constructors to struct and moved from std::vector to std::array and now I have compilation issues, because of different template parameters:
template<std::size_t N>
struct PerSeverity
{
constexpr PerSeverity(Severity severity, const std::array<RawSettingsPerId, N>& perId)
: m_Severity(severity)
, m_PerId(perId)
{}
const Severity m_Severity;
const std::array<PerId, N> m_PerId;
};
template<std::size_t N, size_t M>
struct PerTask
{
constexpr PerTask(enTaskID component, const std::array<PerSeverity<M>, N>& perSeverity)
: m_Component(component)
, m_PerSeverity(perSeverity)
{}
const enTaskID m_Component;
const std::array<PerSeverity<M>, N> m_PerSeverity;
};
constexpr std::array rawSettingsPerComponent
{
RawSettingsPerComponent<1,2>{
eTASK1, { PerSeverity<2>{Critical, { PerId{Violated, 0x22},
PerId{Expired, 0x33}}}}
},
PerComponent<2,2>{
eTASK2 , { PerSeverity<2>{ Critical, { PerId{Violated, 0x11},
PerId{Expired, 0x22}}},
PerSeverity<1>{ Informational, { PerId{Violated, 0x44}}}}
}
}
So is it possible at all? May be I need some trick, but I can’t find some thing similar
1