auto

C++14 using auto keyword in a method's definition

安稳与你 提交于 2019-12-21 07:29:26
问题 I have several std::unordered_maps . They all have an std::string as their key and their data differs. I want to make a csv string from a given map's keys because that data needs to be sent over the wire to a connected client. At the moment I have a method for each individual map. I wanted to make this generic and I came up with the following : std::string myClass::getCollection(auto& myMap) { std::vector <std::string> tmpVec; for ( auto& elem : myMap) { tmpVec.push_back(elem.first); } std:

Is it possible to have an “auto” member variable?

雨燕双飞 提交于 2019-12-21 07:26:25
问题 For example I wanted to have a variable of type auto because I'm not sure what type it will be. When I try to declare it in class/struct declaration it's giving me this error: Cannot deduce auto type. Initializer required Is there a way around it? struct Timer { auto start; }; 回答1: You can, but you have to declare it static and const : struct Timer { static const auto start = 0; }; A working example in Coliru. With this limitation, you therefore cannot have start as a non-static member, and

web前端css(二)

[亡魂溺海] 提交于 2019-12-20 18:09:48
一. 标准文档流 标准文档流中会有一些现象: 空白折叠 和 高低不齐边底对齐的现象 标准文档流等级森严, 标签分为两种等级: 行内元素 和 块级元素. 1. 行内元素 和 块级元素的区别: 行内元素:不能设置宽高, 默认的宽度就是文字的宽度; 与其他行内元素并排 块级元素:设置宽高, 如果不设置就默认宽度是父级的100% ; 独占一行,不与其它任何元素并列 2. 标签分类 在HTML中已经将标签分过类了,当时分为文本级 和 容器级 a) 从HTML的角度来讲,标签分为: 文本级标签: p, span, a, u下划线, i斜体(已废弃), em斜体(已废弃), b粗体(已废弃) 容器级标签: div, li, dt, dd, h系列 这里为什么说p是文本级标签呢? 因为p里面只能放 文字, 图片, 表单. P里不能放h系列, 不能放ul 也不能放p. b) 现在从css角度看 和上面很像,就p不一样: 行内元素: 除了p之外,所有的文本级标签都是行内元素. P是文本级标签但是是个块级元素 块级元素:所有的容器级标签 div lid dt dd h, 还有 p 标签 3. 块级元素和行内元素的转换 我们可以通过display属性将块级元素和行内元素相互转换 块级元素转行内元素: 设置display:inline; 行内元素转块级元素: 设置display:block; 4.

Correctly propagating a `decltype(auto)` variable from a function

孤街浪徒 提交于 2019-12-20 16:46:40
问题 (This is a follow-up from "Are there any realistic use cases for `decltype(auto)` variables?" ) Consider the following scenario - I want to pass a function f to another function invoke_log_return which will: Invoke f ; Print something to stdout ; Return the result of f , avoiding unnecessary copies/moves and allowing copy elision. Note that, if f throws, nothing should be printed to stdout . This is what I have so far: template <typename F> decltype(auto) invoke_log_return(F&& f) { decltype

Which IDEs and text editors can deduce type of variables declared using auto keyword in C++11

孤者浪人 提交于 2019-12-20 13:00:09
问题 In "Almost always auto" article Herb Sutter lists several reasons for declaring variables using auto keyword. He says that actual variable type can be automatically deduced by IDE and shown by hovering over variable name. I would like to know which IDEs and text editors (or plugins) currently support "auto" variable type deduction. Edit: List of IDEs from answers: Visual Studio 201x Eclipse Qt Creator 2.7.0 KDevelop 4.5.1 Text editors What about Vim, Emacs, Sublime Text, etc. - are there

C++11 auto declaration with and without pointer declarator

微笑、不失礼 提交于 2019-12-20 10:16:35
问题 What's the difference between the types of bar1 and bar2 ? int foo = 10; auto bar1 = &foo; auto *bar2 = &foo; If both bar1 and bar2 are int* , does it makes sense to write the pointer declarator ( * ) in the bar2 declaration? 回答1: The declarations are exactly equivalent. auto works (almost) the same as template type deduction. Putting the star explicitly makes the code a bit easier to read, and makes the programmer aware that bar2 is a pointer. 回答2: Using auto * "documents intention". And

C++ return different objects

∥☆過路亽.° 提交于 2019-12-20 07:49:14
问题 i have a big problem.. I wonna select the Storage Service via a wrapper class. The returning value must be an object within the storage service class. I pasted my current approach. But my mindset didn't worked so far. Error: error: inconsistent deduction for auto return type: ‘SQL*’ and then ‘REDIS*’ return new REDIS(); The big wish is to have an interface class which defines the struct and some "driver classes" which contains all necessary operations for the target storage service. I hope

CSS清除浮动float方法总结

穿精又带淫゛_ 提交于 2019-12-20 00:23:47
使用浮动造成的BUG: 使用 浮动前 :(子节点是将父节点撑开了) 代码如下 1 <div class="box"> 2 <div class="d1">1</div> 3 <div class="d2">2</div> 4 </div> 5 .box{ 6 border: 1px solid black; 8 margin: 50px auto; 9 padding: 50px; 10 color: #fff; 11 } 12 .d1{ 13 float: left; 14 background: purple; 15 width: 100px; 16 height: 100px; 17 } 18 .d2{ 19 float: left; 20 background: #9c3; 21 width: 100px; 22 height: 100px; 23 } 首先说明现象:我没有给父节点设置高度,在给子div设置float:left后,出现如下BUG: 1.父节点的margin属性失效 2.子节点没有将父节点撑开 那么,我们该怎么解决这样由浮动造成的bug呢? 三种方法: 一、 :after的3行代码 (最高大上的方法,写情书的感觉哟) 原理:利用:after和:before在元素内插入两个元素块(其实就是在节点本身构造出两个存在于Render Tree的节点)

hibernate 自动生成数据库表

给你一囗甜甜゛ 提交于 2019-12-19 12:41:19
只要在hibernate.cfg.xml添加这句话,就可以自动生成数据表 <property name="hibernate.hbm2ddl.auto">update</property> update:表示自动根据model对象来更新表结构,启动hibernate时会自动检查数据库,如果缺少表,则自动建表;如果表里缺少列,则自动添加列。 还有其他的参数: create:启动hibernate时,自动删除原来的表,新建所有的表,所以每次启动后的以前数据都会丢失。 create-drop:启动hibernate时,自动创建表,程序关闭时,自动把相应的表都删除。所以程序结束时,表和数据也不会再存在。 PS:数据库要预先建立好,因为 hibernate只会建表,不会建库 ========================================== 表结构和数据总是在程序执行的时候无端的修改,折腾了好长时间,查了很长时间hibernate的数据库映射文件和接口程序,始终没有发现有什么错误,到最后才发现了它! <property name="hibernate.hbm2ddl.auto" value="update" /> 解释如下: hibernate.hbm2ddl.auto Automatically validate or export schema DDL to the

Lifetime Extension of a initializer_list return

给你一囗甜甜゛ 提交于 2019-12-19 07:43:06
问题 So I have a lambda who's return type is auto and I'm having issues with the array backing for an initializer_list being destroyed here: const auto foo = [](const auto& a, const auto& b, const auto& c) { return {a, b, c}; }; I will be using the lambda like this: auto bar = foo(1, 2, 3); for(const auto& i : bar) cout << i << endl; A job that I'm working has as part of their coding standard that all lambdas are single statements (feel free to express your outrage.) I think that I can get around