Using lower_bound() and upper_bound() to select records
<p>I have a map of objects, keyed by a date (stored as a double). I want to filter/extract the objects based on date, so I wrote a function similar to the snippet below.</p>

<p>However, I found that if I provide a date that is either lower than the earliest date, or greater than the last date, the code fails. I have modified the  code so that any input startdate that is lower than the first date is set to the first (i.e. lowest) date in the map, likewise, enddate  > last date is set to the last (greatest) date in the map</p>

<pre><code>void extractDataRecords(const DatedRecordset&amp; recs, OutStruct&amp; out, const double startdt, const double enddt)
{
    double first = recs.begin()-&gt;first, last = recs.rbegin()-&gt;first;
    const double sdate = (start &lt; first) ? first : startdt;
    const double edate = (enddt &gt; last) ? last : enddt;

    DatedRecordsetConstIter start_iter = recs.lower_bound(sdate), end_iter = recs.upper_bound(edate);

    if ((start_iter != recs.end()) &amp;&amp; (end_iter != recs.end()))
    {

        // do Something
    }
}
</code></pre>

<p>Is this the correct way to achieve this behaviour?</p>
