auto

Why can't virtual functions use return type deduction?

北战南征 提交于 2019-12-01 02:09:36
n3797 says: § 7.1.6.4/14: A function declared with a return type that uses a placeholder type shall not be virtual (10.3). Therefore the following program is ill-formed: struct s { virtual auto foo() { } }; All I can find for the rationale is this vague one-liner from n3638 : virtual It would be possible to allow return type deduction for virtual functions, but that would complicate both override checking and vtable layout, so it seems preferable to prohibit this. Can anyone provide further rationale or give a good (code) example that agrees with the above quote? The rationale that you

How would auto&& extend the life-time of the temporary object?

回眸只為那壹抹淺笑 提交于 2019-12-01 00:19:56
问题 The code below illustrated my concern: #include <iostream> struct O { ~O() { std::cout << "~O()\n"; } }; struct wrapper { O const& val; ~wrapper() { std::cout << "~wrapper()\n"; } }; struct wrapperEx // with explicit ctor { O const& val; explicit wrapperEx(O const& val) : val(val) {} ~wrapperEx() { std::cout << "~wrapperEx()\n"; } }; template<class T> T&& f(T&& t) { return std::forward<T>(t); } int main() { std::cout << "case 1-----------\n"; { auto&& a = wrapper{O()}; std::cout << "end-scope

【LeetCode】解数独

老子叫甜甜 提交于 2019-11-30 23:32:34
做题之前先复习下 【STL中的Tuple容器】 我们知道,在Python中,大家都知道tuple这个概念,是一个只读的元素容器,容器内的元素数据类型可以不同,而在CPP中大部分的容器只能储存相同数据类型的数据,而 std::pair函数 是为数不多的可以将两个不同类型的值放到一起。我们今天说的tuple是std::pair的推广,表示固定大小的异类值的汇集。 std::tuple是C++11标准开始提出的,其有很多用途,比如一个函数如果拥有多个不同类型的返回值 ,就可以直接返回一个tuple.不用再像以前一样,定义一个class或者struct保存结果进行返回那么麻烦了! 其使用的重要函数有: std::make_tuple 创建一个tuple对象 std::tie 创建左值引用的tuple,或将tuple解包为独立对象 std::get(std::tuple) 元组式访问指定的元素 结构化绑定(重要,效率最高),避免使用std::tie函数 使用Demo示例: #include <tuple> #include <iostream> #include <string> #include <stdexcept> std::tuple<double, char, std::string> get_student(int id) { if (id == 0) return std:

RabbitMQ 消息确认以及消息消费方处理消息时候抛出了异常以

こ雲淡風輕ζ 提交于 2019-11-30 22:47:49
本篇的代码使用的前面两篇文章《RabbitMQ与Spring整合之消息生产方》和《RabbitMQ与Spring整合之消息消费方》的代码,这两篇文件里配置文件的名称不正确,不可直接运行。 一 自动确认机制 在服务消费者rabbitmq.xml 做修改: <!-- queue litener 观察 监听模式 当有消息到达时会通知监听在对应的队列上的监听对象 --> <rabbit:listener-container acknowledge="auto" connection-factory="connectionFactory"> <rabbit:listener queues="spring_queue_test_01" ref="consumerService" /> </rabbit:listener-container> 添加了配置 acknowledge="auto",这里来配置mq的确认机制,auto 自动确认,这也是 默认缺省 的配置。 特点:消费者挂掉,待ack的消息回归到队列中。消费者抛出异常,消息会不断的被重发,直到处理成功。不会丢失消息,即便服务挂掉,没有处理完成的消息会重回队列,但是异常会让消息不断重试。 ConsumerService.java package cn.mn.app; import org.springframework.amqp.core

一些c++<auto>

橙三吉。 提交于 2019-11-30 22:21:02
-------------------------------------------------------------- auto:用来声明自动变量。它是存储类型标识符,表明变量(自动)具有本地范围,块范围的变量声明(如for循环体内的变量声明)默认为auto存储类型。其实大多普通声明方式声明的变量都是auto变量,他们不需要明确指定auto关键字,默认就是auto的了。auto变量在离开作用域是会变程序自动释放,不会发生内存溢出情况(除了包含指针的类)。使用auto变量的优势是不需要考虑去变量是否被释放,比较安全。 new:new是用来在堆上申请内存地址的关键字,他产生的变量不会自动释放,除非delete来手动释放,或者程序结束时由操作系统释放,使用new的优势是内存使用比较灵活,理论可以申请任意大小的内存区块(实际与操作系统有关),但这很容易产生问题,一不小心忘记释放对象,特别是在频繁调用的函数内创建的对象忘记释放时,会产生内存溢出,严重时导致程序出错,系统崩溃。new一般都是在类的定义中使用,结合delete可以使包含new出来对象的类也具有自带变量功能,这样就继承了两种方式的优势。 -------------------------------------------------------------- 另外,最新的C+

Why can't virtual functions use return type deduction?

主宰稳场 提交于 2019-11-30 21:33:36
问题 n3797 says: § 7.1.6.4/14: A function declared with a return type that uses a placeholder type shall not be virtual (10.3). Therefore the following program is ill-formed: struct s { virtual auto foo() { } }; All I can find for the rationale is this vague one-liner from n3638: virtual It would be possible to allow return type deduction for virtual functions, but that would complicate both override checking and vtable layout, so it seems preferable to prohibit this. Can anyone provide further

「UR#5」怎样更有力气

微笑、不失礼 提交于 2019-11-30 19:40:01
「UR#5」怎样更有力气 解题思路 考虑没有限制的情况,一定是把操作离线下来,按照边权从小到达做。可以发现,如果没有限制,完全图是多余的,直接拿树边进行合并就可以了。我们要做这么一件事情,把每个点属于的图上联通块看做颜色,每次合并链上相邻两块颜色不一样的,那么我们再额外使用一个并查集,把树上相邻的颜色相同的点合并在一个集合里,每次跳到集合中最浅的点做图上的合并操作即可,复杂度 \(\mathcal O(n\alpha(n))\) 。 考虑一个操作的限制数量 \(cnt\) ,如果 \(cnt \geq\) 链上的点数,那么这些点仍然是联通的,所以可以直接当做没有限制的情况来做。于是发现,有限制的情况的链的点数不超过 \(p_i\) ,考虑暴力把这条链上的点拿出来。问题转化为有一个点集 \(S\) ,并且给出这个点集的补图,要合并联通块信息。涉及到补图可以试图用一个小技巧解决,拿出补图中度数最小的点 \(x\) ,有 \(\deg[x]\leq \min(|S|,\sqrt{p_i})\) 。划分成与 \(x\) 相连的点集和与 \(x\) 不相邻的点集两个问题考虑。所有不与 \(x\) 相连的点可以直接与 \(x\) 合并,所有与 \(x\) 相邻的点不超过 \(\sqrt{p_i}\) 个,可以直接枚举两个点合并。对于两个集合直接的连边,考虑与 \(x\) 相邻的集合的每一条对

Compiler can't deduce the return type?

天涯浪子 提交于 2019-11-30 18:45:35
I am trying to use the decltype keyword on an auto function: struct Thing { static auto foo() { return 12; } using type_t = decltype(foo()); }; And I get the following error (gcc 7.4): <source>:6:25: error: use of 'static auto Thing::foo()' before deduction of 'auto' decltype(foo()); ^ <source>:6:25: error: use of 'static auto Thing::foo()' before deduction of 'auto' Why has the compiler not yet deduced the return type? Because for class definition, compiler will first determine all member names and types. Function body is analyzed after this is done. That's why a class member function can

SQLSEVER导出 xml文件

℡╲_俬逩灬. 提交于 2019-11-30 12:56:19
各种都可以参照: 链接: https://wenku.baidu.com/view/778f794bfe4733687e21aa90.html 怎样把SQL Server里的某个表的数据导出成XML文件,要用SQL语言,而且要自动实现,怎么做? 最佳答案 select * from 表名 for xml 以下是详细介绍: FOR 子句 FOR 子句用于指定 BROWSE 或 XML 选项(BROWSE 和 XML 是不相关的选项)。 语法 [ FOR { BROWSE | XML { RAW | AUTO | EXPLICIT } [ , XMLDATA ] [ , ELEMENTS ] [ , BINARY BASE64 ] } ] 参数 BROWSE 指定当查看 DB-Library 浏览模式游标中的数据时允许更新。如果表包含时间戳列(用 timestamp 数据类型定义的列),表有唯一索引且 FOR BROWSE 选项在 SELECT 语句的最后发送到 SQL Server,则可以在应用程序中浏览该表。 说明 在含有 FOR BROWSE 选项的 SELECT 语句中无法使用 <lock_hint> HOLDLOCK。 FOR BROWSE 选项不能出现在用 UNION 运算符联接的 SELECT 语句中。 XML 指定查询结果将作为 XML 文档返回。必须指定下列 XML

Why does a range-based for statement take the range by auto&&?

こ雲淡風輕ζ 提交于 2019-11-30 11:25:42
A range-based for statement is defined in §6.5.4 to be equivalent to: { auto && __range = range-init; for ( auto __begin = begin-expr, __end = end-expr; __begin != __end; ++__begin ) { for-range-declaration = *__begin; statement } } where range-init is defined for the two forms of range-based for as: for ( for-range-declaration : expression ) => ( expression ) for ( for-range-declaration : braced-init-list ) => braced-init-list (the clause further specifies the meaning of the other sub-expressions) Why is __range given the deduced type auto&& ? My understanding of auto&& is that it's useful