2016-09-07 162 views
0

我正在为我的一位论文的教授质谱数据库工作。这也是我的第一篇文章,虽然网站一直非常有帮助。奇怪的错误与std :: lower_bound

我正在使用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

这听起来像按照'std :: lower_bound'的要求,要分区的数组不是严格的弱顺序。 –

+1

出示您的[MCVE]。 MCVE不仅仅是“最小”,也是“完整”的。如果你还没有,那么你还没有完成调试!山姆可能是对的;那些比较者对我来说看起来颇为怀疑。 –

+0

好的感谢您的意见。我会用std :: sort()来检查是否是错误。 – mWellington

回答

2

只能在多数民众赞成在您的比较仿函数使用相同的标准排序顺序运行lower_bound。由于您在代码中未显示任何sort,我必须假定您的数据未排序。

+0

对不起,很晚回复。我的坏形式。这确实是答案。 – mWellington