Home How to determine whether an index of an array of unknown type is empty?
Reply: 1

How to determine whether an index of an array of unknown type is empty?

Schwiftyy Published in 2018-02-11 19:13:08Z
template<typename K, typename V, int N>
    class KVList
        int m_size;
        K m_key[N] = {};
        V m_value[N] = {};

        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?

max66 Reply to 2018-02-11 19:26:58Z

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.341282 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO