standards

What is the rationale for parenthesis in C++11's raw string literals R“(…)”?

百般思念 提交于 2019-11-27 00:09:24
问题 There is a very convenient feature introduced in C++11 called raw string literals, which are strings with no escape characters. And instead of writing this: regex mask("\\t[0-9]+\\.[0-9]+\\t\\\\SUB"); You can simply write this: regex mask(R"(\t[0-9]+\.[0-9]+\t\\SUB)"); Quite more readable. However, note extra parenthesis around the string one have to place to define a raw string literal. My question is, why do we even need these? For me it looks quite ugly and illogical. Here are the cons

Use CSS to automatically add 'required field' asterisk to form inputs

Deadly 提交于 2019-11-26 23:48:13
What is a good way to overcome the unfortunate fact that this code will not work as desired: <div class="required"> <label>Name:</label> <input type="text"> </div> <style> .required input:after { content:"*"; } </style> In a perfect world, all required input s would get the little asterisk indicating that the field is required. This solution impossible since the CSS is inserted after the element content, not after the element itself, but something like it would be ideal. On a site with thousands of required fields, I can move the asterisk in front of the input with one change to one line (

Can an ANSI C-compliant implementation include additional functions in its standard library?

一曲冷凌霜 提交于 2019-11-26 23:15:34
问题 Is an ANSI C-compliant implementation allowed to include additional types and functions in its standard library, beyond those enumerated by the standard? (An ideal answer would reference the relevant part of the ANSI standard.) I ask particularly because Mac OS 10.7 declares the getline function in stdio.h, even when compiling with gcc or clang using the -ansi flag. This breaks several older programs that define their own getline function. Is this a fault of Mac OS 10.7? (The man page for

What is an Anonymous Object?

末鹿安然 提交于 2019-11-26 23:09:40
问题 What is an Anonymous Object exactly? Does C++ support/have Anonymous Objects? 回答1: The C++ standard does not define the term "anonymous object", but it stands to reason that one might sanely use the term to describe any object that has no name: Temporaries: f(T()); Unnamed function parameters: void func(int, int, int); What I wouldn't count is dynamically-allocated objects: Technically speaking, an "object" is any region of storage [1.8/1 in 2003], which would include the X bytes making up

In the standard, what is “derived-declarator-type”?

烂漫一生 提交于 2019-11-26 22:51:02
问题 In different places in the C++ (C++11) standard, declarations are described in terms of derived-declarator-type-list . I am studying rvalue references and the use of this term is critical in that context (§8.3.2): In a declaration T D where D has either of the forms & attribute-specifier-seq opt D1 && attribute-specifier-seq opt D1 and the type of the identifier in the declaration T D1 is “ derived-declarator-type-list T ,” then the type of the identifier of D is “ derived-declarator-type

Is it legal/well-defined C++ to call a non-static method that doesn't access members through a null pointer?

痞子三分冷 提交于 2019-11-26 22:24:09
问题 I came across the following code recently: class Foo { public: void bar(); // .. other stuff }; void Foo::bar() { if(!this) { // .. do some stuff without accessing any data members return; } // .. do normal actions using data members } The code compiles because in C++ methods are just functions that are implicitly passed a pointer for 'this' and 'this' can be checked to be NULL just like any other pointer. Obviously this code is confusing and bad practice even though it doesn't crash; it

List or longer code snippet inside paragraph

孤街浪徒 提交于 2019-11-26 22:12:06
问题 This question was migrated from Webmasters Stack Exchange because it can be answered on Stack Overflow. Migrated 6 years ago . When writing about algorithms, it is often very convenient to write some (pseudo)code inside a paragraph, or even in the middle of a sentence . To visually support the structure of a more complex sentence, lists come handy too. Obviously, one sentence must not be split across different paragraphs. But in our case it has to be due to HTML nesting rules. Paragraph is

Why statements cannot appear at namespace scope?

六月ゝ 毕业季﹏ 提交于 2019-11-26 22:00:25
问题 Any idea on which rule in standard states the statements like this: p++; //where 'p' is pointer to array cannot appear in global scope? I'm looking for a reference not just an explanation if possible. 回答1: The expression p++ which you've written is at namespace scope. It is forbidden by the grammer of namespace-body which is defined in §7.3.1/1 as: namespace-body: declaration-seq opt which says the namespace-body can optionally contain only declaration . And p++ is surely not a declaration,

Node.TEXT_NODE and IE7

风格不统一 提交于 2019-11-26 21:34:05
问题 I've some javascript that tests DOM node types against like this: if(node.nodeType == Node.TEXT_NODE) { Of course, it all works fine in Firefox, Safari, and Opera. But Internet Explorer 7 is complaining that Node (with the capital N) is undefined. But that's part of DOM Level 2! Do I really need to change my code to use magic numbers? Or am I missing something simple here? 回答1: Unfortunately you are not missing anything. There is no Node constant in IE. Look here http://www.ibm.com

Why an unnamed namespace is a “superior” alternative to static? [duplicate]

陌路散爱 提交于 2019-11-26 21:21:33
This question already has an answer here: Superiority of unnamed namespace over static? 3 answers The section $7.3.1.1/2 from the C++ Standard reads: The use of the static keyword is deprecated when declaring objects in a namespace scope; the unnamed-namespace provides a superior alternative. I don't understand why an unnamed namespace is considered a superior alternative? What is the rationale? I've known for a long time as to what the standard says, but I've never seriously thought about it, even when I was replying to this question: Superiority of unnamed namespace over static? Is it