I have a class with an std::variant
in it. This std::variant
type is only allowed to hold a specific list of types.
I have template functions which allow the user of the class to insert various values into an std::unordered_map
, the map holds values of this variant type. I.e., the user is only allowed to insert values if it's type is in the specific list of types. However, I don't want the user to be able to define this list of types themselves.
class GLCapabilities
{
public:
using VariantType = std::variant<GLint64>; // in future this would have other types
template <typename T>
std::enable_if_t<???> AddCapability(const GLenum parameterName)
{
if(m_capabilities.count(parameterName) == 0)
{
/*... get correct value of type T ... */
m_capabilities.insert(parameterName,value);
}
}
template<typename T>
std::enable_if_t<???,T> GetCapability(const GLenum parameterName) const
{
auto itr = m_capabilities.find(parameterName);
if(std::holds_alternative<T>(*itr))
return std::get<T>(*itr);
return T;
}
private:
std::unordered_map<GLenum,VariantType> m_capabilities;
};
You'll see in the above where there's the ???
, how can I check? Some combination of std::disjunction
with std::is_same
?
Like
std::enable_if<std::disjunction<std::is_same<T,/*Variant Types???*/>...>>
To make it clear, I'd prefer to not have to check against each allowed type manually.