如何创建一个简单的 boost::lambda 函数?

发布于 2024-08-17 21:03:49 字数 413 浏览 1 评论 0原文

我正在尝试创建一个简单的函数来进行简单的测试并返回 true 或 false。

myfunct = (_3 < someArray[i]);

当我这样做时,我收到此错误:

error: no match for 'operator<' in '<unnamed>::_1 < depths[i]'

我希望得到与此等效的东西

bool myFunct(unsigned int a, unsigned int b, unsigned int c, unsigned int d)
{
   return c < 22; // Suppose 22 was in someArray[i]
}

I'm trying to create a simple function that makes a simple test and return true or false.

myfunct = (_3 < someArray[i]);

When I do this, I get this error :

error: no match for 'operator<' in '<unnamed>::_1 < depths[i]'

What I hope is get something equivalent to this

bool myFunct(unsigned int a, unsigned int b, unsigned int c, unsigned int d)
{
   return c < 22; // Suppose 22 was in someArray[i]
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尐籹人 2024-08-24 21:03:49

您确定命名空间正确吗?

应该是

using namespace boost::lambda;

或者

boost::lambda::_1

请记住,占位符用于 boost 的其他部分,或者其他库(可能会与本​​地 TR1 发生冲突!),这可能会引发错误。

Are you sure you've got the namespaces right?

It should be either

using namespace boost::lambda;

or

boost::lambda::_1

Remember that placeholders are used in other parts of boost, or in other libraries (conflict with a local TR1 may happen!), which may induce errors.

舂唻埖巳落 2024-08-24 21:03:49

以下编译没有任何错误,您的其余代码是什么样子的?

#include <boost/function.hpp>
#include <boost/lambda/lambda.hpp>

using namespace boost;
using namespace boost::lambda;

int main(void)
{
    int someArray[5];
    int i;
    function<bool(int,int)> f = (_1 < someArray[i]);
}

The following compiles without any errors, how does the rest of your code look like?

#include <boost/function.hpp>
#include <boost/lambda/lambda.hpp>

using namespace boost;
using namespace boost::lambda;

int main(void)
{
    int someArray[5];
    int i;
    function<bool(int,int)> f = (_1 < someArray[i]);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文