Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • how to create a test function and define a property when using std::map in c++?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 341
    Answer it

    Hi Team

    i am struggling to implement two things on this class,

     

    1) to define a property when creating a modifier for using std::map<K, V> that one K is an int and V string.

    2).how to create a test function inside a class?

    - this class must first get a property being define first and declared using this standard library std::find, map<K, V>

    -how to implement assign void method using a loop?

    -the assign void method must be called from the test function, in order to check all test functions are met within a class and be able to compile without any errors.

     

    // Attempt from the code

    #include <map>
    template<typename K, typename V>
    class interval_map {
    	friend void IntervalMapTest();
    	V m_valBegin;
    	std::map<K,V> m_map;
    public:
    	// constructor associates whole range of K with val
    	interval_map(V const& val)
    	: m_valBegin(val)
    	{}
    
    	// Assign value val to interval [keyBegin, keyEnd).
    	// Overwrite previous values in this interval.
    	// Conforming to the C++ Standard Library conventions, the interval
    	// includes keyBegin, but excludes keyEnd.
    	// If !( keyBegin < keyEnd ), this designates an empty interval,
    	// and assign must do nothing.
    	void assign( K const& keyBegin, K const& keyEnd, V const& val ) {
    	}
    
    	// look-up of the value associated with key
    	V const& operator[]( K const& key ) const {
    		auto it=m_map.upper_bound(key);
    		if(it==m_map.begin()) {
    			return m_valBegin;
    		} else {
    			return (--it)->second;
    		}
    	}
    };

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: