Talk:C++11: Difference between revisions
Auto~enwiki (talk | contribs) →Concepts: moved to new name |
70.90.174.101 (talk) →C++1x?: new section |
||
Line 619: | Line 619: | ||
Article moved from [[Concepts (C++0x)]] to [[Concepts (C++)]] per above. <tt>[[User:Auto|auto]] / [[User:decltype|decltype]]</tt> ([[User talk:Decltype|talk]]) 12:36, 23 July 2009 (UTC) |
Article moved from [[Concepts (C++0x)]] to [[Concepts (C++)]] per above. <tt>[[User:Auto|auto]] / [[User:decltype|decltype]]</tt> ([[User talk:Decltype|talk]]) 12:36, 23 July 2009 (UTC) |
||
== C++1x? == |
|||
I guess you'll all have heard that the new standard is delayed to 2010 or later.[http://tech.slashdot.org/story/09/07/23/1817225/Stroustrup-Says-New-C-Standard-Delayed-Until-2010-Or-Later] |
|||
It's funny, I didn't realize until last night that the 0x in C++0x was a partially instantiated year number, like C++93 and so forth. I'd thought it was a reference to C/C++'s syntax for hexadecimal constants, just like the ++ in C++ is a reference to C's increment operator. [[Special:Contributions/70.90.174.101|70.90.174.101]] ([[User talk:70.90.174.101|talk]]) 19:02, 23 July 2009 (UTC) |
Revision as of 19:02, 23 July 2009
Computing Start‑class High‑importance | ||||||||||
|
C/C++ Unassessed | ||||||||||
|
undefined proposals
This article talks about yet to be defined proposals for certain features. the commitee does not accept any proposals other than those outsources from current proposals (as they are better handled as single proposals). therefore some of these features mentioned here are definetly not to be added to C++09. Also some of the features mentioned here will (if at all) only go into TR2 which will be *after* C++09.
Rewrite
The article is riddled with typoes and strange terminology. I fixed a few, but the task is daunting as many of the sentences are difficult for me to undestand what they were meant to say (although I can guess a few, My knowledge in the subject is limited, so I won't even try). --M.A. 21:02, 24 November 2006 (UTC)
- Yes, I'm sorry for my bad English. If you take my some examples of incomprehensible text, we could try to fix it. NOTE:
bernoulli_distribution
andpoisson_distribution
are lowercase, as they are been defined by "ISO/IEC DTR 19768 (June 24, 2005) Doc No: N1836 Draft Technical Report on C++ Library Extensions".--Gildos 19:13, 26 November 2006 (UTC)
- Your contribution is appreciated and the article does treat much (everything?) of the proposal as of now! I applaud the effort you've put into it! Still, though, Acolyte of Discord's comments remains valid: the article is in need of thorough copy-editing since the language is partially only semi-grammatical resulting in ambiguous propositions, unnecessarily convolute constructions, statements reading as POV, and an often awkward read. Unfortunately, I too dare not touch it since I'm not familiar enough with the topic and fear that I might introduce untruths, which would be worse than problematic language. Mikademus 18:17, 27 November 2006 (UTC)
- The article doesn't treat everything of the proposal but only principal features, as you can see here and in the Technical Report 1 --Gildos 19:28, 27 November 2006 (UTC)
- Your contribution is appreciated and the article does treat much (everything?) of the proposal as of now! I applaud the effort you've put into it! Still, though, Acolyte of Discord's comments remains valid: the article is in need of thorough copy-editing since the language is partially only semi-grammatical resulting in ambiguous propositions, unnecessarily convolute constructions, statements reading as POV, and an often awkward read. Unfortunately, I too dare not touch it since I'm not familiar enough with the topic and fear that I might introduce untruths, which would be worse than problematic language. Mikademus 18:17, 27 November 2006 (UTC)
- I have done quite a bit of copyediting of the article today to clean up some of the awkward wording. However, there were some sentences I simply couldn't parse. In particular, in the "Extensible random number facility" section, I have no idea what "Apparent casualness is due only from limited perception of users" means. If anyone can figure that out and reword it, it would be a help. Julesd 03:41, 8 July 2007 (UTC)
- Maybe they meant "causality" not "casualness"? Alternately, maybe they meant that rand() seems simple (and good enough) to users only because users don't fully understand the complicated nature of RNG/distributions? I also find it hard to understand the original meaning 24.17.110.123 11:26, 18 August 2007 (UTC)
Aspect Oriented Software?
Won't the new version of C++ include AOS (Aspect Oriented Software)? (This is more a wish than a discussion).
- Not according to this document, but I'm not close enough to the topic to say for certain. --Gabriel "Jarl" Sjoberg 07:38, 2 January 2007 (UTC)
Strange paragraph
This concerns a paragraph which I (EatMyShortz) deleted:
- I have referenced now the piece of article you have deleted. The document is The Design of C++0x: Reinforcing C++’s proven strengths, while moving into the future at the paragraph of Design and Evolution. If you find unreferenced parts use comments or the discussion page like the other user please. I am available to clarify all your doubts about this article. --Gildos 19:41, 8 January 2007 (UTC)
- Hi Gildos. Well I found the paragraph which was paraphrased in the above article. However, just because it's referenced doesn't give it a neutral point of view. This article is an opinion piece, written by the language's author. The statement (and the paraphrased version of it here) is basically a sweeping opinion of one language designer, about language design in general, as well as a prediction of what "will" provide the greatest benefits. It has no specific relevance to C++, and is non-encyclopedic. Therefore, I am removing it again. Please don't add it back unless you have a specific reason for it to be here. (And if you must revert, please do so to my previous version, where I added a link in the reference). —EatMyShortz 11:34, 10 January 2007 (UTC)
You can trust or don't trust it, but it is not the point of view of one language designer, it is a line guide of the C++ Language Committee. If you don't like the way it was writed,rewrite it please. Deletion is a bad solution. --Gildos 14:53, 10 January 2007 (UTC)
Do you prefer this way?
- The designers of a language can be obsessed with notation problems of small relevance, neglecting more meaningful language features that may allow new programming styles to develop. The C++ Language Committee believe that a good feature provides a direct response to a problem; it does not significantly interact with other features of the language and typically has a reduced logical expression, leading to concise portions of code. The greatest benefits will come from solutions that allow the programmer to resolve a problem and to better organize the code, as happened with the introduction of object-oriented programming and generic programming (templates).
I'm waiting the opinion of other users. --Gildos 14:53, 10 January 2007 (UTC)
"It has no specific relevance to C++, and is non-encyclopedic."
You must be joking, sir. Either that, or you really have no idea how the committee works. BS's opinion is extremely respected. Of course it's not just his "baby", he can't decide anything alone.
But throwing away BS's text like that is silly. It's obviously relevant to C++ and obviously encyclopedic.
I think you are just trolling. Find another game, please.
--212.27.60.48 (talk) 07:44, 11 February 2009 (UTC)
I did what I could to rewrite the section about smart pointers, but I wasn't sure what to say about the weak_ptr template, since I can't figure out why that would be used instead of a regular pointer, if what I googled about the topic was any use. Using my own judgement, the only purposes of a weak_ptr would be to prevent the implicit/automatic destruction of objects, or have a reference that would be automatically nulled when the owner was destroyed, but I couldn't find any evidence for either theory.--Prgrmr@wrk 07:22, 23 January 2007 (UTC)
- The main goal of the weak pointer is to reference an object without influence its cicle of life. Garbage Collection is not provided in the proposal of General Purpose Smart Pointers as you can see in A Proposal to Add General Purpose Smart Pointers to the Library Technical Report (Revision 1).--Gildos 11:40, 23 January 2007 (UTC)
- A regular pointer is just a pointer to an area of memory - after the object it is pointing to has been deleted, the regular pointer will still seem fine to the naive user, but will be pointing to god-knows-what. A weak_ptr has no effect on the existence of the object it is referring to, but it does know when the object has been deleted, and prevents the user from accessing it thereafter.
Indeed, they are very few uses for weak_ptr. And for the few cases where they can be used, it's usually suboptimal.
Most people who pretend weak_ptr is extremely useful simply don't understand anything about smart pointers; they confuse them with gc (as in Boehm gc) where every normal pointer (T*) is followed by the gc system and is thus a strong pointer.
Most examples of use of weak_ptr are totally bogus. It's frighting! I have been (almost) kicked of a forum for saying that weak_ptr wasn't that useful! --212.27.60.48 (talk) 07:38, 11 February 2009 (UTC)
Article is now out of date
The Portland meeting in October 2006 established what will be the main additions to C++0x. Many items that were originally considered for inclusion (and mentioned in the current article) are now no longer so considered. A good overview of the Portland decision was written up by Herb Sutter here.
Daveed V. 22:12, 15 February 2007 (UTC)
- I've replaced the dispute template with {{update}}, which is more specific and looks better. Hairy Dude 17:59, 24 April 2007 (UTC)
- yeah okay this does not change that 80% of that article is entirely made up see also http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2007/n2228.html
- I've read much of the stuff in from the n228.html webpage, and I have a pretty good handle on what C++0x is shaping up to be. I'm willing to take some time to rewrite the article, but I have a few questions about how to do it (with appropriate citations).
- Should I make any attempts to specify how likely one feature is to be added to the final C++0x spec? Should I make some effort to categorize the new features, or should I just list them one (perhaps alphabetically)? Korval 01:58, 30 May 2007 (UTC)
- Be bold! Do what you feel would be best for the article. However as a suggestion, the more details (with app cite) you can provide the better, avoid just a list of items. KTC 09:03, 12 June 2007 (UTC)
2.4.2 Lambda Expression
It says that "As a shortcut, closure variables refering to local variables can be defined as:" and then comes the following code:
int total = 0; <>(x: &total) {total += x}
Which should be equal to
int total = 0; <>(x: auto &total = total) {total += x}
I was wondering if not the ":" should be a comma (","), so the code should be
int total = 0; <>(x, &total) {total += x}
and
int total = 0; <>(auto x, auto &total = total) {total += x}
81.233.131.203 19:57, 10 September 2007 (UTC)
- No, the ':' is there to separate parameters to the lambda from references to variables outside the lambda. 'x' is a parameter, 'total' is a local variable that is referenced by the lambda code. The '&' means that the lambda closure will contain a reference to the local variable 'total', it could be done without the '&' as well in which case the closure would have it's own copy of the variable (and the whole lambda would be a no-op).
- 213.100.20.12 02:21, 12 October 2007 (UTC)
Article is Too Long
The article has been flagged as too long. Granted, this is probably meaningless because most people who might be inclined to shorten it can't understand and properly summarize the material. So there isn't much worry about the lay person coming along and ransacking it. However, it is very long. Should we make some of the sections smaller, turning some of the detailed explanations into summaries? Korval (talk) 19:11, 27 December 2007 (UTC)
- When I start to write this article, I planned that in 2009, at the release of new C++ standard, it will be split in many sub article one for every utilty like other existing utilities of actual C++. I think this is the right way to split this article. At now every new article should be an upcoming software and the article C++0x will be a summarise of all the modifications. It's no so simple, because references may be split for every article. If the community like this way of splitting I start to do that, with the hope that no new article will be deleted. --Gildos (talk) 02:38, 29 December 2007 (UTC)
On the wrapper reference
The example used to motivate the introduction of wrapper references is:
// This function will obtain a reference to the parameter 'r' and increase it.
void f( int &r ) { r++ ; }
// Template function.
template<class F, class P>void g( F f, P t ) { f(t) ; }
int main()
{
int i = 0 ;
g( f, i ) ; // 'g<void ( int &r ), int>' is instantiated
// then 'i' will not be modified.
cout << i << endl ; // Output -> 0
g( f, ref(i) ) ; // 'g<void(int &r),reference_wrapper<int>>' is instanced
// then 'i' will be modified.
cout << i << endl ; // Output -> 1
}
Won't we achieve the same effect by simply defining g with the second argument as a reference, like this:
template<class F, class P>void g( F f, P& t ) { f(t) ; }
Jorram (talk) 12:07, 16 January 2008 (UTC)
- You 're in right but withyou cannot decide if parameter t will be modified or not. Every intallation of template g will modify the parameter. Remember, it's only a stupid example. Bye. --Gildos (talk) 12:39, 19 January 2008 (UTC)
template< class F, class P > void g( F f, P& t ) { f(t) ; }
- Equally importantly, what if you don't have control over g's definition? For example, Boost.Bind/TR1.Bind can't take references as parameters to be bound to functions, because that's how it is defined. It has to take reference wrappers if you want to pass a reference. In many ways, it exists for the same reason that something like TR1.Bind does: so that you can do something with someone elses code that would otherwise be syntactically impossible. Bind can turn a multi-parameter function into a function of 1 parameter suitable for use in a standard algorithm. Reference wrappers turn a copy-style template parameter into a reference-style parameter. All without having to change the actual interface itself.Korval (talk) 02:51, 22 January 2008 (UTC)
Color tags for c++0x/TR2/abandonned
It would be useful to add an icon or a color tag or something else to easily see what will be available in C++0x, what would be available for the next revision (TR2?) and what is abandoned (if any in this page). As I'm not a specialist (about the subject and about wiki edition standards), I'll do it myself now, but maybe will try in some weeks if i found time and energy to parse the last reports. Klaim (talk) 00:26, 20 February 2008 (UTC)
- Nothing on this page should be anything that has been specifically remanded to a future TR or language revision. Everything on the page should be exactly what is expected to be in C++0x. If, as standardization approaches, something is remanded to later revisions, then it should be removed from this page, not color coded. Korval (talk) 00:46, 20 February 2008 (UTC)
- Then i guess the garabage collector part should be removed? MJKlaim (talk) 01:08, 20 February 2008 (UTC)
Initializer lists to initialize std::vector?
This paragraph in the initializer list part suggest that a container like a std::vector cannot be initialized by an initializer list:
Standard C++ allows this on structs and classes, except that these objects must conform to the Plain Old Data (POD) definition; non-POD classes cannot use initializer lists, nor can useful C++-style containers like std::vector and boost::array.
note from --Lightness1024 (talk) 21:50, 22 April 2009 (UTC) : I don't know where this quotation comes from, but the last part is false to my knowledge. In current C++ standard and boost implementation, array is an aggregate and can be initialized with init-list. notably, this form is correct
boost::array< int, 2 > a = {{1, 2}}; // initializes the elems[N] (only) member.
boost::array< int, 2 > a = {1, 2}; // acceptable too according to boost documentation. compiles with a warning on g++4.
end note.
For example:
std::vector<int> v = { 1, 2, 3, 4 };
I think that this is wrong. A non-pod can be initialized, but cannot be part of an initializer list, eg:
std::vector< std::vector<int> > v = { std::vector<int>({10, 11, 12}), std::vector<int>({13, 14, 15}) };
So the first would be correct in C++0x, the second code ill-formed. Should the paragraph be changed to make that clear?
213.196.194.249 (talk) 22:08, 4 May 2008 (UTC)
Technically, both the first and second would be valid C++0x (there's still some dispute with regard to uniform initialization). However, the paragraph wasn't talking about C++0x yet; references to "Standard C++" mean "C++03". Korval (talk) 05:38, 5 May 2008 (UTC)
Name conflict resolution on concept maps
My doubt is the concept version of inheriting from two classes which have a common member name.
Suppose I write a template with one type as parameter, and which requires that type to satisfy two concepts (hence using the generalized notation):
template<typename T> requires Concept1<T>, Concept2<T>
void f(T x) {
...
}
Now imagine both concepts consist, e.g., on having a typename defined:
concept Concept1<typename T>
{
typename pointer;
//...
}
concept Concept2<typename T>
{
typename pointer;
//...
}
And as none of the concepts is "auto", they must be satisfied by explicit concept_maps. Now both concept_maps may have to define different things for the typename "pointer":
concept_map Concept1<MyClass>
{
typedef char* pointer ;
};
concept_map Concept2<MyClass>
{
typedef int* pointer ;
};
If inside of my template function (f) I try to use T::pointer, and I have specialized T to MyClass, the compiler won't be able to resolve which one I want (either char* or int*). Is there a way to specify to which concept I refer when writing ::pointer? (IIRC, when faced with the analogous problem on inheriting from two classes, one could use the sintax base1::member and base2::member to distinguish between them.) -- User:Euyyn —Preceding unsigned comment added by 212.0.110.2 (talk) 18:23, 17 July 2008 (UTC)
- That's an interesting issue. However, this is not a discussion forum for how C++0x will work in specific detail. Please see the PDF article on concepts for further details.
- That being said, I'm guessing that it would be erronous to do what you say. That is, if concept mapping is to be used, each constraint on the template must resolve to the same concept map. Korval (talk) 02:20, 18 July 2008 (UTC)
Delete 5.6 Uniform Function Syntax
In private correspondence with an influential member of the standards committee I'm told that "the 'uniform function syntax' is not part of C++0x and IMO is unlikely to become one." 24.5.238.80 (talk) 21:11, 27 July 2008 (UTC) Jon Kalb
OnlyInt question and possible suggestion.
Hi, I read this part of the article:
struct OnlyInt
{
void f(int i);
template<class T> void f(T) = delete;
};
and that made me wonder if this would work:
template<class T>
struct OnlyInt
{
void f(T) = delete;
void f(int i);
};
OnlyInt<int> x;
x.f( 5 ); // Valid?
I guess the question is whether f(int) or f(T) will get called, and if f(T) is called, maybe that should be noted. I tried to test this, but void f(T) = delete wouldn't compile with GCC (as expected).
Thanks in advance. Posted by SoC (talk) -- Posted at: 20:31, 11 August 2008 (UTC)
- This isn't valid, because the specialization
OnlyInt<int>
contains two identical function declarations. Note that in the example,OnlyInt
is a class, not a template, and the deleted function is a member function template. In this caseOnlyInt().f(5);
is valid, and that's the entire point of the example (that a normal function is a better function than a function template specialization when there is no conversion involved). decltype 09:39, 2 February 2009 (UTC)
Removal of User-defined Literals Section
User-defined literals were last described in N2378 (8/1/2007) but were not included in the draft N2606 (5/19/08). They are also not listed on GCC's C++0x features to implement, which, while it shouldn't be taken as authoritative, is probably a good indication that its not considered a feature that's likely to go into the final standard. Since there is supposed to be a new working draft coming in October, if that draft should include user-defined literals, the section can be reinstated, but to me right now it looks like they've been turned down.
--98.232.203.240 (talk) 06:12, 26 August 2008 (UTC)
- That logic is not sufficient to remove that section of the page. The GCC status update only includes functionality that has been voted into the working draft. Concepts are not on that list, despite the fact that WG21 is adamant about getting concepts in C++0x. Concepts are also not in the working paper, which will happen fairly soon. So just because something isn't in the working draft yet doesn't mean it shouldn't be presented on this page. The next meeting should tell us whether extensible literals make it or not, so keeping it around for a month won't hurt anyone. Korval (talk) 02:08, 27 August 2008 (UTC)
- User-defined literals are currently in the working draft, N2798. It's section 13.5.8. --Snaxe/fow (talk) 16:18, 20 April 2009 (UTC)
Expected release date?
Is there any estimate of a release date? Are we looking at 2009 or 2010? Or later? Might be good to include if there's a source. 71.244.5.124 (talk) 23:02, 31 October 2008 (UTC)
- As the standard is called C++0x, it was supposed to be released at most in 2009. 90.39.68.35 (talk) 07:40, 4 April 2009 (UTC)
Property
Nice stuff but why we don't have anything to define properties????
null pointer constant (not "null pointer"!)
There are many very significant and sadly common errors in this section. This is shows a superficial understanding of C++.
null pointer constant (not "null pointer"!)
A null pointer is a possible value of a pointer:
int *p = 0;
if (!p)
std::cout << "p is null pointer\n";
A null pointer constant is an expression (used to set pointers to the null pointer value). It is not a value. (An expression is a part of the program source, while a value exist at runtime - except for some compile-time values of integral or pointer type.)
In C++98, a null pointer constant cannot have pointer type.
The whole section is about null pointer constants not null pointers. There is no change in C++ with null pointers.
integer vs. pointer
- The statement foo(NULL); will call foo(int), which is almost certainly not what the programmer intended.
- Since the dawn of C in 1972, the constant 0 has the double role of constant integer and null pointer.
No. 0 is not a null pointer, it isn't a pointer; it's integral constant expression.
It's very important not to confuse programmers about the fundamental fact that: The expression 0 never has a pointer type in either C or C++.
In either language, any expression (given a set of declarations of course) has only one type. For the expression 0 the type is always int, end of story.
That you can write :
void foo (int*);
foo (0);
doesn't mean the expression 0 suddenly has type int*, just as 1 doesn't has type float in the following:
void foo (float);
foo (1);
- the preprocessor macro NULL, which expands to either ((void*)0) or 0.
...or OL or ((short)0) or (2*2-4) or ((void*)(2*2-4)) or any integral constant expression (compile-time computed expression with type char, short, int, long, unsigned char...) with value 0, or any such expression casted to void*.
However, the only two common choices in C are 0 or ((void*)0).
- When C++ adopted this behavior, additional ambiguities were created due to other design decisions in C++. Implicit conversion from type void* to other pointer types is not permitted, so NULL must be defined as 0 in order for statements like char* c = NULL; to compile.
No, this is unrelated and a deep mistake (and BS made confused statements about it).
In either C or C++, an integer (an arbitrary expression with integral type) isn't convertible to a pointer :
int i = 0;
int *p = i; /* error in both C and C++ */
int *q = 0; /* ok */
but the expression 0 is convertible to a pointer, because it's a null pointer constant.
So it's only a matter of how null pointer constants are defined. Had C++ (BS) defined ((void*)0) as a null pointer constant, the following would be valid:
int *p = (void*)0;
BS didn't made this choice, the committee didn't revisit his decision, but to say this was about converting void* to T* is dishonest. It was and is only about the definition of null pointer constants.
Overloading
void foo(char *);
void foo(int);
- The statement
foo(NULL);
will callfoo(int)
, which is almost certainly not what the programmer intended.
Not so fast! Only true if NULL is defined as 0 or (2*2-4) or ((short)0).
If NULL is defined as 0L, for example, the first function will match with a pointer conversion (long -> char*), and the second with an integer conversion (long -> int); both implicit conversion sequences have conversion rank, and none is better than the other. As no match is better than all others, the call is ambiguous.
C++ compilers usually simply define NULL as 0 but they don't have to according to C++98 or C++03, so the statement needs to be qualified properly.
Deprecation
- If the new syntax is a success, the C++ committee could declare deprecated the usage of
0
andNULL
as null pointers, and eventually abolish this double role.
Very funny indeed!
- This is Wikipedia. If you have found errors, feel absolutely free to correct them. You don't even need an account. Korval (talk) 22:52, 11 February 2009 (UTC)
- Yes, the wording of the null pointer section was in fact problematic. I think it looks ok now, unless one wants to get extremely pedantic. For example, while 0 is an integer constant in C, it is an integer-literal in C++. —Preceding unsigned comment added by Decltype (talk • contribs) 07:20, 12 February 2009 (UTC)
- Alright I made a large edit on this section. I think I addressed all the issues outlined. --Snaxe/fow (talk) 17:47, 20 April 2009 (UTC)
Current status of this issue: resolved.
better example for move semantics?
"For example, a std::vector is, internally, a wrapper around a C-style array with a size. If a vector temporary is created or returned from a function, it can only be stored by creating a new vector and having it copy all of the R-value's data into it. Then the temporary is destroyed, deleting its data."
This example is just stupid, because copy-on-write makes the trick right now in old C++. I don't see the point of the move stuff from it... 192.100.124.218 (talk) 14:20, 16 March 2009 (UTC)
- COW will work until you start changing the vector. Consider a function append that takes a vector, appends an element to it and returns the new vector. In COW, it will copy the whole vector every time you execute push_back, even if the original vector is temporary and you don't care about preserving its contents. With rvalue reference, no copy will be done if a temporary is passed, so you can write like this: append(append(append(std::vector<int>(),1),2),3); and there will be no copies made. Try to achieve this with COW. Enerjazzer (talk) 00:40, 12 June 2009 (UTC)
- I was under the impression that a copy-on-write implementation of std::vector would be near-impossible to make. Consider the fact that a user can obtain a pointer to an element of the vector at any time using either
&v[n]
or &*iter
. This pointer must remain valid until a reallocation or an insert in front of the pointee takes place. The same applies to iterators and references. I don't see how an efficient COW implementation can preserve these semantics. Perhaps you were referring to return value optimization, which will probably eliminate the copy in the quoted example decltype (talk) 15:24, 16 March 2009 (UTC)
- I dont see your point. COW is about copy data only if necessary. Pointers and iterators will stay valid for the current container, even if another one (which refers to the same array) makes some writing: cow will cause that it will be than reallocated and copied, but the pointers and iterators will point to the original. In assigments what you change is only a pointer, returning from a function is an assigment (if there is anyone who wants to use the return value).
- Consider the following example:
#include <vector>
using std::vector;
int main()
{
vector<int> v1(1000); // holds 1000 ints
const vector<int> v2 = v1; // uses COW - no deep copy made...
const int * p = &v2[42]; // ...but the vector *must* be copied here,
// even if no "writing" takes place....
vector<int>().swap(v1); // Otherwise, the pointer p is invalidated here
}
In this case, const int& operator[] will be called, so the compiler can assume you wont do any writings. If you get the adress of a const&, its up to you if you want to write on it, so no copy will needed. Im not even sure you can get the address of a const with a non-const-pointed pointer. But this is considered hacking in my terms... 192.100.124.218 (talk) 12:51, 17 March 2009 (UTC)
- No, a copy has to be made even after a call to a
operator[] const
. Even something like int i = *p;
would have undefined behaviour if no copy was made. decltype (talk) 13:06, 17 March 2009 (UTC)
- Otherway, i dont understand you. If you swap the v1 with an empty vector, what does that to make with p? v2 will hold the area, and the unnamed vector too, till the end of the scope. p is not invalidated... 192.100.124.218 (talk) 08:30, 20 March 2009 (UTC)
- No, the unnamed temporary is destroyed at the end of the full-expression, not the enclosing scope. The following example demonstrates the same, but is less subtle:
#include <vector>
using std::vector;
int main()
{
vector<int> v1(1000); // holds 1000 ints
const vector<int> v2 = v1; // uses COW - no deep copy made...
const int * p = &v2[42]; // p actually points into v1, since they share the buffer
v1 = vector<int>(); // frees the memory held by v1. p is invalidated
int i = *p; // dereferencing invalid pointer!
}
- No, the line v1 = vector<int>(); wont free the memory used by v1, because v2 still points to it. v1 knows that someone else points to its buffer, so wont free it. 192.100.124.218 (talk) 12:05, 20 March 2009 (UTC)
- Try this example:
vector<int> v1(1000), v2 = v1;
const vector<int> &cv1 = v1, &cv2 = v2;
const int *p = &cv1[42], *q = &cv2[42];
v1[42] = 17;
if (*p == *q) {
// error
} else {
// ok
}
- Can a COW implementation deal with that? -- BenRG (talk) 12:25, 20 March 2009 (UTC)
- Well, if it makes a copy even for operator[] const it should...but that wouldn't be copy-on-WRITE. Which is what I was trying to prove, but failed :) decltype (talk) 14:38, 20 March 2009 (UTC)
- I dont see the point in the example. Lets see what happens. v1, v2 points to the same area on the first line. You give other, const names for v1 and v2, doesnt really matters. You point to the common area with 2 vectors. After that, you change a vector what should be considered const. Do you see my problem with that? C++ is not so hard to hacked, its in the language to give you opportunities. You can always write a const variable with some extra effort, but than the responsibility is on you. Here the v1[42] call is not the const one (obviously), so there will be copy made. Obviously. Iterators/pointers invalidated. Obviously. What did you proved here? Maybe you are right, but i really dont see :( 192.100.124.218 (talk) 15:22, 20 March 2009 (UTC)
- Non-const std::vector<T>::operator[] can't make a copy because it's not allowed to invalidate pointers into the vector. (To put it another way, my example doesn't invoke any undefined behavior.) Non-const std::string::operator[] does invalidate pointers into the string; they made that provision specifically to allow copy-on-write implementations of std::string. But there's no such provision for vectors.
- (Even if vectors had been defined differently, the copy-on-write approach would reduce the cost of vector moves but increase the cost of every non-const vector operation. Move semantics reduces the cost of vector moves without any downside.) -- BenRG (talk) 19:34, 20 March 2009 (UTC)
- They at least considered removing the possibility for cow strings for concurrency reasons, N2668[[1]] - and as such I would suspect cow vectors would fare no better. I do not know how to find out if this was accepted or trashed, though. --84.209.14.149 (talk) 14:56, 26 March 2009 (UTC)
- Look, it doesn't matter if a COW implementation of std::vector would be the effective equivalent of what you get with std::move. The fact is that std::move is useful for far more than just the std::vector example. std::auto_ptr, for example, benefits greatly from it, as do similar RAII structures. Even std::shared_ptr passing will be faster, since you don't have to bump a reference count and then decrease it again after the temporary is destroyed. The std::vector example is an easily understood one, which is why I choose it, but it is hardly the definitive value of std::move. The solution to the forwarding problem alone is justification enough for it. Korval (talk) 18:38, 20 March 2009 (UTC)
- I agree. It's a good example, and one of the most oft-cited. Still, in the trivial case, RVO would take precedence and eliminate the copy/move. I also very much like the fact that you can store movable objects like streams in a vector, because of RR. It's a very visible change that you don't have to understand RR at all to benefit from. Of course, for full benefit you'd have to know how to make your own objects movable. decltype (talk) 20:09, 20 March 2009 (UTC)
Would rvalue references warrant an own article?
Per the above, and the fact that there's much more to be said. Move assignment isn't mentioned at all, and much could be said about how move ctors and move operator= are defined. Examples of perfect forwarding could also be shown. At the same time the main article is getting very large and difficult to navigate. decltype (talk) 20:09, 20 March 2009 (UTC)
- I think they do. This article is truly very looooooooooog. It looks pretty bad to stuff more about move semantics and perfect forwarding here.—Kxx (talk) 06:13, 23 March 2009 (UTC)
- Hey, thanks for explanation, i think i got it. And agree: it would worth an article. 192.100.124.218 (talk) 10:30, 23 March 2009 (UTC)
- The idea was that, once C++0x is a finalized spec, we would break the important and complex sections (rvalue-references, concepts, etc) into their own separate pages. There is certainly enough material to warrant having its own article, but I'm not certain that we should have multiple articles based on something that isn't yet final. Korval (talk) 01:18, 24 March 2009 (UTC)
- I don't see much problem in moving rvalue references and alike out. We can leave 100–200 words here to briefly introduce these concepts and refer whoever is interested to their own articles using Template:Main. Doing so gives the immediate benefit of shortening an article that is already WP:TOOLONG. We can assume a bold attitude despite everything is not yet finalized. Given the standard committee's adamant position in avoiding C++0a, C++0b, …, chance is presumably small that drastical changes would occur. As long as we don't go into too much detail here, we are most likely safe to have separate articles on subjects worth elaboration.—Kxx (talk) 03:51, 24 March 2009 (UTC)
- If you insist, you can move it to a new article. But you should also move Concepts to a new article as well. Maybe even variadic templates. Korval (talk) 22:52, 25 March 2009 (UTC)
- variadic templates already have their own article..but it looks very sandbox-y at the moment. decltype (talk) 06:28, 26 March 2009 (UTC)
- Yes, that article was originally created because I removed someone's original research proposals for Variadic Templates, so they moved it to another page. I'd be totally fine with that page being improved. Korval (talk) 19:02, 26 March 2009 (UTC)
- Rvalue references probably should go into Reference (C++). But that article itself may need some overhaul in the first place. I can't tell what exactly is wrong with it. It just looks unnatural to me, and immediately merging rvalue references into it seems to make things worse.—Kxx (talk) 20:17, 26 March 2009 (UTC)
- Hmm..I didn't even know about that article. It could use some improvement. decltype (talk) 06:33, 27 March 2009 (UTC)
- Concepts have their own article, too.—Kxx (talk) 04:39, 28 March 2009 (UTC)
Almost 100% compatible?
What does it mean? If it's almost 100% compatible it's by definition not 100%. I think that sentence is pretty stupid. 159.149.106.5 (talk) 09:36, 20 March 2009 (UTC)
- I agree, but that's what the man said :). Of course, there will be subtle differences in semantics, and some old code will be broken due to the addition of new keywords, among other things. decltype (talk) 09:43, 20 March 2009 (UTC)
- I think almost 100% means 80% or 99%, depends on metrics we use. I dont see the stupidity. Though im not native speaker (or in this case writer) of english, so. 192.100.124.218 (talk) 10:51, 23 March 2009 (UTC)
- Well, neither am I, nor Bjarne Stroustrup himself. But since it's his exact quote, I don't see the problem. decltype (talk) 11:52, 23 March 2009 (UTC)
- I have put the exact phrase as Bjarne Stroustrup wrote in quotation marks. So let him take any applause or blame for his own words. —Kxx (talk) 19:43, 23 March 2009 (UTC)
- I don't understand the problem with the wording myself. The phrase "almost 100%" means exactly that: almost 100%. By definition, as you say, it is not 100%, but very close to it. That is a good description of the number and potential problem of the backwards compatibility issues that C++0x provides. In short: you might need to change a couple of lines of code, but it's nothing you should worry about. Korval (talk) 22:49, 25 March 2009 (UTC)
axioms
I am a bit surprised to see that axioms are not mentioned at all. They are mentioned on Bjarne Stroustrup's webpage: http://www.research.att.com/~bs/C++0xFAQ.html#axioms —Preceding unsigned comment added by 193.254.175.108 (talk) 09:31, 25 March 2009 (UTC)
- Yes, axioms are an interesting concept (pun intended), that will almost surely be in the new standard. Definitely worth a mention. decltype (talk) 09:43, 25 March 2009 (UTC)
- Axioms are not mentioned because they are not a part of the working draft, nor are they a part of any proposals on the table for discussion (as listed here. Until they are, they should not be discussed in this article.Korval (talk) 22:46, 25 March 2009 (UTC)
- N2857, the working draft dated Mar 23, has axioms under 14.10.1.4. N2800 also had them, but under 14.9.1.4. Does that justify a mention here?
- By the way, what precisely does the word "report" refer to in the last sentence of the opening paragraph? A working draft or a document of some other sort?—Kxx (talk) 23:38, 25 March 2009 (UTC)
- Yes, axioms has been in the draft since concepts were added (N2798), since they were part of the concepts proposal. Apparently, the shift in numbering was to make room for another section on exported templates. Such changes are more or less expected since it's a draft. decltype (talk) 06:25, 26 March 2009 (UTC)
- I have created Axioms under Concepts (looks pretty odd in the table of contents as the only subsubsection), using an example copied from N2857. I am thinking about furthering the example to show how axioms actually work. SGI STL's power algorithm seems to suggest some idea. But I am not sure about the details yet.—Kxx (talk) 23:12, 26 March 2009 (UTC)
C++0x -> C++1x
Seeing as how the next standard will not be out this year (2009), maybe this article should be moved to C++1x. If anyone is opposed, speak now or forever hold your peace. If I remember, I'll move the article in a week if there are no objections. --Snaxe/fow (talk) 21:38, 8 April 2009 (UTC)
- Countervote from me, too. As long as the committee says C++0x, I say that, too. And, as far as I know, nobody ever defined the underlying numerical base for 0x. It could also become C++0xA or C++082 (octal 10). Out of curiosity, Snaxe920, where did you see that it won't come out this year? Phresnel (talk) 14:22, 14 April 2009 (UTC)
- Hmm I heard wrong. According to N2870, they're still aiming for the end of this year. --Snaxe/fow (talk) 23:51, 14 April 2009 (UTC)
They definitely aim for end of 2010. I, for myself, call it c++1x aswell as (who? People of ##c++ and ##iso-c++ in freenode) other people too. But i agree, it would probably be better to keep the name "C++0x" in this article. Not all names are logical, after all :) I created a redirect from C++1x to this article, though.
(and yes, Standard names follow decimal patterns - not hex or anything like that - like "C++98" and "C90". Note how there is even made a difference between C89 and C90). Litb me (talk) 18:53, 17 April 2009 (UTC)
- Nevertheless, IRC channels are not reliable sources. I have yet to see one that uses the term C++1x. That's not to say they don't exist, but they sure are under-represented. decltype (talk) 19:12, 17 April 2009 (UTC)
- See this: [5] (page 17) and this [6] (page 2). However, i agree most people call it C++0x. What i want to say is that the name that should be taken is C++1x, if at any day one decides to change the name of the article - and that it's not just one of those many other "fantasy" names people come up with. Litb me (talk) 19:17, 17 April 2009 (UTC)
- Fair enough. But even so, a name change seems unlikely before the standard is actually approved, since the term C++0x is in such widespread use. But the papers you cite at least justify the redirect. decltype (talk) 19:26, 17 April 2009 (UTC)
Current status: resolved. While the standard will very likely not be released in 2009, C++0x is the most well used name and therefore this article will stay as C++0x until the standard is released.
Publication in 2010 or later?
N2697 seemed to have said little about whether the timetable proposed by Herb Sutter represented standard committee consensus. The following straw poll only dealt with the Sep 2008 committee draft and had nothing to do with the official international standard. Moreover, even if the standard committee plans its work according to that timetable, it will be publishing a final draft international standard after the third meeting of 2010. According to a talk by Lawrence Crowl and Matt Austern, it would take another six months or more before the official international standard is published. That will probably push the publication date into 2011. I think the lead section needs some clarification about that.Kxx (talk) 03:11, 20 April 2009 (UTC)
- Erm, the lead section already does clarify this. Also see the talk section prior to this, C++0x -> C++1x. --Snaxe/fow (talk) 17:46, 20 April 2009 (UTC)
Current status: resolved. See the previous talk section, C++0x -> C++1x.
- The point I wanted to put forward was not about whether the standard will come out in 2009—it is pretty sure that it won't—but that the citation is too weak in supporting the claim. N2697 said nothing about the publication date of the official international standard and thus certainly didn't nail that date in 2010. Furthermore, judging from N2697 alone, it is unclear whether the standard committee endorses Sutter's timetable. Therefore IMHO, N2697 itself does not stand firm enough to back up the claim that "[the standard] would be published in 2010". (BTW, given that the FDIS won't be ready until the third meeting of 2010, personally I would suspect that the official IS will actually come out in 2011.) And the lead section should be less specific about the publication date unless stronger citations are found.Kxx (talk) 19:31, 20 April 2009 (UTC)
- I have tagged that sentence with {{verify source}}. Correct me if I missed something.Kxx (talk) 19:40, 20 April 2009 (UTC)
- Reading over N2697 carefully, there is still some discussion over the timetable, as you pointed out. The main problem here is what exactly the standard being "published" means. Are we going with when the final draft is issued, once the draft makes its way around ISO, or some time entirely different? According to N2697 they do have a meeting planned for October this year, however I think that doesn't keep the final draft from being issued by the end of this year. I propose we clarify this by saying something like "There is some debate over when the standard will be published. The final draft of the standard may be issued either by the end of 2009 or early 2010, however WG21 expects it to take six months to a year before the standard is published by ISO." --Snaxe/fow (talk) 16:02, 21 April 2009 (UTC)
- According to here and here, the ISO is very specific about what something being published means, not approval of drafts but publication of the official document. So probably we should follow the same definition.
- Comparing with how things worked for C++98 (see here), there is still a long way to go for C++0x. The current status of C++0x is similar to what C++98 was in the first half of 1996, with the FCD yet to be completed. Projecting the timeline of C++98 into that of C++0x, we can expect an FCD by the end of 2009, an FDIS by the end of 2010 (in accordance with the timetable in N2697) and final publication in 2011.
- Based on the above, I propose expanding your text into:
There is some debate over when the standard will be published. The final committee draft of the standard may be issued by the end of 2009, and the final draft international standard by the end of 2010. However, WG21 expects that it will take another six months to a year before the standard is published by the ISO.
Kxx (talk) 20:25, 21 April 2009 (UTC)
- I like that wording. I'll merge it in right now. --Snaxe/fow (talk) 05:58, 22 April 2009 (UTC)
- The like the wording too. Seeing how long it took for C++98's FDIS to become the official Standard (i read somewhere it only takes a few weeks for ISOs, but apparently C++98 did take way longer), i think it's reasonable to expect something around early 2011. Litb me (talk) 18:59, 22 April 2009 (UTC)
Why talking of PODs while standard clearly defines the aggregate terminology ?
I'm curious of why it has never been mentioned in the paragraph of new POD definition and Initialize lists.
would by any chance an aggregate be a POD ? I still havn't read the entire 1300 pages of the standard (PITA...) so i wouldn't know.
what i know for sure is that an aggregate IS the condition to be initializable with initialize list. —Preceding unsigned comment added by Lightness1024 (talk • contribs) 21:55, 22 April 2009 (UTC)
- From what i know, an aggregate in the new Standard is the same as in the old Standard as explained in the section about declarators/initializers. An aggregate can be initialized with an initializer list, that's right. However, in C++1x, initializer lists can be used to initialize other things too. Like class types with an initializer list constructor.
- Aggregates have little to do with PODs, other than that POD structs are aggregates (in C++03, at least) (but not the other way around:
struct x { string f; };
is an aggregate, but not a POD). However, now in C++1x there are several changes to the definition of PODs and the rules of the associated text. So, now you can memcpy non-PODs, as long as they are trivially copyable. And you can use offsetof on classes that are standard-layout classes. Litb me (talk) 15:32, 26 April 2009 (UTC)
- Very interesting answer, making me want to read a little more about this, for clarity. --Lightness1024 (talk) 21:53, 14 May 2009 (UTC)
Inaccuracy With Concept Maps?
The article says that concept maps
allows a pre-existing object to be converted, without touching the definition of the object, into an interface that a template function can utilize.
From what I understand, concept maps can only adapt operators and free functions, but not member functions, so the object is not converted to any type. Maybe one should clarify this? Mstocker (talk) 07:47, 7 May 2009 (UTC)
- Given the example in 14.10.2.1/1 of N2857, I think the quoted sentence is fine.Kxx (talk) 08:48, 7 May 2009 (UTC)
pack and unpack in variadic template
IMHO, the original description of pack and unpack operator in variadic template is wrong.
The point is not the "..." at the left or right hand side of _type_, but the place.
For example, see template<typename... Params> void printf(const std::string &strFormat, Params... parameters);,typename... Params is the template "parameter", and Params... parameters is the function "parameter". "..." here are pack operators.
In printf(*s ? ++s : s, args...); and static const int value = 1 + count<Args...>::value;,
arg... is function "argument" and Args... is template "argument". They are doing unpack.
Say "When the operator is to the right of the type, it is the "unpack" operator." is wrong because
in the above, arg... is not collection of type.
That's what I have got after reading n2080(Variadic Templates (Revision 3)). I'm not a native speaker of english so my modification is in poor english and got rejected. :( Hope for some discussion and advice. —Preceding unsigned comment added by 220.135.250.105 (talk) 05:58, 11 June 2009 (UTC)
- Take words from n2087(A Brief Introduction to Variadic Templates): "The ellipsis therefore has two roles: when it occurs to the left of the name of a parameter, it declares a parameter pack; when it occurs to the right of a template or function call argument, it unpacks the parameter packs into separate arguments." —Preceding unsigned comment added by 220.135.250.105 (talk) 06:14, 11 June 2009 (UTC)
Concepts
I've read here (http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=441) that concepts have been voted out of C++0x. Should this article be updated to reflect that? Mattsnowboard (talk) 14:12, 18 July 2009 (UTC)
- Yes, definitely. This is a monumental change. While blanket removal may be a bit drastic, everything indicates that concepts will not be a part of C++0x in any shape or form. decltype (talk) 03:39, 19 July 2009 (UTC)
- The removal of concepts seems very solid. Unless they're not going to have C++0x for the next 3-5 years, it's gone. So I'm going to go ahead and remove the section, but leaving a note saying that it was removed. Personally, I think they made the right decision. C++ is more than templates, and concepts are *only* useful for templates. Concepts was slowing down C++0x, and it's best to just cut it and release it in a TR or something. Korval (talk) 01:30, 21 July 2009 (UTC)
- The range-based for-loop now needs som clarification. 194.237.142.20 (talk) 06:43, 21 July 2009 (UTC)
- You're right. Unfortunately, there is no paper (yet) on how "foreach" will behave now that concepts are gone. Korval (talk) 18:19, 21 July 2009 (UTC)
- Sounds like a good decision (to remove it from the article, that is). decltype (talk) 09:59, 21 July 2009 (UTC)
- The section should NOT be removed, since concepts are still historically relevant, and anyway the fallout from the committee vote will go on for ages. I just heard about the committee vote to remove concepts from the standard and came to the WP article to find out just what it was that had been removed (I'm a fairly low tech C++ user and wasn't familiar with concepts). It's pretty bogus to chop the section out of the article now that a bunch of us are here wondering what the fuss was about. To exaggerate a little, it's sort of like deleting Michael Jackson's biography because he died. (Note: having skimmed the deleted section, it looks like concepts are sort of like Haskell's type classes and associated types, and might have been a bit ambitious for C++. Maybe they will come back in some form someday.) 70.90.174.101 (talk) 05:48, 22 July 2009 (UTC)
- You have a point, in that there should be something on the page that explains what Concepts used to be. But the original concepts section was a fairly detailed description; what is needed is just a brief glossing over of what the proposal was intended to do and how it would have done it. Korval (talk) 20:39, 22 July 2009 (UTC)
- There were things that were initially planned for C++0x but were removed later, namely garbage collection and modules. I think it's worth having a separate section listing all these things, and the concepts should go there. Also, to avoid page bloat, this section should probably contain only links to separate pages where each feature will be described in detail. Enerjazzer (talk) 00:13, 23 July 2009 (UTC)
- I've made the change [7] and created a separate page Concepts (C++0x). Please review. Enerjazzer (talk) 01:06, 23 July 2009 (UTC)
- I'm not sure if it's a good idea to have a page for the Concepts proposal, but I know it's a bad idea to have C++0x in the title, since it's not going to be in C++0x. Also, the additions you made mention "Macro Scopes" as being postponed. What are those? I don't recall seeing a paper about a feature called that. Korval (talk) 05:03, 23 July 2009 (UTC)
- Thanks, moving it to a separate page seems reasonable. I added an introductory paragraph (feel free to change it) and will try to read the article more carefully in the next few days. The article should probably be recast somewhat to be more in the "past", but preferably with some references to how the idea might keep developing. It does seem like a worthwhile addition to the language, that was removed due to time constraints but may stay around in implementations and reappear in a future standard. Templates themselves were like that for quite a long time. 70.90.174.101 (talk) 06:15, 23 July 2009 (UTC)
Article moved from Concepts (C++0x) to Concepts (C++) per above. auto / decltype (talk) 12:36, 23 July 2009 (UTC)
C++1x?
I guess you'll all have heard that the new standard is delayed to 2010 or later.[8]
It's funny, I didn't realize until last night that the 0x in C++0x was a partially instantiated year number, like C++93 and so forth. I'd thought it was a reference to C/C++'s syntax for hexadecimal constants, just like the ++ in C++ is a reference to C's increment operator. 70.90.174.101 (talk) 19:02, 23 July 2009 (UTC)