Note that there are some explanatory texts on larger screens.

plurals
  1. POstd::map lower_bound is not returning the correct value
    primarykey
    data
    text
    <p>Good afternoon, I am trying to use the std::map lower_found member function. However , it keeps returning the wrong answer. Here is an excerpt of my test code. Please explain to me how to make std::map lower bound function properly. Thank you.</p> <pre><code>class Interval { public: explicit Interval(int item){ mLow = item; mHigh = item; mStamp = 0; } Interval(int low, int high, int stamp = 0){ mLow = low; mHigh = high; mStamp = stamp; } Interval(void){ mLow = 0; mHigh = 0; mStamp = 0; } Interval(const Interval&amp; r): mLow(r.mLow), mHigh(r.mHigh), mStamp(r.mStamp) { } bool operator&lt;(const Interval&amp; rhs) const{ if (mLow &lt; rhs.mLow){ return true; } return false; } // operator&lt; int low() const { return mLow; } int high() const { return mHigh; } int getStamp() const { return mStamp; } void setLow(int lower) { mLow = lower; } void setHigh(int higher) { mHigh = higher; } void setStamp(int stamp) { mStamp = stamp; } private: int mLow; int mHigh; int mStamp; }; // class Interval int main(int Argc_,char *Argv_[]) { int n; Interval r; std::map&lt;Interval, Interval&gt; Intervals_type; r.setLow(0); r.setHigh(10); r.setStamp(1); std::pair&lt; Interval, Interval &gt; tmp(r,r); Intervals_type.insert(tmp); r.setLow(10); r.setHigh(20); r.setStamp(2); std::pair&lt; Interval, Interval &gt; tmp2(r,r); Intervals_type.insert(tmp2); r.setLow(20); r.setHigh(30); r.setStamp(3); std::pair&lt; Interval, Interval &gt; tmp3(r,r); Intervals_type.insert(tmp3); r.setLow(30); r.setHigh(40); r.setStamp(4); std::pair&lt; Interval, Interval &gt; tmp4(r,r); Intervals_type.insert(tmp4); n = 36; std::map&lt;Interval, Interval&gt;::const_iterator it = Intervals_type.lower_bound(Interval(n)); if (it == Intervals_type.end()){ printf(" n = %d not found\n",n); } return 1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload