« first day (213 days earlier)      last day (4735 days later) » 

7:00 PM
Now this wouldn't work
 
point being, I'd end up with a reference to the object on the right side of the operation.
 
because inside operator= something is an lvalue
can't bind A&& to that
you could do A&& operator=(A& something) { return std::move(something); }
 
huh?
I thought something was the argument sent in....
 
Yes
And it's an lvalue
 
a = b..... no... b is rvalue
 
7:02 PM
Inside operator= it's an lvalue
Consider int* f(int const& i) { return &i; }
Would you agree that i is an lvalue?
 
lvalue because it was returned?
 
(a const is missing above)
 
@Xaade No, names are almost always lvalues.
The distinction between lvalues and rvalues has nothing to do with the two sides of the assignment anymore.
 
ZOMG....
 
@Xaade It shouldn't matter whether it's returned or not, like int const* f(int const& i) { return 0; }
 
7:04 PM
There are three different value categories in C++0x, but surely the assignment does not have three sides ;-)
 
@Fred WTH... why not
 
@FredOverflow It never did to begin with
But you knew that already I assume...
 
@LucDanton Right, but that just enforces my point.
 
ok.... so what's an lvalue, and what's an rvalue?
 
@Xaade What are you current working definitions of lvalue and rvalues ?
even informally
 
7:05 PM
78
Q: What are rvalues, lvalues, xvalues, glvalues, and prvalues?

James McNellisIn C++03, an expression is either an rvalue or an lvalue. In C++0x, an expression can be an: rvalue lvalue xvalue glvalue prvalue Two categories have become five categories. What are these new categories of expressions? How do these new categories relate to the existing rvalue and lva...

 
I was taught that lvalue and rvalue meant the side of the operation.
 
@Xaade WRONG
 
it most assuredly does not
 
One of the most common misconceptions in C++.
 
consider a simple array assignment
 
7:06 PM
@Xaade I suggest you take up the current meanings of lvalue and rvalue before attempting to undertand rvalue refs
 
int a[1];
int b = a[0];
a[0] = 1;
 
Even if it's not a technical explication
 
is a[0] an lvalue or rvalue? it must be both!
 
@Xaade If &(expression) compiles, than expression is an lvalue, otherwise it's an rvalue.
 
I think a better and informal way to each about lvalues and rvalues (for C++03) are operator* vs operator& than operator=
Someone thinks faster than me apparently :)
 
7:08 PM
And here is an example with an rvalue on the left and an lvalue on the right:
std::string("hello") = my_string;
 
Xeo
@DeadMG How about xvalue ?
 
@Xeo No xvalue in C or C++03
 
Xeo
@LucDanton Oh, C++03 talk in here. :) Nevermind me then
 
@Xeo An xvalue is the call of a function that returns an rvalue-reference (or a cast to an rvalue-reference). The most prominent example of such a function is std::move.
 
Xeo
@FredOverflow Mm, right, I remember reading that...
 
7:10 PM
So basically don't use xvalues after the statement that returns them.
 
Not just return
 
std::string("hello") = my_string; doesn't look like it would be valid.
 
Usually std::move(x) is the last time you'll be using x, you're correct
 
@Xaade What do you mean, "use" xvalues? Value categories describe expressions, not objects.
 
don't use a reference to an xvalue after the expression is done evaluating.
The object may not exist.
 
7:12 PM
@Xaade There is no such thing as a reference to an xvalue.
 
Then what's the point in the designation if you can't refer to it?
 
An object is neither an lvalue nor an rvalue nor any other value. It's an object.
lvalues/rvalues & co. are expressions, not objects.
 
As a property it's called the value category of an expression
 
@LucDanton Which is highly confusing terminology :)
expression category would be more fitting.
 
so a reference to an rvalue is
 
7:14 PM
I agree, the category bit is the important one
 
@Xaade Again, there is no such thing.
 
What's A&&
 
You cannot have a reference to an expression.
 
A reference to an rvalue is an lvalue
but reference as in A&& a;
A&& is a type
Well
 
You cannot have an rvalue reference.... yet the term rvalue reference is all over the place.
 
7:15 PM
more like given A&& a = /* ... */;, then the expression a is an lvalue
 
30
Q: What does T&& mean in C++0x?

paxdiabloI've been looking into some of the new features of C++0x and one I've noticed is the double ampersand in declaring variables, like T&& var. For a start, what is this beast called? (I wish Google would allow us to search for punctuation like this.) What exactly does it mean? At first gl...

@Xaade An rvalue reference is a reference bound to an object designated by an rvalue.
@LucDanton Named rvalue references are lvalues, and anonymous rvalue references are xvalues.
 
So if you wish to ask whether something is an lvalue or rvalue, make sure you're asking about an expression
 
An rvalue reference behaves just like an lvalue reference except that it can bind to a temporary (an rvalue), whereas you can not bind a (non const) lvalue reference to an rvalue.

TRUE or not, because I understand this definition.
 
@Xaade A temporary is not an rvalue, even though the standard states it.
 
Muther *&(*&(&
 
7:17 PM
The expression that created that temporary is an rvalue, however.
 
ok ok... that's fine
 
Rvalues references bind to rvalues, but not just expressions involving temporaries are rvalues
 
I don't care about the difference.... I understand that point.
 
Okay, so everything's clear now?
 
What else can be an rvalue?
 
7:18 PM
Some literals
like 3
but not "blah"
 
fine
 
(Thanks to C those are complicated)
 
got it
 
string lits are not, but other lits are
 
@Xaade rvalue is an abstraction that subsumes both prvalues (a new name for what was previously known as rvalues in C++03) and xvalues (a new concept in C++0x).
 
7:19 PM
So, T&& t = T();
T();
the second line would have created a temporary
T&& t lets me bind to that temporary
 
Yes
 
Fair enough.
However,
T t(); is an lvalue
 
const T& t = T() is already valid btw
 
@Xaade T t(); is a function declaration.
 
@Xaade: is a function declaration?
 
7:22 PM
Formally, given T t; then the expression t is an lvalue but I think you're getting the hang of this
 
t = t;
Both t and t in the statement t=t are lvalues;
 
@Xaade Again, T t(); is a function declaration.
Yes, t is an lvalue. It does not matter in what context that t appears. Especially, forget about assignment.
 
Can I do this?
T&& t;

t = T();
 
No, references must be initialized. T&& t; is a compiler error.
 
T&& t = NULL;
 
7:24 PM
There is no such thing as a null reference in C++.
 
T could be int or a pointer type
but as a general thing, it's also invalid
 
...
So there's no way to make a rvalue reference and use it later?
 
just the same as for lvalue references
 
References must be initialized. You cannot (re)bind them later.
 
woot.... I just found something that validly breaks my companies coding standards.
 
7:25 PM
@Xaade And what is that?
 
Every variable must be declared at the top of its scope.
 
that's a horrific standard
 
I know
 
This sounds like a reasonable standard for 1989
 
@Xaade Totally anti C++
 
7:26 PM
Not saying it's good. I'm saying I found something that will break it....
 
what if it needs construction with arguments based on logic with previous variables?
a reference is just one example
 
There are types that have no default-constructor, for very good reasons.
 
@DeadMG I know I know.... that's my frustration.
 
@Xaade You can abuse it by opening a block btw
 
and you're making variables available before you're using them, which is worthless
 
7:27 PM
And it makes the code harder to understand.
And you can't use auto.
 
Code is harder to understand. The reasoning is so that the variables scope will be easy to identify, for reading on paper.
 
Given { T t; /* something */ t = /* ... */ }, => { /* something */ { T t = /* ... */ } }
 
@Xaade Are you sure it's a C++ coding standard and not a C coding standard? Because in C89, you cannot have declarations after the first statement.
 
Most of our standards that make no sense are in place to make reading on paper easier.
 
@Xaade But it isn't easier to read. Why would I separate the declaration from its first use? It makes me have to go up and down unnecessarily, which I find annoying.
 
7:29 PM
Hey hey.... don't ask me.
We still use systems hungarian notation.
 
You cannot search on paper, it cannot possibly get any worse than that.
 
Argument being in the middle of code, it's the only way to know a variables type.
 
uh
just mouse over it and the compiler will tell you
 
I always like to debug my code on paper, one random statement at a time.
 
7:30 PM
even if you use auto, etc, then it will tell you
 
Xeo
0
Q: Is it valid to directly call a (virtual) destructor?

XeoIn this answer, Ryan directly calls the virtual destructor. I've tested the code in VS2010, and it correctly calls all destructors (tested with logging statements). Is it actually valid to do so? What are the problems, flaws or even the good points of such an approach? I can only think of it as ...

 
So what would a variable of type typename std::map<std::string, std::map<int, std::string> >::const_iterator be named like according to your standard?
 
I tried to reason.... I suggested that if we use hungarian at all, we use it to identify the use of the variable, not its type.
@FredOverflow You ready for that answer?
 
@Xaade That's actually very useful!
 
msmisciMap
 
7:31 PM
@FredOverflow cName
 
@Xaade What does that tell me about the type? Nothing!
 
@FredOverflow That it has 'c' in it!
 
Xeo
Okay @DeadMG, that was fast.
 
@FredOverflow But that way it gives you the impression that's it's const, when it's not!
 
@Xeo: I'm watching a video on the other screen, so
 
7:32 PM
@LucDanton Right, which is terrible.
 
@FredOverflow For example, using notation ix to designate iterators if they are primitive (like ints used in a loop) so you don't accidentally put their values into an int that represents a coordinate.
@FredOverflow Objects have hungarian notation 'c'
Just shows how old it is.
 
@Xaade What is the technical term for this (as opposed to systems hungarian)?
 
I think it's just hungarian
That's how it was at the start
 
The real one.
 
@FredOverflow I'm not sure, but I've heard the distinction between systems hungarian and app hungarian.
 
7:33 PM
Would the real Hungarian please stand up?
 
But those are Microsoft's terms
hungarian is useless in C#.... everything is designated 'c'
 
@Xaade Even structs?
 
IIterable makes me foam
(not sure if it's C#)
 
@LucDanton Does that really exist? LOL
 
it's "Hungarian Notation"
 
7:35 PM
Although I like it's use of 'm_' and 'g_' to designate member and global
 
hungarion is useless in any strongly-typed language
 
@FredOverflow Well, you're right..... structs are designated 'st'
 
@LucDanton No wait, I think it is called IEnumerable in C#.
 
@FredOverflow Well they do have IComparable and the likes, so...
 
if I want to know the type of a C++ variable, I will just mouse over it and the compiler will tell me
 
7:35 PM
Righto
Perhaps some library then
 
Ironically.... strings have their own special designation even if they're objects.... designated 'str'
@DeadMG Not on paper.
 
who gives a crap about paper?
paper doesn't compile my code
 
1989 does
 
people don't read code on paper unless they're insane
2
 
Apparently these worthless standards.
 
7:36 PM
and not just "I like Singletons" insane
but really, really, really insane
 
Hey.... coming from people who print COBOL code on 89 sheets of paper, sit in a room at a round table, and complain about how my loop's condition is at the end of the loop code.... even though I argued that the loop occurs at least once.
 
well
just what a horrific waste of paper
 
Disregarding the fact that you can't even read COBOL in functional order because of sections.... and perform statements
And god help us GOTO statements
 
I'm not sure I want to know about COBOL
 
Think assembly, but with the option to have a keyword in the middle of a statement, and without knowledge of the registers.
All variables are forward declared, and defined in a memory area called "working storage".
 
7:39 PM
COBOL is the kind of language where it's written in all caps, I'm pretty sure
and the assignments are the other way around
 
Checks are performed by attaching check levels to variables with predefined values to check against, and given their own reference, so when you use the check reference, it checks against the appropriate variable automatically.
 
PRICE TIMES TAX_PERCENT GIVES TAX;, from memory
 
Unless you use their COMPUTE statement, then yes.
COMPUTE x = a + b.
 
Ah, non-IT guys should be able to read COBOL code or something, right?
 
yeah
 
7:42 PM
CARS pic 9.
CARS_MAX value 9.

IF CARS_MAX THEN
blah.
 
I'm gone for a second and when I come back there's COBOL everywhere
I'm pretty sure I didn't want to know about COBOL :(
 
I dealt with COBOL for a year.... first job out of college
pickings were slim
Now I'm dealing with C++.... with weird coding standards.
 
those are some blindingly bad coding standards
 
like, the first bracket is on the line after the statement that starts a code block.
if (a)
{
}
Declarations at the top of the scope.
Hungarian notation
 
Braces are a matter of taste (obviously this way is worse, because I don't like it).
 
7:47 PM
Well, everywhere else uses
if (a) {
}
For good reason
If balance is a problem, then just do this
if (a) {
} // end if
 
Tell your boss that he needs to read this book. Should he ask "Who the hell are Herb Sutter and Andrei Alexandrescu?", please quit your job immediately.
 
How do you practice "safe" overriding?
There's no such thing.... abstinence is best.
@FredOverflow If I don't know who they are.... should I quit programming?
 
Either that, or you should start learning modern C++.
 
To be fair.... I'm not good with names.... I could read every single one of their books, and never notice.
 
If you don't know Herb Sutter, it probably means you don't know exception safety, hence you have absolutely no clue about modern C++.
 
7:51 PM
@FredOverflow Believable.... I was a C# programmer, but I couldn't find an entry level job.
 
@Xaade Out of curiosity, do you like C++?
 
@LucDanton Not necessarily... But I don't mind C++
As primitively as we use it, I don't really have to know much about it at all.
 
Do you know what "undefined behavior" means?
 
Yes
 
For example, what's wrong with the following code?
char* p = "hello world";
p[0] = 'H';
 
7:54 PM
It means that the result of doing X is not formally specified. Compilers may implement it differently, or it may have unintended consequences, or it may not work at all.
 
Sounds fine except for the "Compilers may implement it differently" part, that sounds more like unspecified behavior or even implementation-defined behavior.
 
char* p points to the first char of the memory reserved for "hello world";
p[0] puts 'H' into the start of that memory area....
But what's 'H'
is 'H' one byte or two?
I'm not sure what's wrong.
 
Naw, literals are const char* and cannot be modified (compilers usually put them in a read-only memory).
 
I don't bother with instantiating memory at a char* in that way.
 
char* is ugly.
 
7:59 PM
If I had to.... I would have done char* p = new char[12];
 

« first day (213 days earlier)      last day (4735 days later) »