auto

can I use auto with g++ 4.4?

▼魔方 西西 提交于 2019-12-11 02:15:13
问题 I can specify -std=c++0x for compilation with my g++ 4.4, and initializer lists are correct, I may use them (in c++98 I can't) but still get errors when try use auto keyword: std::list< std::vector<int> > li2; li2.push_back({1, 2, 3}); //push_back vector li2.push_back({4, 2, 6}); //again, vector implicitly for (auto& vv : li2) { for (auto &i : v) printf("element: %d\n", 8); } so I assume I can't use C++11 functionallities with g++4.4. I have 4.4 because of compatibility with CUDA. 回答1: This

html、css 实现网页布局

时光怂恿深爱的人放手 提交于 2019-12-10 23:37:44
布局:排列页面中的区域 ;布局写起来不难,但是里面蕴含着许多基本知识 我下面讲的布局方式,都是自适应的(若你要将布局全部定宽,看完本文,这对你来说更是没有难度了,把下文中代码出现的自适应宽度值改为你需要的宽度值即可,本文很多知识点的讲解都是围绕auto的) 文章目录 两栏布局 三栏布局 后台页面的布局 先了解一个知识点: 常规流格式化模型 ,大体上将页面的排列方式分为三种方式 常规流 浮动 定位 常规流布局讲解-start 常规流: 又名文档流 所有元素,默认情况下都属于常规流布局 总体规则:块盒独占一行,行盒水平依次排列 包含块: 每个盒子都有它的包含块,包含块决定了盒子的排列区域,绝大部分情况下,盒子的包含块为父元素的内容盒 块盒(水平方向): 每个块盒的总宽度(border-box + margin),必须等于包含块的宽度 宽度的默认值是auto(会将包含块的剩余空间吸收掉) margin默认值为0,也可以取值为auto(当width不等于auto时,margin吸收包含块的剩余空间) width、margin都取值为auto时, width: auto; 的吸收能力更强,优先级高,包含块的剩余空间由width吸收 若width、border、padding、margin计算后,仍然有剩余空间,该剩余空间会被margin-right吸收掉 块盒(垂直方向): height:

Error with for_each, map and lambda when passing by non-auto non-const lvalue reference

风流意气都作罢 提交于 2019-12-10 18:53:06
问题 In the following code, the first for_each statement gives me errors with GCC 7.2, some of which says: cannot bind non-const lvalue reference of type 'std::pair&' to an rvalue of type 'std::pair' #include <algorithm> #include <iostream> #include <map> int main() { std::map<int, double> m = { {1, 1.0}, {2, 2.0}, {3, 3.0} }; std::for_each(std::begin(m), std::end(m), [](std::pair<int, double>& e){ e.second += 1.0; }); // ERROR std::for_each(std::begin(m), std::end(m), [](auto& e){ e.second += 1.0

Are There Restrictions on What can be Passed to auto Template Parameters? [duplicate]

回眸只為那壹抹淺笑 提交于 2019-12-10 17:44:24
问题 This question already has answers here : Non-type template parameters (4 answers) Closed 12 months ago . In c++17 we got auto template parameters. I was trying to use one to pass an object in this question: Can I Write Relational Operators in Terms of Arithmetic Operations? But directed by AndyG's comment I found that didn't compile :( Given the template function: template <auto T> void foo() There seem to be restrictions on what I can pass as a template parameter. For example, as seen in my

Why must <initializer_list> be included for using auto?

白昼怎懂夜的黑 提交于 2019-12-10 14:34:05
问题 There has already been a similar question on SO, but I want to stress another aspect of braced-init-lists . Consider the following: auto x = {1}; //(1) This is ill-formed (8.5.4/2) unless the header <initializer_list> is included. But why? The standard says, that the template std::initializer_list is not predefined. Does this mean, that declaration (1) introduces a new type? In all other situations, where auto may be used such as auto y = expr; where expr is an expression, the type auto

How do I deduce auto before a function is called?

烈酒焚心 提交于 2019-12-10 12:32:20
问题 while experimenting with function return type deduction auto func(); int main() { func(); } auto func() { return 0; } error: use of ‘auto func()’ before deduction of ‘auto’ Is there a way to use this feature without needing to specify the definition before the call? With a large call tree, it becomes complicated to re-arrange functions so that their definition is seen before all of the places they are called. Surely an evaluation could be held off until a particular function definition was

C++ pipeline segment with multiple output ports - type matching

拈花ヽ惹草 提交于 2019-12-10 11:54:30
问题 I am trying to design a pipeline for my project. I am loosely relying on the VTK pipeline concept. However, there are major differences. In my design the input-output connection type matching was done using variadic templates and recursive inheritance (similar to CRTP). This allows me to manually define which segments can be connected with which segments by passing a list of abstract base classes to the base filter/mapper classes. In itself, this does not cause any problems. I need to be able

Different behavior observed with constexpr auto/char-array variable

ε祈祈猫儿з 提交于 2019-12-10 09:08:06
问题 Following up with this question Having a constexpr static string gives a linker error In the question, this code wasn't able to compile: #include <iostream> struct Test { static constexpr char text[] = "Text"; }; int main() { std::cout << Test::text << std::endl; // error: undefined reference to `Test::text' } From the comment, this code is able to compile: #include <iostream> struct Test { static constexpr auto text = "Text"; }; int main() { std::cout << Test::text << std::endl; } My

还在定闹钟收蚂蚁森林能量? 全自动神器

走远了吗. 提交于 2019-12-10 08:10:18
适用系统:安卓+IOS 许多人喜欢在蚂蚁森林种树 但是里面能量要很早起来收 有的人还要定闹钟起来 自己能力总被偷 而且还偷不到别人的能量 今天教大家怎样定时收自己的能量 定时偷别人的能量 安卓 安卓手机上有一款自动化程序 Auto.js , 使用这款软件和写好的脚本可以完成一系列的手机动作 跟之前分享的自动刷TB喵币是一样的 首先下载安装 Auto.js 程序到手机上,首次打开会提示开启「无障碍服务」,按照提示开启权限。 下载蚂蚁森林自动化脚本的压缩包到手机上,下载完成后将该文件放到根目录下的「脚本」文件夹内,然后解压。部分手机可能没有脚本文件夹而是「Scripts」文件夹。 回到 Auto.js,主界面文件夹选项下出现「Auto.js_Projects-Ant_Forest」文件夹,点击文件夹 ,直到出现如下界面: 点击「Aut_Forest_Settings」后面的三角形按钮进入蚂蚁自动化的配置界面,大家可以根据自己的需求修改脚本中的一些参数。 更改完成后点击右上角保存配置。没有特殊需求的可以不做更改。返回运行「Aut_Forest_Launcher」。 运行后,你就可以看到手机自动打开支付宝进入蚂蚁森林为你自动收能量,然后好心的帮助未及时收取能量的好友收取他们的能量,顺带也偷点能量。 整个自动化过程中,程序运行不会像你自己操作手机偷能量那样行云流水

C++11新特性 auto

会有一股神秘感。 提交于 2019-12-10 06:07:48
【前言】 C++11这次的更新带来了令很多C++程序员期待已久的for range循环,每次看到javascript, lua里的for range,心想要是C++能有多好,心里别提多酸了。这次C++11不负众望,再也不用羡慕别家人的for range了。 【使用场景】 ex1:遍历字符串 std :: string str = “hello , world” ; for ( auto ch : str ) { std :: cout << ch << std :: endl ; } 遍历str,输出每个字符,同时用上auto,简直是如虎添翼。 ex2:遍历数组 int arr [ ] = { 1 , 2 , 3 , 4 } ; for ( auto i : arr ) { std :: cout << i << std :: endl ; } 不用知道数组容器的大小,即可方便的遍历数组。 ex3:遍历stl 容器 std :: vector < std :: string > str_vec = { “i” , “like” , "google” } ; for ( auto & it : str_vec ) { it = “c ++ ” ; } 在这段程序中,可以返回引用值,通过引用可以修改容器内容。 ex4:遍历stl map std :: map < int , std :