auto

Is there a way to pass auto as an argument in C++?

我的梦境 提交于 2019-11-27 22:40:33
Is there a way to pass auto as an argument to another function? int function(auto data) { //DOES something } If you want that to mean that you can pass any type to the function, make it a template: template <typename T> int function(T data); There's a proposal for C++17 to allow the syntax you used (as C++14 already does for generic lambdas), but it's not standard yet. Templates are the way you do this with normal functions: template <typename T> int function(T data) { //DOES something } Alternatively, you could use a lambda: auto function = [] (auto data) { /*DOES something*/ }; I dont know

linux基础命令:alias

扶醉桌前 提交于 2019-11-27 21:28:52
linux下alias命令详解 功能说明:设置指令的别名。 语  法:alias[别名]=[指令名称] 形如: alias cp=“cp -i”   补充说明:用户可利用alias,自定指令的别名。若仅输入alias,则可列出目前所有的别名设置。 alias的效力仅及于该次登入的操作。若要每次登入是即自动设好别名,可在/etc/profile或自己的~/.bashrc中设定指令的别名。还有,如果你想给每一位用户都生效的别名,请把alias la='ls -al' 一行加在/etc/bashrc最后面,bashrc是环境变量的配置文件 /etc/bashrc和~/.bashrc 区别就在于一个是设置给全系统一个是设置给单用户使用 有,如果你想给每一位用户都生效的别名,请把alias la='ls -al' 一行加在/etc/bashrc最后面,bashrc是环境变量的配置文件 /etc/bashrc和~/.bashrc 区别就在于一个是设置给全系统一个是设置给单用户使用 [root@VM_0_15_centos ~]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls

cisco路由器&三层交换机简单环境配置实例

≡放荡痞女 提交于 2019-11-27 21:17:41
一、网络拓扑图: 二、配置命令: 1、路由器的配置: interface FastEthernet0/0 ip address 10.66.88.222 255.255.255.0 ip nat outside duplex auto speed auto interface FastEthernet0/1 ip address 192.168.1.1 255.255.255.0 ip nat inside duplex auto speed auto interface Vlan1 no ip address shutdown ip nat inside source list 1 interface FastEthernet0/0 overload ip classless ip route 192.168.2.0 255.255.255.0 192.168.1.222 ip route 192.168.3.0 255.255.255.0 192.168.1.222 access-list 1 permit 192.168.0.0 0.0.255.255 三、三层交换机的配置: hostname L3-SW ip dhcp pool vlan2pool network 192.168.3.0 255.255.255.0 default-router 192.168.3.1

Is there a downside to declaring variables with auto in C++?

筅森魡賤 提交于 2019-11-27 19:56:11
问题 It seems that auto was a fairly significant feature to be added in C++11 that seems to follow a lot of the newer languages. As with a language like Python, I have not seen any explicit variable declaration (I am not sure if it is possible using Python standards). Is there a drawback to using auto to declare variables instead of explicitly declaring them? 回答1: You've only asked about drawbacks, so I'm highlighting some of those. When used well, auto has several advantages as well. The

margin属性

前提是你 提交于 2019-11-27 19:48:12
---恢复内容开始--- css盒子 由内容边缘(Content edge)包围形成的是内容盒(Content Box),类推还有内边距盒(Padding Box)、边框盒(Border Box)、外边距盒(Margin Box)。 其中内容盒、内边距盒、边框盒的背景由 background 属性决定,而外边距盒的背景是透明的。 盒子的外边框margin属性: 盒子的外边距margin 指的是当前盒子与其他盒子之间的距离,环绕在盒子周围的空白区域,属于不可见的区域,不会影响到可见框的大小,但是会影响到盒子的位置。 margin属性可以用来指定盒子外边框的大小,有两种方法设置外边距:第一种单独属性分别设置四个方向的外边距,第二种是使用简写属性同时设置多个方向的外边距(注意顺序),margin 属性接受任何长度单位,可以是像素px、英寸in、毫米mm或 em。 关于 margin 属性,有几点可能跟我们的直觉不相符: 如果 margin 的值是百分比,则是相对于父元素的内容盒宽度来计算的,即使 margin-top 和 margin-bottom 也是如此。因此即使父元素的高宽不相等,子元素的 margin 元素指定了相同的百分比值,则子元素各个方向的 margin 计算值都是相等的。 margin-top 和 margin-bottom 值对行内非替换元素(non-replaced

How to select iterator type using auto variable?

做~自己de王妃 提交于 2019-11-27 17:52:00
问题 I have a std::unordered_map std::unordered_map<std::string, std::string> myMap; I want to get a const iterator using find. In c++03 I would do std::unordered_map<std::string, std::string>::const_iterator = myMap.find("SomeValue"); In c++11 I would want to use auto instead to cut down on the templates auto = myMap.find("SomeValue"); Will this be a const_iterator or iterator? How does the compiler decide which to use? Is there a way I can force it to choose const? 回答1: It will use non-const

Why does auto a=1; compile in C?

佐手、 提交于 2019-11-27 17:25:10
The code: int main(void) { auto a=1; return 0; } gets compiled without errors by the MS Visual Studio 2012 compiler, when the file has the .c extension. I have always thought that when you use the .c extension, compilation should be according to the C syntax, and not C++. Moreover, as far as I know auto without a type is allowed only in C++ since C++11, where it means that the type is deduced from the initializer. Does that mean that my compiler isn't sticking to C, or is the code actually correct in C-language? Fred Foo auto is an old C keyword that means "local scope". auto a is the same as

C++ auto keyword. Why is it magic?

与世无争的帅哥 提交于 2019-11-27 16:45:01
From all the material I used to learn C++, auto has always been a weird storage duration specifier that didn't serve any purpose. But just recently, I encountered code that used it as a type name in and of itself. Out of curiosity I tried it, and it assumes the type of whatever I happen to assign to it! Suddenly STL iterators and, well, anything at all that uses templates is 10 fold easier to write. It feels like I'm using a 'fun' language like Python. Where has this keyword been my whole life? Will you dash my dreams by saying it's exclusive to visual studio or not portable? auto was a

C++11 Change `auto` Lambda to a different Lambda?

独自空忆成欢 提交于 2019-11-27 15:59:35
Say I have the following variable containing a lambda: auto a = [] { return true; }; And I want a to return false later on. Could I do something along the lines of this? a = [] { return false; }; This syntax gives me the following errors: binary '=' : no operator found which takes a right-hand operand of type 'main::<lambda_a7185966f92d197a64e4878ceff8af4a>' (or there is no acceptable conversion) IntelliSense: no operator "=" matches these operands operand types are: lambda []bool ()->bool = lambda []bool ()->bool Is there any way to achieve something like this? I would like to change the auto

Range-for-loops and std::vector<bool>

隐身守侯 提交于 2019-11-27 14:16:57
Why does this code work std::vector<int> intVector(10); for(auto& i : intVector) std::cout << i; And this doesn't? std::vector<bool> boolVector(10); for(auto& i : boolVector) std::cout << i; In the latter case, I get an error error: invalid initialization of non-const reference of type ‘std::_Bit_reference&’ from an rvalue of type ‘std::_Bit_iterator::reference {aka std::_Bit_reference}’ for(auto& i : boolVector) Quentin Because std::vector<bool> is not a container ! std::vector<T> 's iterators usually dereference to a T& , which you can bind to your own auto& . std::vector<bool> , however,