C ++:如何使用boost :: range查找max_element?(C++: how to find max_element using boost::range?)
我试图将迭代器返回到过滤范围中的最大元素。 这是我到目前为止:
#include <boost/lambda/lambda.hpp> #include <boost/range/adaptors.hpp> #include <boost/range/algorithm.hpp> #include <vector> #include <iostream> using namespace boost::adaptors; using namespace boost::lambda; using namespace std; int main () { vector<double> x = {100, 150, 200, 110}; auto it = boost::max_element(x | indexed(0) | filtered(_1>100)); /* problem here */ cout << it.index() << endl; return 0; }
我希望代码打印出矢量x中具有最大元素(即2)的索引,但不幸的是它不能编译(Linux 64bit,GCC 4.7.2),问题出现在上面指出的行中。 我从编译器(以及其他)获得的第一个编译错误如下:
/boost/tuple/detail/tuple_basic.hpp:396:36:错误:只读成员'boost :: tuples :: cons :: head'的赋值
我有什么想法我做错了吗? 或者我怎么能实现我想做的事情呢? 提前致谢!
编辑:
将有问题的行更改为:
auto it = boost::max_element<boost::return_found>(x | sliced(1,4) | filtered(boost::function<bool(double)>(_1>100)));
似乎将迭代器返回到最大的元素。 但是,有没有办法检查迭代器是否在范围内? 将它与boost :: end(x)进行比较会给我一个错误。 我唯一能想到的就是回归
auto another_range = boost::max_element<boost::return_found_end>(x | sliced(1,4) | filtered(boost::function<bool(double)>(_1>100)));
并检查是否boost :: empty(another_range)。 这是唯一的选择吗? 谢谢。
I am trying to return an iterator to the largest element in a filtered range. Here is what I have so far:
#include <boost/lambda/lambda.hpp> #include <boost/range/adaptors.hpp> #include <boost/range/algorithm.hpp> #include <vector> #include <iostream> using namespace boost::adaptors; using namespace boost::lambda; using namespace std; int main () { vector<double> x = {100, 150, 200, 110}; auto it = boost::max_element(x | indexed(0) | filtered(_1>100)); /* problem here */ cout << it.index() << endl; return 0; }
I expected the code to print out the index in the vector x which has the largest element (ie 2), but unfortunately it does not compile (Linux 64bit, GCC 4.7.2), the problem being in the line indicated above. The first compilation error I get from the compiler (amongst others) is the following:
/boost/tuple/detail/tuple_basic.hpp:396:36: error: assignment of read-only member ‘boost::tuples::cons::head’
Any ideas what I am doing wrong? Or how else I can achieve what I am trying to do? Thanks in advance!
EDIT:
Changing the problematic line to :
auto it = boost::max_element<boost::return_found>(x | sliced(1,4) | filtered(boost::function<bool(double)>(_1>100)));
seems to return the iterator to the largest element. However, is there a way to check that the iterator is within the range? Comparing it with boost::end(x) gives me an error. The only thing I can think of is to return
auto another_range = boost::max_element<boost::return_found_end>(x | sliced(1,4) | filtered(boost::function<bool(double)>(_1>100)));
and check if boost::empty(another_range). Is this the only option? Thanks.
原文:https://stackoverflow.com/questions/15723885
最满意答案
从命令行中的主app目录输入
cake bake controller -p <pluginname>
- 选择你正在烘焙的控制器
使用默认值回答脚手架问题(否)
你想使用动态脚手架吗? (Y / N)
[n]>From your main app directory in the command line enter
cake bake controller -p <pluginname>
- select the controller you're baking
Answer the scaffolding question with default (no)
Would you like to use dynamic scaffolding? (y/n)
[n] >
相关问答
更多-
子文件夹是名称空间,使用命名空间分隔符提供控制器名称,即反斜杠。 还要使用合适的驼峰套管。 bin/cake bake test controller Api\Users Subfolders are namespaces, supply the controller name using the namespace separator, ie a backslash. Also use proper camel casing. bin/cake bake test controller Api\User ...
-
CakePHP 2.2.2烘焙插件(CakePHP 2.2.2 bake for plugin)[2022-01-18]
1)烘焙你的插件: cake bake plugin PluginNameInCamelCase 2)烘焙其他一切: cake bake controller ControllerName --plugin PluginNameInCamelCase 有关烘焙插件的更多文档,请参阅此页面: 使用CakePHP创建自己的插件 1) Bake your plugin: cake bake plugin PluginNameInCamelCase 2) Bake everything else: cake ... -
我最终基于REST资源的模式创建了一个模拟数据库。 请参阅此答案 ,了解为什么没有数据库烘焙将无法运行。 我也没有做脚手架,而是用bake生成代码。 I ended up creating a mock database based on the schema of the REST resources. See this answer to understand why baking would not function without the database. I also did not do sc ...
-
如何检查cakephp-2.3中控制器使用的型号?(How to check which model is using by a controller in cakephp-2.3?)[2023-05-10]
您可以尝试使用get_class()来确定它是否真的使用“用户”模型,或者通用的“AppModel”或“模型”; 在你的控制器的动作内; debug(get_class($this->User)); 如果它是'Model'或'AppModel',CakePHP显然无法从插件中找到或加载您的User模型。 还要检查你是否真的在bootstrap.php中加载了插件。 阅读此处的文档: 插件 You may try get_class() to find out if it is really using t ... -
作为一种方法,可以自定义脚手架视图 。 您可以从蛋糕核心Cake\View\Scaffolds获取用于这些模板的源,并将它们放在文档中所考虑的目的地,然后编辑它们以隐藏您想要的内容。 例如:在index.ctp中,有以下片段生成操作列表: echo '
'; echo $this->Html->link(__d('cake', 'View'), array('action' => 'view', ${$singularVar}[$modelClass][ ... 如何在CakePHP中烘焙插件时获得交互式控制台?(How to get an interactive console when baking a plugin in CakePHP?)[2023-08-24]
当使用cake bake model MyModel --plugin MyPlugin插件中的模型时,它使用脚手架。 为了避免这种情况,你必须使用cake bake model --plugin MyPlugin然后提供的第一个选项将允许您从可能的模型中进行选择。 适当地用controller / view替换model以烘焙它们。 When a model in a plugin is baked using cake bake model MyModel --plugin MyPlugin it us ...您可以使用cake console脚本烘焙代码。 这一切都在食谱中解释过 You can bake the code using the cake console script. It's all explained in the cookbook终于....只需将localhost替换为127.0.0.1 'Datasources' => [ 'default' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', /** * C ...如何在cakephp 2.3中使用脚手架烘焙插件控制器(How to bake a plugin controller without scaffolding in cakephp 2.3)[2021-10-02]
从命令行中的主app目录输入 cake bake controller -p选择你正在烘焙的控制器 使用默认值回答脚手架问题(否) 你想使用动态脚手架吗? (Y / N) [n]> From your main app directory in the command line enter cake bake controller -p select the controller you're baking Answer the scaffolding ... 文档说它不够灵活。 但是,当调试级别为0时,它仍然有效。 脚手架是自动CRUD创建。 cakephp在你烘烤时产生CRUD。 脚手架的优势在于它适用于早期开发阶段。 更多阅读 http://www.indywebshop.com/bestpractices/2007/06/13/early-impressions-of-cakephp/ 但我建议不要使用它,因为在任何阶段你都需要编写自己的代码。 但对于不经常更改的应用程序,它确实有帮助。 The documentation says that it's n ...相关文章
更多- Lucene4:获取中文分词结果,根据文本计算boost
- Lucene4:运用中文分词器创建索引,给指定文本增加boost值
- could not find system property or JNDI
- Solr boost某字段的特殊值
- Guava学习笔记:Range
- Guava Range类-范围处理
- 《新版 Visual C++全能速查宝典》扫描版[PDF]
- Nike Barkley Foamposite Max “Rayguns”
- 《C/C++图像处理编程》扫描版[PDF]
- 谁给推荐一个C++的JSON库
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)