Jump to content

Talk:C++11/Archive 5

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Archive 1Archive 3Archive 4Archive 5

Noexcept

Is it possible for the article to explain noexcept? When I heard about it, I came here to find out what it does, but there isn't even a mention. Hiiiiiiiiiiiiiiiiiiiii (talk) 15:43, 2 July 2011 (UTC)

Yes, it is possible for the article to explain noexcept. Whether someone will take the time to do so is another question ;) Korval (talk) 03:15, 3 July 2011 (UTC)

The Future of this page

The standards committee is going to meet in a few weeks, and when they do, we will likely have a C++11. This will get people looking for C++11 materials, and naturally, that means hits on Wikipedia. So, what should become of this article?

The C++11 page redirects to C++0x; the obvious thing to do is reverse that, transferring this article to the C++11 page and making C++0x go there. But my question is more about content. There was discussion about certain features getting their own page, with a link from the main page. This already effectively happened with decltype. My suggestions for the others would be things that are difficult to understand or have significant corner cases:

  • r-value references. This section is a good introduction to them, but there is lots of depth and misunderstanding to the feature. Indeed, the C++0x specification currently has lots of reference types.
  • Variadic template. This article is anemic; the section here is more detailed.
  • Uniform initialization. There are a lot of corner cases with uniform initialization.

The other thing I would like to see is a section on the C++ standard library page about the enhancements. When I originally rewrote this article a few years back, I didn't really look up the material on the standard library features coming down the line. And there are some interesting changes to some old favorites (emplace member functions, for example). Korval (talk) 09:06, 29 July 2011 (UTC)

I think that this article can be kept as a directory for diffs from C++03 to C++11 like (C1X vs C99 vs C). Moving things out has long been necessary per WP:LONGWP:TOOLONG, but not all things can be treated equally. Like you have suggested, certain C++-specific features are prominent enough to warrant a separate article (r-value references, variadic templates, smart pointers). Some others that are shared with other programming languages (type inference, lambdas, ranged-based loops, memory model) can be made a section of the page on the general topic. But it seems that these are just the exception cases. For most features, they cannot go anywhere—a brief description needs to be retained even after a move, but the existing one is brief already. Kxx (talk | contribs) 15:37, 29 July 2011 (UTC)
Hi. I'm not sure whether this edit doesn't qualify as WP:SPAM or offtopic, but anyways. FYI there's a separate third-party C++ reference wiki that specializes in a more technical description of the C++ language and standard library. The great thing is that this wiki also uses Mediawiki as the backend, supports multiple languages and most importantly, uses the same licensing as Wikipedia. I think that the material, which would otherwise be deleted for reasons such as lack of notability or too much detail, could happily live in the said wiki retaining a more concise explanation here.62.212.207.242 (talk) 19:42, 3 August 2011 (UTC)
Don't see how this is related. It is unlikely that contents of this article will be deleted. Rather, they may be just moved to other places. Kxx (talk | contribs) 04:23, 4 August 2011 (UTC)
Well, he might have a point, since often similar content is deleted citing WP:NOTTEXTBOOK and friends, as is here. However, I don't think this applies to this article also.1exec1 (talk) 22:54, 19 August 2011 (UTC)

Alignment Support

We don't mention the inclusion of alignment support in C++11 and the new keywords alignas and alignof. I think it would be worth creating a new section for this. — Preceding unsigned comment added by Ricky6565 (talkcontribs) 13:48, 19 November 2011 (UTC)

Needs work: section on Rvalue references and move constructors

Rvalue references and move constructors is opaque. I hope someone will rewrite it with examples and motivation a la Bjarne's talk at 37:08.
Encyclopedant (talk) 06:30, 6 March 2012 (UTC)

use case for "final"?

Why is it necessary to declare a member function or a whole class final? I can't see any and I cannot find any rationale in the standard. --RokerHRO (talk) 21:33, 27 December 2012 (UTC)

The standard doesn't provide rationale; it simply says what the behavior is. As for rationale, it comes from the functionality. `final` stops people from being able to derive from a class or overriding a virtual function. The rationale is that you don't want someone to derive from a particular class or override a particular virtual function. Some schools of OOP thought will decide when it is a good idea to do this. Other OOP doctrines don't believe that `final` should ever be employed. Korval (talk) 16:00, 29 December 2012 (UTC)
I know that the standard provides only a few rationals for its decisions. :-( Stroustup's books provides some rationales (especially in the "D&E" which is full of rationales and proves of not working alternatives etc.) so I must wait for C++11 versions of his books ;-()
I know what finally does, but I cannot find any good example or use case where finally is necessary or at least a very good idea.
--RokerHRO (talk) 10:14, 20 January 2013 (UTC)
Stroustrup gives kind of an answer in his C++11 FAQ: [1]. Tigrisek (talk) 12:43, 20 January 2013 (UTC)
First, it's not finally; it's final. Second, as stated, whether it is a good idea or necessary is a matter of opinion. Some people don't believe it ever is necessary. Others think you should use it for any virtual function or class you don't want someone to override later. Some would argue that if your class doesn't have a virtual destructor, you could declare the class final to prevent people from overriding it and thus potentially causing problems. It's not a simple issue; the feature is there for people who want it. Korval (talk) 01:00, 21 January 2013 (UTC)

Insert section about new __func__ identifier

Would it be worth including a paragraph about the new __func__ identifier which is defined in section 8.4.1 of the standard and was (almost exactly copied) from C99 to C++11?

This is the corresponding paragraph from the standard (citing working draft N3337):

The function-local predefined variable __func__ is defined as if a definition of the form

static const char __func__[] = "function-name ";

had been provided, where function-name is an implementation-defined string. It is unspecified whether such a variable has an address distinct from that of any other object in the program.

[Example:

struct S {
  S() : s(__func__) { }             // OK
  const char *s;
};
void f(const char * s = __func__);  // error: __func__ is undeclared

—end example ]

Keilandreas (talk) 17:19, 21 January 2013 (UTC)

{{visible anchor}} at chapter Rvalue references and move constructors

I couldn't find anything related to modifying a temporary in the guideline #15 of Sutter's "C++ coding standards" book, which is "Use const proactively". Senarvi (talk) 13:20, 4 March 2014 (UTC)

I have changed the two following redirections:

Before my change, theses pages were redirecting to {{visible anchor}} in the middle of the section text. Therefore, I was lost on the Article page, and I thought about a browser bug (I was expecting to see the chapter title). I noticed the {{visible anchor}} after this change. Actually, I do not think putting {{visible anchor}} in the middle of a section is a good idea. Because the reader expects to see the Article title or the section title, not to be redirected in the middle of a sentence. What should be the {{visible anchor}} usage? Oliver H (talk) 15:41, 28 September 2012 (UTC)

I had not thought of this when I had added those visible anchors. Your changes are a tremendous improvement. Thanks.
We could replace the visible anchors with plain (hidden) anchors, placed right before the section title. See Template:Anchor/doc.
Or we could move the description of rvalue references and move constructors to its own page. — Tobias Bergemann (talk) 17:29, 28 September 2012 (UTC)

brace-or-equal-initializer

I've read that brace-or-equal-initializers is a new feature of C++11 that allows what looks like assignments in the struct body, like this:

struct MyData{
        // Note that none of these members are static or const:
        unsigned    a = 42;
        const char *b = "";
};

I can only guess that the assignments will take place in some kind of constructor, but have yet to find the final spec on that. If this is indeed C++11, a section about it would be appreciated! 79.160.13.2 (talk) 12:20, 12 March 2014 (UTC)

Change eg. C++0x even though it redirects here?

Ellipsis (programming operator): "C++0x introduces templates with a variable number of arguments". Should C++0x be changed to C++11? There and in general? Or at least allowed? comp.arch (talk) 11:40, 2 May 2014 (UTC)

The section on move constructors has a link to a wikibooks discussion of move constructors. However, the referenced link has detailed instruction on c++03 move constructors and no extensive discussion of c++11 move constructors. This is confusing since the main article is on c++11. --2605:6000:101E:115:498E:5B25:973:56D7 (talk) 14:43, 27 June 2014 (UTC)

Does using parentheses make something into an lvalue??

Currently the section on type inference contains the following (shortened to only the relevant lines):

The type denoted by decltype can be different from the type deduced by auto.

#include <vector>
int main() {
    auto c = 0;           // c has type int
    decltype(c) e;        // e has type int, the type of the entity named by c
    decltype((c)) f = c;  // f has type int&, because (c) is an lvalue
}

I don't understand the last line at all, which should (c) have a different declared type than c? Certainly c is already an lvalue, and I don't think putting it in parentheses changes anything to that (if anything one might imagine it no longer being an lvalue, since writing something like (c)=3; looks weird, but it is perfectly legal). Is this an error, or else what should one make of this? Marc van Leeuwen (talk) 07:37, 2 June 2014 (UTC)

The answer is that parentheses make a huge difference. It's explicit in the standard for how decltype works. The rules start with "if e is an unparenthesized id-expression or an unparenthesized class member access ..." In other words, the language demands that decltype(e) and decltype((e)) be treated very differently. — Preceding unsigned comment added by 216.80.140.25 (talk) 02:24, 9 September 2014 (UTC)

42

Is there a way to evade all those 42s? See, it makes Douglas Adams' book somewhat misfortuned. The book has a lot of good stuff, yet this joke is (intentionally) silly: showing it above anything else makes great disservice to the series. That is not to mention that to repeat jokes many times is always silly, and to do this outside of the proper context even more so: I think that Mr. Adams did have more things to say and imply that we who repeat the joke do. As a conclusion, I think that this repetition is stylistically improper and raises the feeling of bad taste; may I change it for something more neutral, like 3, 11, or 24?.. - 91.122.0.110 (talk) 17:04, 18 August 2014 (UTC) @91.122.0.110: You don't need permission to change something like this. Just change it and state your justification. Spinlock55 (talk) 22:44, 27 February 2015 (UTC)

Ref-qualifiers not listed

There is a new feature in C++11 that isn't listed on this page, adding ref-qualifiers to member functions.

i.e.

class A
{
public:
  void LvalueOnly() &;
  void RvalueOnly() &&;
};

A().RvalueOnly();
A a;
a.LvalueOnly();
a.RvalueOnly(); //bad call

Paper: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2439.htm

50.35.73.36 (talk) 23:10, 15 May 2016 (UTC)

References to C++03 language

I disagree with the comparisons to a "C++03" language in the article. AFAIK there has never been such a thing, and no compiler have ever supported a C++03 version of C++. They have supported C++98 until the switched to the next version of the core language C++11. There was no changes to the language itself in between, only errata to the C++98 standard.Carewolf (talk) 13:49, 31 May 2016 (UTC)

Then what is this: http://www.iso.org/iso/catalogue_detail.htm?csnumber=38110 which is titled ISO/IEC 14882:2003 Programming languages -- C++? Do they publish an entirely new standards document just to handle errata?
franl | talk17:54, 18 December 2016 (UTC)