Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 480.9k

Assign value to interval on void assign method using C++?

Sep 6 2022 1:23 PM

Hi Team

 

I need some help on my following logic that must implement on void assign method.  On this method void assign, must do 

#include
template
class interval_map {friend void IntervalMapTest();V m_valBegin;std::map m_map;
public:// constructor associates whole range of K with valinterval_map(V const& val): m_valBegin(val){}void assign( K const& keyBegin, K const& keyEnd, V const& 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}
// look-up of the value associated with keyV 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;}}
};}