standards

why STL header files have no extension?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 01:24:32
I got this basic doubt. The STL header doesn't have .h extension. #include <vector> #include <map> Is there is any specific reason behind this? Anybody knows history behind this, please share. EDIT : @GMan found Michael Burr's answer which addresses this question. The #include directive doesn't discriminate file types (it's just a glorified copy-paste operation) - no automatic adding of .h is happening. C++ standard header files are provided without the .h extension Sometimes backward compatibility header files are provided by the vendor with the same name with the .h extension added It all

Why do both struct and class exist in C++?

寵の児 提交于 2019-12-04 00:50:01
问题 As we know, struct and class are interchangeable in many places in the language. Confusingly, the keywords themselves do not necessarily correspond to the language used in the standard. For example, in draft standard N4567 [class]/10, A POD struct 109 is a non-union class that is both a trivial class and a standard-layout class, and has no non-static data members of type non-POD struct, non-POD union (or array of such types). Similarly, a POD union is a union that is both a trivial class and

Why is a non-static data member reference not a variable?

我的未来我决定 提交于 2019-12-04 00:49:56
问题 The definition of a variable in C++11 is as follows (§3/6): A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name denotes the reference or object. So a non-static data member reference is not a variable. Why is this distinction necessary? What's the rationale here? 回答1: Here's one way I can declare a variable in C++: int scientist = 7; After this declaration (and definition, in this case), I can use scientist to

Should `unique_ptr< T const [] >` accept a `T*` constructor argument?

时光怂恿深爱的人放手 提交于 2019-12-04 00:13:19
Code: #include <memory> using namespace std; struct T {}; T* foo() { return new T; } T const* bar() { return foo(); } int main() { unique_ptr< T const > p1( bar() ); // OK unique_ptr< T const [] > a1( bar() ); // OK unique_ptr< T const > p2( foo() ); // OK unique_ptr< T const [] > a2( foo() ); // ? this is line #15 } Example errors with Visual C++ 10.0 and MinGW g++ 4.4.1: [d:\dev\test] > cl foo.cpp foo.cpp foo.cpp(15) : error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>' with [ _Ty=const T [] ] C:\Program Files (x86)

Is _ (single underscore) a valid C++ variable name?

假装没事ソ 提交于 2019-12-03 23:49:17
问题 With gcc 4.7.2 this compiles just fine for me: int main() { int _ = 1; return 0; } Can I expect this to compile in general? I've read the answers about underscores as prefixes. But what if the underscore isn't prefixing anything? 回答1: Yes, from The C++ Programming Language, 4th Edition: A name (identifier) consists of a sequence of letters and digits. The first character must be a letter. The underscore character, _, is considered a letter. 回答2: According to Stroustrup (3rd edition, section 4.9

Move semantic with std::function

孤街浪徒 提交于 2019-12-03 23:42:21
std::function provides a constructor from an rvalue ref. What happens to the moved function object by standard? Will it be empty so that calling it again has no effects? Under 20.8.11.2.1p6, function(function &&f) leaves f in a valid state with an unspecified value . The empty state is a valid state, so you should expect that the moved from function object can be empty. Because function performs type erasure, and function objects can be arbitrarily expensive, the optimisation to leave the moved from object empty makes sense: std::function<void()> g{std::bind{f, std::array<int, 1000>{}}}; std:

printf conversion specifier for _Bool?

和自甴很熟 提交于 2019-12-03 23:42:05
With printf() , I can use %hhu for unsigned char , %hi for a short int , %zu for a size_t , %tx for a ptrdiff_t , etc. What conversion format specifier do I use for a _Bool ? Does one exist in the standard? Or do I have to cast it like this: _Bool foo = 1; printf("foo: %i\n", (int)foo); There is no specific conversion length modifier for _Bool type. _Bool is an unsigned integer type large enough to store the values 0 and 1 . You can print a _Bool this way: _Bool b = 1; printf("%d\n", b); Because of the integer promotions rules, _Bool is guaranteed to promote to int . Until C99, bool was not

Visual C++ standards compliance [closed]

南楼画角 提交于 2019-12-03 23:41:21
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I was wondering if, and to what degree, does Microsoft's Visual C++ compiler conform to the current C (C90/C99) and C++ (ISO/IEC 14882:2003) standards. Unfortunately I'm only able to find partial information on the subject, I may be

Which gcc and g++ version support which standard of c and c++?

China☆狼群 提交于 2019-12-03 23:35:50
问题 For example, which gcc version support c99? Is there any table or graph to show the standard supported status of gcc and g++? How gcc and g++ evolved? Thank you~ 回答1: Very strictly speaking, GCC only supports C89, C++98 and C++03, all for sure since 4.3. Support for C99 is still incomplete as of yet, but a very large and usable subset has been supported by GCC for a long time. Experiemental C++11 support started with 4.3 and has been improving ever since; it's already very usable in 4.6.x,

When an array is created by a subexpression, what happens with the temporaries therein?

大兔子大兔子 提交于 2019-12-03 22:44:11
I was reading these two paragraphs of the FDIS (12.2p{4,5}): There are two contexts in which temporaries are destroyed at a different point than the end of the full-expression. The first context is when a default constructor is called to initialize an element of an array. If the constructor has one or more default arguments, the destruction of every temporary created in a default argument is sequenced before the construction of the next array element, if any. and The second context is when a reference is bound to a temporary. The temporary to which the reference is bound or the temporary that