Reputation: 1
template<typename K, typename V, int N>
class KVList
{
int m_size;
K m_key[N] = {};
V m_value[N] = {};
public:
KVList& add(const K&, const V&)
{
//Check if index is empty or null
//Add key value pair
}
}
Hey guys,
I'm creating a templated class that has 3 template parameters. My question, as stated above, is how I can determine whether or not an array at certain indexes is NULL or has no user-defined value.
Currently passing these datatypes as template arguments:
w4::KVList<std::string, double, 5> x;
w4::KVList<std::string, std::string, 5> y;
I was thinking maybe something along the lines of type conversions to bool might help but I'm stuck.
How can I check if the index has a null value for occurrences KVList
accepts different datatypes or classes than the ones specified above?
Upvotes: 0
Views: 218
Reputation: 66200
I want to know whether or not the array index is not user-defined so I can add values at the index.
You could add a third C-style array of bool
's
bool isSet[N] = {};
and set/unset the values when keys and values are set/unset.
Upvotes: 1