如何反转find

编程入门 行业动态 更新时间:2024-10-11 03:25:43
本文介绍了如何反转find_if?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下find_if对我来说很好,除了我想要向后执行内部 个别比较(从m + 5,m + 4,...,到m)。我可以使用reverse()来反转数组,但这会引入 开销(整个数组的副本)。似乎我可以使用反向的迭代器但是数组m不是标准的STL容器,例如 向量。可能吗?非常感谢你的帮助。 float m [6]; float * p = find_if(m,m + 6,bind2nd(greater_equal< float> (),14.5)); Tony

解决方案

JDT写道:

以下find_if对我来说很好,除了我想要向后执行内部 个别比较(从m + 5,m + 4,...到m)。我可以使用reverse()来反转数组,但这会引入 开销(整个数组的副本)。似乎我可以使用反向的迭代器但是数组m不是标准的STL容器,例如 向量。可能吗?非常感谢你的帮助。 float m [6]; float * p = find_if(m,m + 6,bind2nd(greater_equal< float> (),14.5));

我认为你可以使用带指针的std :: reverse_iterator。见24.1.1 即: typedef std :: reverse_iterator< float * rfloat_iter; rfloat_iter p = std :: find_if(rfloat_iter(m + 6),rfloat_iter(m), std :: bind2nd(greater_equal< float>(),14.5));

嗨红, 感谢您的帮助。首先,24.1.1是什么意思? 其次,我正在测试你的代码。要检查find_if是否找到了某些内容, 我应该使用p == rfloat_iter(m + 6)或p == rfloat_iter(m)?此外, 是m + 5和m-1之间的范围? 您的代码有一些编译错误。我很感激,如果有人能告诉我 什么是正确的语法(因为我对这方面不熟悉)。 感谢您提供进一步的帮助。 Tony red floyd写道:

JDT写道: > 以下find_if对我来说很好,除了我想要向后执行内部个人比较(从m + 5, m + 4,...,到m)。我可以先使用reverse()来反转数组,但这会引入开销(整个数组的副本)。似乎我可以使用反向迭代器但是数组m不是标准的STL容器,例如矢量。可能吗?非常感谢你的帮助。 float m [6]; float * p = find_if(m,m + 6,bind2nd(greater_equal< float>(),14.5));

我认为你可以使用带指针的std :: reverse_iterator。见24.1.1 即: typedef std :: reverse_iterator< float * rfloat_iter; rfloat_iter p = std :: find_if(rfloat_iter(m + 6),rfloat_iter(m), std :: bind2nd(greater_equal< float>(),14.5));

JDT写道:

red floyd写道:

>我认为你可以使用带指针的std :: reverse_iterator。见24.1.1 typedef std :: reverse_iterator< float * rfloat_iter; rfloat_iter p = std :: find_if(rfloat_iter(m + 6),rfloat_iter(m), std :: bind2nd(greater_equal< float>(),14.5));

感谢您的帮助。首先,你对24.1.1的意思是什么?

ISO C ++标准(ISO / IEC 14882:2003)第24.1.1节。

我正在测试你的代码。要检查find_if是否找到了某些内容,我是否应该使用p == rfloat_iter(m + 6)"或p == rfloat_iter(m)?

后者。

此外,m + 5和m-1之间的范围是多少?

排序。有关详细信息,请参见24.1.1。

您的代码存在一些编译错误。我很感激,如果有人能告诉我 什么是正确的语法(因为我不熟悉这方面)。

我并不感到惊讶,我把它写在了我的头顶。我敢肯定,这里其他更知识渊博的人可以帮助你比我更多。 另外,作为礼仪问题,请尽量不要发帖(在你回复的内容之上张贴所有文件) - 在这个 新闻组中,它不赞成。相反,将你的回复与你提到的文本(正如我在这里所做的那样)或文本之后一起散布。

Hi, The following find_if works fine to me except that I want the internal individual comparison performed backward (from m+5, m+4, ..., to m). I can use reverse() to reverse the array first but that introduces overhead (a copy of the whole array). It seems that I can use a reverse iterator but the array m is not a standard STL container such as a vector. Is it possible? Your help is much appreciated. float m[6]; float *p = find_if(m, m+6, bind2nd(greater_equal<float>(), 14.5)); Tony

解决方案

JDT wrote:

Hi, The following find_if works fine to me except that I want the internal individual comparison performed backward (from m+5, m+4, ..., to m). I can use reverse() to reverse the array first but that introduces overhead (a copy of the whole array). It seems that I can use a reverse iterator but the array m is not a standard STL container such as a vector. Is it possible? Your help is much appreciated. float m[6]; float *p = find_if(m, m+6, bind2nd(greater_equal<float>(), 14.5));

I think that you can use std::reverse_iterator with a pointer. See 24.1.1 i.e.: typedef std::reverse_iterator<float *rfloat_iter; rfloat_iter p = std::find_if(rfloat_iter(m+6), rfloat_iter(m), std::bind2nd(greater_equal<float>(), 14.5));

Hi Red, Thanks for your help. First of all, what do you mean by 24.1.1? Second, I am testing your code. To check if find_if finds something, should I use "p == rfloat_iter(m+6)" or "p == rfloat_iter(m)"? Besides, is the range between m+5 and m-1? Your code has some compile errors. I appreciate if somebody can show me what''s the correct syntax (because I am not familiar with this regard). Thanks for any further help. Tony red floyd wrote:

JDT wrote:

>Hi,The following find_if works fine to me except that I want the internalindividual comparison performed backward (from m+5, m+4, ..., to m).I can use reverse() to reverse the array first but that introducesoverhead (a copy of the whole array). It seems that I can use areverse iterator but the array m is not a standard STL container suchas a vector. Is it possible? Your help is much appreciated.float m[6];float *p = find_if(m, m+6, bind2nd(greater_equal<float>(), 14.5));

I think that you can use std::reverse_iterator with a pointer. See 24.1.1 i.e.: typedef std::reverse_iterator<float *rfloat_iter; rfloat_iter p = std::find_if(rfloat_iter(m+6), rfloat_iter(m), std::bind2nd(greater_equal<float>(), 14.5));

JDT wrote:

red floyd wrote:

>I think that you can use std::reverse_iterator with a pointer. See 24.1.1typedef std::reverse_iterator<float *rfloat_iter;rfloat_iter p = std::find_if(rfloat_iter(m+6), rfloat_iter(m), std::bind2nd(greater_equal<float>(), 14.5));

Thanks for your help. First of all, what do you mean by 24.1.1?

Section 24.1.1 of the ISO C++ Standard (ISO/IEC 14882:2003).

I am testing your code. To check if find_if finds something, should I use "p == rfloat_iter(m+6)" or "p == rfloat_iter(m)"?

The latter.

Besides, is the range between m+5 and m-1?

Sort of. See 24.1.1 for more details.

Your code has some compile errors. I appreciate if somebody can show me what''s the correct syntax (because I am not familiar with this regard).

I''m not surprised, I wrote it off the top of my head. I''m sure that one of the other more knowledgeable types here can help you more than me. Also, as a matter of etiquette, please try not to top-post (posting all your text above what you''re replying to) -- it''s frowned on in this newsgroup. Instead, intersperse your replies with the text you''re referring to (as I did here), or after the text.

更多推荐

如何反转find

本文发布于:2023-11-30 14:35:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650344.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:find

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!