首页 \ 问答 \ 基于函数返回的stl容器构造效率(Efficiency of construction of stl container based on a function return)

基于函数返回的stl容器构造效率(Efficiency of construction of stl container based on a function return)

我有一个返回stl容器的工厂函数:

const std::vector<int> f(...) {
    std::vector<int> retval;
    return retval;
}

我想可以定义一个stl实例如下(没有错误):

const std::vector<int> stl_instance(f(...));

但这样做有效吗?

临时stl对象是否直接分配给stl_instance


I have a factory function which return a stl container:

const std::vector<int> f(...) {
    std::vector<int> retval;
    return retval;
}

I guess it is ok to define a stl instance as follow(no error):

const std::vector<int> stl_instance(f(...));

But is it efficient to do so?

Is the temporary stl object directly assigned to stl_instance?


原文:https://stackoverflow.com/questions/14251010
更新时间:2022-07-17 22:07

最满意答案

您可以编写一个调用PMD的Ant脚本,并在保存/构建项目时运行它。 这样做的缺点是在IDE之外提供PMD报告。 这将否定原始程序的任何时间节省。 如果您只是想知道是否有任何错误,它可能会很有用。

或者您可以扩展Eclipse插件以添加快捷方式。


You could write an Ant script that calls PMD and have it run whenever you save/build the project. That has the disadvantage of giving you a PMD report outside the IDE. Which would negate any time savings from the original procedure. It could be useful if you just want to know whether there are any errors or not.

Or you could extend the Eclipse plugin to add a shortcut.

相关问答

更多
  • 如果将jar作为Eclipse插件片段添加到Eclipse安装中,则可以使用自定义规则类。 插件片段的主机必须是ch.acanda.eclipse.pmd.core 。 要将jar转换为插件片段,您必须修改文件MANIFEST.MF文件并添加一些清单头。 以下是Eclipse插件片段的完整清单: Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Custom PMD Rules Bundle-SymbolicName: org.exam ...
  • Gradle的默认配置是使用java-basic ( 源代码 ) 然而,这是一种非常保守的方法,几乎没有PMD所提供的优势。 我作为PMD维护者的个人建议是: 查看https://pmd.github.io/pmd-5.8.1/pmd-java/rules/index.html上提供的所有规则 创建您自己的规则集,包括您同意的那些规则,以及您可能希望从默认值更改的所有额外属性。 Gradle和PMD Eclipse插件都可以从文件规则集加载规则,这样可以很容易地使它们始终保持同步。 The default ...
  • 你必须把它们列在一个数组中。 喜欢这个: @SuppressWarnings({ "PMD.OnlyOneReturn", "PMD.ShortVariable" }) You have to list them in an array. Like this: @SuppressWarnings({ "PMD.OnlyOneReturn", "PMD.ShortVariable" })
  • eclipse插件使用PMD分析文件。 如果你想自动化分析,那么你想直接使用PMD,而不是eclipse插件。 看看PMD的课。 它具有启动分析的静态方法PMD.doPMD(配置) 。 如果您想从命令行启动它,同一个类还包含主要方法 。 你可以找到一个如何在eclipse插件的Analyser.runPMD()方法中调用PMD.doPMD(配置)的例子。 The eclipse plugin uses PMD to analyse the files. If you want to automate the ...
  • 要安装PMD for Eclipse插件: 在Eclipse中,单击“帮助” - >“安装新软件”... 点击添加.. 输入以下内容:名称:Eclipse更新站点URL的PMD: https : //sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/ ,然后单击“确定”。 您应该看到Eclipse的PMD 选中它旁边的复选框,然后单击下一步>。 您需要接受许可证并确认您要安装未经过数字签名的插件。 无论如何,继续安装它。 重启eclipse ...
  • 您可以编写一个调用PMD的Ant脚本,并在保存/构建项目时运行它。 这样做的缺点是在IDE之外提供PMD报告。 这将否定原始程序的任何时间节省。 如果您只是想知道是否有任何错误,它可能会很有用。 或者您可以扩展Eclipse插件以添加快捷方式。 You could write an Ant script that calls PMD and have it run whenever you save/build the project. That has the disadvantage of giving ...
  • 您可以使用PMD编写新规则。 在您的情况下,新的XPath规则足以快速检查AST(抽象语法树)并执行您需要的检测。 替代文字http://pmd.sourceforge.net/images/designer_screenshot.png 因此,您可以声明新的规则集 ,并将它们与您的PMD插件一起集成到您的eclipse中 。 注意: PMD代表很多东西 ;) 我们一直试图找到PMD字母的含义 - 坦率地说,我们并不知道。 我们只是认为这些字母听起来很合适。 相当多 项目混乱探测器 项目监督指令 项目符合截 ...
  • 首选项 - > PMD(请不要在搜索栏上搜索PMD,然后找不到规则配置,尝试通过滚动每个首选项来查找)。 选择所需的规则。 点击应用和确定(它会重新建立规则) 现在右键单击代码并选择PMD->代码检查 Preferences -> PMD (please do not search PMD on search bar then you can not find the rule configuration try to find by scrolling each preference). Select t ...
  • 从sourceforge托管的更新站点安装pmd-eclipse时可能会出现一些已知问题,请参阅https://github.com/pmd/pmd-eclipse-plugin/issues/19 要解决所有这些问题,请按照以下说明操作: 从那里下载最新的pmd-eclipse-plugin版本的更新站点作为zip文件: https : //github.com/pmd/pmd-eclipse-plugin/releases 在eclipse中,转到:帮助>安装新软件>添加>存档并选择更新站点zip文件( ...
  • 命令行解析器在PMD 5.0.1中已更改,但遗憾的是文档从未更新过。 这些是变化: args[0]现在是-dir args[1]现在是-format args[2]现在是-rulesets 当你-format ideaj ,它还需要三个参数。 现在使用-property {name}={value}指定那些报告格式特定参数: args[3]现在是-property sourcePath args[4]现在是-property classAndMethodName args[5]现在是-property si ...

相关文章

更多

最新问答

更多
  • 您如何使用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)