auto

Using 'auto' type deduction - how to find out what type the compiler deduced?

醉酒当歌 提交于 2019-12-31 08:28:26
问题 How can I find out what type the compiler deduced when using the auto keyword? Example 1: Simpler auto tickTime = 0.001; Was this deduced as a float or a double? Example 2: More complex (and my present headache): typedef std::ratio<1, 1> sec; std::chrono::duration<double, sec > timePerTick2{0.001}; auto nextTickTime = std::chrono::high_resolution_clock::now() + timePerTick2; What type is nextTickTime ? The problem I'm having is when I try to send nextTickTime to std::cout . I get the

CSS的置换和非置换元素

痞子三分冷 提交于 2019-12-28 14:35:27
一个来自面试的坑。 面试的时候考官先问了行内元素和块级元素的区别,这个不难理解。然后一脚就踩进了,置换元素的坑。例如img就是行内置换元素,这种行内元素是可以设置宽高的。 什么是置换元素 一个内容不受CSS视觉格式化模型控制,CSS渲染模型并不考虑对此内容的渲染,而且元素本身一般拥有固定的尺寸(宽度、高度、宽高比)的元素。 行内级置换元素的宽度 对于 行内级非置换元素 ,高度和宽度设置是不适用,垂直方向上的margin、padding设置也没有用。、 对于 行内级置换元素 ,宽度: 如果宽高或者宽的值为auto,且元素有固有的宽度,则width是此固有的宽度: 如果宽度设置为auto,但是高度有非auto的值,且元素有固定的宽高比: width = 高度 * 固定宽高比。 如img只设定了height,宽度会按比例计算 如果宽度设置为auto,且不符合上述条件,则宽度的使用值为300px。 如:iframe,canvas 行内级置换元素的高度 对于 行内级非置换元素 ,高度和宽度设置是不适用,垂直方向上的margin、padding设置也没有用。、 对于 行内级置换元素 ,高度: 如果宽高或者高的值为auto,且元素有固有的高度,则height是此固有的宽度 如果高度设置为auto,但是宽度有非auto的值,且元素有固定的宽高比: height = 宽度 / 固定宽高比。

C++11 auto: what if it gets a constant reference?

耗尽温柔 提交于 2019-12-27 13:39:47
问题 Please take a look at the following simple code: class Foo { public: Foo(){} ~Foo(){} Foo(const Foo&){} Foo& operator=(const Foo&) { return *this; } }; static Foo g_temp; const Foo& GetFoo() { return g_temp; } I tried to use auto like this: auto my_foo = GetFoo(); I expected that my_foo will be a constant reference to Foo , which is the return type of the function. However, the type of auto is Foo , not the reference. Furthermore, my_foo is created by copying g_temp . This behavior isn't that

C++11 auto: what if it gets a constant reference?

大兔子大兔子 提交于 2019-12-27 13:38:32
问题 Please take a look at the following simple code: class Foo { public: Foo(){} ~Foo(){} Foo(const Foo&){} Foo& operator=(const Foo&) { return *this; } }; static Foo g_temp; const Foo& GetFoo() { return g_temp; } I tried to use auto like this: auto my_foo = GetFoo(); I expected that my_foo will be a constant reference to Foo , which is the return type of the function. However, the type of auto is Foo , not the reference. Furthermore, my_foo is created by copying g_temp . This behavior isn't that

CSS 盒子和内外边距

北战南征 提交于 2019-12-26 00:45:13
文章目录 height width max-height max-width min-height min-width overflow overflow-x overflow-y padding padding-bottom padding-left padding-right padding-top margin margin-bottom margin-left margin-right margin-top 属性 描述 版本 height 设置元素的高度 CSS1 width 设置元素的宽度 CSS1 max-height 设置元素的最大高度 CSS2 max-width 设置元素的最大宽度 CSS2 min-height 设置元素的最小高度 CSS2 min-width 设置元素的最小宽度 CSS2 overflow 设置元素内容溢出时样式。 CSS2 overflow-x 设置元素内容水平方向溢出时样式。 CSS3 overflow-y 设置元素内容垂直方向溢出时样式。 CSS3 padding 在一个声明中设置所有内边距属性 CSS1 padding-bottom 设置元素的下内边距 CSS1 padding-left 设置元素的左内边距 CSS1 padding-right 设置元素的右内边距 CSS1 padding-top 设置元素的上内边距 CSS1

Auto.js软件工具集合

你离开我真会死。 提交于 2019-12-25 13:21:09
在学习和使用Auto.js时用到的软件工具等等; 学习/教程/文档 社区: https://www.autojs.org Auto.js 源码: https://github.com/hyb1996/Auto.js 官方文档: https://hyb1996.github.io/AutoJs-Docs Auto.js官方教程(从入门到精通): https://www.bilibili.com/read/readlist/rl27762 JavaScript 教程/菜鸟教程 https://www.runoob.com/js/js-tutorial.html 笔青居Auto.js哔哩哔哩视频教程 https://space.bilibili.com/21486893 案例/现成脚本 官方应用内置脚本案例 https://github.com/hyb1996/Auto.js/tree/master/app/src/main/assets/sample 蚂蚁森林能量智能收取脚本: Ant_Forest autojs 登陆脚本 https://github.com/bjc5233/autojs autojs 注册登陆签到脚本 https://github.com/bayson/autojs 一些autojs的脚本仓库: snailuncle/autojsDemo 2019淘宝双11喵币:

why this variable isn't deduced as initializer_list in g++ in C++14?

拜拜、爱过 提交于 2019-12-24 15:04:54
问题 Consider the following program: #include <iostream> int main() { int n = 3; int fact = 1; for(auto i{1};i<=n;i++) fact*=i; std::cout<<"fact of "<<n<<" is "<<fact; } It compiles fine on ideone even when I use -std=c++14 option. See live demo here. But in C++14 the variable i should be deduced as initializer_list according to this. There is a proposal for C++1z that implements new type deduction rules for brace initialization: For direct list-initialization: For a braced-init-list with only a

How to return arbitrary type in C++11 using auto keyword?

冷暖自知 提交于 2019-12-24 12:43:59
问题 I have a class that looks like this: class Container { public: Container(){ Doubles["pi"] = 3.1415; Doubles["e"] = 2.7182; Integers["one"] = 1; Integers["two"] = 2; } // Bracket.cpp:23:9: error: 'auto' return without trailing return type // auto& operator[](const std::string&); auto& operator[](const std::string& key); private: std::map<std::string, double> Doubles; std::map<std::string, int> Integers; }; I'd like to overload the operator[] function to return something from either Doubles or

也谈C++11里的auto类型

纵然是瞬间 提交于 2019-12-24 12:03:25
1.C++的强类型语言特性 C语言本身是一种强类型语言,在C语言基础之上的C++也是一种强类型语言。在C和C++之中,一切变量(包括函数),都必须明确标明类型。只有类型确定,才会被编译器认为是一种可以接受的语法。 由于C++本身的强类型特性,传统的C++开发会有很多特点: 1)任何变量和函数都必须明确标明类型; 2)如果两个不一致类型的变量进行比较或者赋值,要么报错,要么会被隐式转换(隐式转换会告警); 3)C++语言本身,或者说面向对象语言本身有个重载功能,重要原因是强类型;由于语言本身类型是强类型的,必须对类似功能的函数,进行重载,才可以具有类似的功能。 当然,强类型语言的优点是:由于类型是强类型,所以在编译初期,就可以确定语言的类型,导致编译时候就可以检查出错误;同时,由于类型确定,编译时可以比较快速确定类型,并快速编译,然后快速运行。 2.推断类型语言的崛起 随着计算机性能的提高,计算机可以飞速运行,甚至可以JIT执行,也就是可以便解释,边执行。这也让计算机可以运行很多“笨重”或者性能不高的语言。 与之相应的,许多不是强类型的语言开始崛起。最具有典型意义的是python;python是一种弱类型的语言;对于该语言来说,任何变量的类型都不是提前声明的,而是在运行的时候进行推断的。由于这些语言的类型不是强类型,让编程语言开发的门槛变得更低

Why can't I initialize a value using braces with auto and pass it into this function

南楼画角 提交于 2019-12-24 11:30:04
问题 Why can't I initialize a value with auto and pass it into a function that expects a decltype as a parameter? Let me set the scene, and show you a tiny program. Here is a function that returns a value. int Function(void); In this case, it happens to be an integer, but the return type is subject to change. That is why this next function, is written as followed: void What_I_Take_Depends_On_Function(decltype(Function()) x); If someone decides to change the return type of Function, then the