std :: lower_bound的奇怪错误

时间:2016-09-07 01:35:30

标签: c++

我正在为我的一位教授从事质谱数据库工作。这也是我在这里发表的第一篇文章,尽管该网站非常有帮助。

我使用带有标志的GNU CPP 4.8获得以下错误:

CXX = g++
BOOSTDIR = /home/user/boost_1_60_0/ #Uses boost_1_60_0 lirary.
CXXFLAGS = -std=c++11 -g -ggdb -rdynamic -D_GLIBCXX_DEBUG -Wall -Wextra -I$(BOOSTDIR)
LDFLAGS = -L/home/user/boost_1_60_0/stage/lib -lboost_system -lboost_filesystem -lboost_iostreams

结果如下:

/usr/include/c++/4.8/bits/stl_algo.h:2438:error: elements in iterator range 
    [__first, __last) are not partitioned by the predicate __comp and value     
    __val.

Objects involved in the operation:
iterator "__first" @ 0x0x7ffd8a308c30 {
type = N11__gnu_debug14_Safe_iteratorIN9__gnu_cxx17__normal_iteratorIP11cache_tableNSt9__cxx19986vectorIS3_SaIS3_EEEEENSt7__debug6vectorIS3_S7_EEEE (mutable iterator);
  state = dereferenceable (start-of-sequence);
  references sequence with type `NSt7__debug6vectorI11cache_tableSaIS1_EEE' @ 0x0x7ffd8a308c30
}
iterator "__last" @ 0x0x7ffd8a308c60 {
type = N11__gnu_debug14_Safe_iteratorIN9__gnu_cxx17__normal_iteratorIP11cache_tableNSt9__cxx19986vectorIS3_SaIS3_EEEEENSt7__debug6vectorIS3_S7_EEEE (mutable iterator);
  state = past-the-end;
  references sequence with type `NSt7__debug6vectorI11cache_tableSaIS1_EEE' @ 0x0x7ffd8a308c60
}
Aborted (core dumped)

以下是相关的方法调用:

void db::get_range(double mz_min, double mz_max, double rt_min, double rt_max, std::vector<dp> & ilist){    
    //Get valid rt ranges. //OPTIMIZE
    auto rt_low = std::lower_bound(tlist.begin(), tlist.end(), rt_min, rt_less_than());     
    //Iterate from low end until out of range or end of list.
    for(auto a = rt_low; (a != tlist.end() && (*(*a).begin()).rt_max < rt_max); a++){
        //Get valid mz ranges. //OPTIMIZE                       
        auto mz_low = std::lower_bound((*a).begin(), (*a).end(), mz_min, mz_less_than()); //This call is what is throwing the error.

        for(auto b = mz_low; (b != (*a).end() && (*(*a).rbegin()).mz_max < mz_max); b++){

            std::clock_t access_time = std::clock();
            (*b).get(mz_min, mz_max, rt_min, rt_max, ilist, access_time);
            tqueue.push(std::make_pair(&(*b), access_time));
            trim();
        }
    }
}

以下是一些支持代码:

        //Comparator to check rt ranges.
        struct rt_less_than{
            bool operator()(std::vector<cache_table> & p, double s) const{ 
                return p[0].rt_max < s; 
            }
            bool operator()(double p, std::vector<cache_table> & s) const{ 
                return p < s[0].rt_max; 
            }
        };

        //Comparator to check mz ranges.
        struct mz_less_than{
            bool operator()(cache_table & p, double s) const{ 
                return p.mz_max < s; 
            }
            bool operator()(double p, cache_table & s) const{ 
                return p < s.mz_max; 
            }
        };

现在这一切都在进行,直到我不得不重构大部分代码。我不是最有经验的cpp,这个错误让我觉得我没有满足函数的一些模板要求,但是当我检查mz_lower_than()对象里面的类名时,似乎没问题。在mz_lower_than()调用内部检查发现,对于此测试集的大小为99的向量大约90次调用后,它将抛出一个错误。

谷歌搜索这个错误已经发现其他一些人已经看过它,但在前3页之后,似乎没有人真正得到答案。我感觉这是一种极其简单的奇怪错误,但我似乎无法弄清楚它会是什么。

该程序非常大,所以我只粘贴了看起来所需的最少代码量,以便了解正在发生的事情。如果需要,我当然可以粘贴更多代码。

有人可以帮我吗? 谢谢!

1 个答案:

答案 0 :(得分:2)

您只能对按比较函数中使用的相同条件排序的序列运行lower_bound。由于您未在代码中显示任何sort,因此我必须假设您的数据未排序。