本文整理汇总了C++中std::map::upper_bound方法的典型用法代码示例。如果您正苦于以下问题:C++ map::upper_bound方法的具体用法?C++ map::upper_bound怎么用?C++ map::upper_bound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::map
的用法示例。
在下文中一共展示了map::upper_bound方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: temp
seconds seti_time::ut1_utc_diff() const {
// UT1 and UTC drift from each other, but are brought closer together when
// leap seconds are added. They are never more than a second apart.
if (ut1_utc_conv.size() == 0) {
read_time_conversions();
}
seti_time temp(*this);
temp.base(UTC);
// need to be sure we never extrapolate across a leap second.
std::map<seti_time,seconds>::iterator i(ut1_utc_conv.upper_bound(temp)),j;
j=i;
j--;
std::pair<seti_time,seconds> lower(*j), upper;
if (i!=ut1_utc_conv.end()) {
upper=*i;
if (upper.second > (lower.second+seconds(0.95))) {
upper.second-=seconds(1.0); // the upper point is on the wrong side of a leap
// second.
}
} else {
upper=lower;
j--;
lower=*j;
if (upper.second > (lower.second+seconds(0.95))) {
lower.second+=seconds(1.0); // the lower point is on the wrong side of a leap
// second
}
}
// now interpolate between the two points.
seconds diff(
(upper.second-lower.second)*((temp-lower.first)/(upper.first-lower.first))
);
return diff;
}
示例2: assign
// Assign value val to interval [keyBegin, keyEnd).
// Overwrite previous values in this interval.
// Do not change values outside 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, const V& val) {
using iter_t = std::map<K, V>::const_iterator;
if (!(keyBegin < keyEnd))
return;
const iter_t lower_bound = map_.lower_bound(keyBegin);
const iter_t upper_bound = map_.upper_bound(keyEnd);
const iter_t prev = std::prev(lower_bound);
const iter_t next = std::prev(upper_bound);
// erase elements in range [lower_bound, upper_bound)
map_.erase(lower_bound, upper_bound);
if (!(prev->second == val)) {
// set new value at the beginning of the range
map_.insert(upper_bound, std::make_pair(keyBegin, val));
}
if (!(next->second == val)) {
// set next value at the end of the range
map_.insert(upper_bound, std::make_pair(keyEnd, next->second));
}
}
示例3: tai_utc_diff
seconds seti_time::tai_utc_diff() const {
// before 1972 TAI and UTC drifted freely. After 1972 the difference
// is defined to be the cumulative number of leap seconds.
if (tai_utc_conv.size() == 0) {
read_time_conversions();
}
seti_time temp(*this);
temp.base(UTC);
// find the time conversion prior to this time.
std::map<seti_time,tai_conv>::iterator i(tai_utc_conv.upper_bound(temp));
i--;
tai_conv conv(i->second);
seconds diff(conv.a0+(temp.mjd().uval()-conv.d0)*conv.a1);
return diff;
}
示例4: ComputeOldXY
void vstUndoRadialDistortion::ComputeOldXY(double xn, double yn, double& xo, double& yo) const
{
double rn = sqrt((xn*xn) + (yn*yn)); //// r is r squared
map<double, double>::const_iterator next = lookup_.upper_bound(rn);
map<double, double>::const_iterator prev = next; prev--;
// The compiler will optimise this.
double a = (*prev).first;
double b = (*next).first;
double c = rn;
double d = (*prev).second;
double e = (*next).second;
double f = ((e-d)/(b-a))*(c-a) + d;
xo = f*xn;
yo = f*yn;
}
示例5: find_containing_block
heap_block_iterator find_containing_block ( const void *p )
{
heap_block_iterator it ( m_heap_blocks.upper_bound ( ( void * ) p ) );
if ( it != m_heap_blocks.begin() )
{
--it;
if ( p < it->second.end() )
{
assert ( p >= it->second.p );
// p is inside this heap block.
return it;
}
}
return m_heap_blocks.end();
}
示例6: findUnwindRelocNameAddend
/// Given a relocation from __compact_unwind, consisting of the RelocationRef
/// and data being relocated, determine the best base Name and Addend to use for
/// display purposes.
///
/// 1. An Extern relocation will directly reference a symbol (and the data is
/// then already an addend), so use that.
/// 2. Otherwise the data is an offset in the object file's layout; try to find
// a symbol before it in the same section, and use the offset from there.
/// 3. Finally, if all that fails, fall back to an offset from the start of the
/// referenced section.
static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
std::map<uint64_t, SymbolRef> &Symbols,
const RelocationRef &Reloc,
uint64_t Addr,
StringRef &Name, uint64_t &Addend) {
if (Reloc.getSymbol() != Obj->symbol_end()) {
Reloc.getSymbol()->getName(Name);
Addend = Addr;
return;
}
auto RE = Obj->getRelocation(Reloc.getRawDataRefImpl());
SectionRef RelocSection = Obj->getRelocationSection(RE);
uint64_t SectionAddr;
RelocSection.getAddress(SectionAddr);
auto Sym = Symbols.upper_bound(Addr);
if (Sym == Symbols.begin()) {
// The first symbol in the object is after this reference, the best we can
// do is section-relative notation.
RelocSection.getName(Name);
Addend = Addr - SectionAddr;
return;
}
// Go back one so that SymbolAddress <= Addr.
--Sym;
section_iterator SymSection = Obj->section_end();
Sym->second.getSection(SymSection);
if (RelocSection == *SymSection) {
// There's a valid symbol in the same section before this reference.
Sym->second.getName(Name);
Addend = Addr - Sym->first;
return;
}
// There is a symbol before this reference, but it's in a different
// section. Probably not helpful to mention it, so use the section name.
RelocSection.getName(Name);
Addend = Addr - SectionAddr;
}
示例7: while
std::string
toRoman(uint32_t number)
{
static std::map<uint32_t, std::string> alphabet =
{
{1000, "M" }, { 900, "CM" }, { 500, "D" }, { 400, "CD" },
{ 100, "C" }, { 90, "XC" }, { 50, "L" }, { 40, "XL" },
{ 10, "X" }, { 9, "IX" }, { 5, "V" }, { 4, "IV" },
{ 1, "I" }, { 0, "" }
};
std::string result;
while (number > 0)
{
auto digit = *(--alphabet.upper_bound(number));
result += digit.second;
number -= digit.first;
}
return result;
}
示例8: return
V const& operator[](K const& key) const {
return ( --m_map.upper_bound(key))->second;
}
示例9: Key
UTF16String *CreateValue(const wchar_t *pwszName){
xKey Key(pwszName, std::wcslen(pwszName));
const auto iterHint = xm_mapValues.upper_bound(Key);
return &(xm_mapValues.emplace_hint(iterHint, std::move(Key), UTF16String())->second);
}