« first day (1446 days earlier)      last day (3506 days later) » 

9:00 PM
I just re-read Herb's slides on the subject and it's even worse than I remember
He's using std::string-specific properties for his performance argument
 
not copying strings is the most important part of every c++ program!
!!
 
and he complicates his option #4 to no tomorrow to 'prove' his point on noexcept being 'dodgy'
it's like he missed the in between
 
Ell
I thought he was talking just about strings?
 
user1804599
Herb is a loser.
 
'general guidelines'
 
9:03 PM
major obstacle
 
I only use const T& + T&& when I have to optimise and found a bottleneck
or when the object is expensive to move (for some reason)
 
Ell
I just met a guy on the train
 
improbable
 
user1804599
I take everything by value except when it isn't copyable.
 
@AndyProwl OK, after some more thinking: the advantage of const& for anything big (>= 16 bytes say) is that you don't have to overthink usage patterns (lvalue/rvalue, are moves cheap, is capacity reusable). That makes it a useful default. For optimal performance, I would still go for T const& + T&&. Only in specific circumstances (well-predictable usage pattern, but too annoying for multiple overloads), I would go for single T overload
 
Ell
9:05 PM
Can you use brackets to nest functions in Haskell?
He was writing Haskell
 
@R.MartinhoFernandes from my understanding, yes
 
user1804599
@Ell You are being vague as thecoshman.
 
Ell
But it was parse erroring
 
@Ell Nesting meaning what?
 
Ell
As in f(g(1, 2))
I thought it was f $ g 1 2
 
9:06 PM
Yes no maybe
 
Ell
But I can't remember
Ahh 4% battery
 
I suspect you wanted f (g 1 2).
 
@TemplateRex Wait, I'm not following: why is const& beneficial for big things? If I pass an rvalue vector of a million elements, it will copy it
 
user1804599
That's function application, not functions.
 
or you mean sizeof()?
 
9:07 PM
Also those aren't brackets
 
Ell
Sorry parenthesis
 
Ell
Theyre brackets in the uk
 
they're brackets in most English speaking countries
 
user1804599
They're haakjes in the Netherlands.
 
9:08 PM
the only country that uses 'brackets' for something else is the US
[]
 
Ell
3% bye folks
 
bb
 
If you wanna be pedantic then brackets is a group that includes all of those things which is still vague and unhelpful to use in a sentence so WHATEVER
also kill me this ui shit is like 5% done
 
user1804599
You deserve it.
 
@AndyProwl where does that big vector come from? what usage pattern conjures up that stuff? reading from file? and if you are doing that a lot, chances are that you can reuse existing capacity
 
9:12 PM
Yes, let’s bet on this.
 
@TemplateRex I just don't understand why for big stuff always copying makes more sense
 
I'm just saying, if you have lots of big data around, why not keep that data by pointer, and swap pointers, rather than relying on the compiler doing it behind your back with move semantics
 
'cache_choices': False, 'choice_cache': None,
 
@TemplateRex not following, sorry. I think I'll just have to digest this new guideline for a while before I assimilate it
it just sounds counter-intuitive to me
 
Also thanks forms, value is exactly nowhere
 
9:16 PM
@AndyProwl I think a setter taking a really big object should treat it as an inout parameter and accept pointer/reference to that big object explicitly
small and medium sized stuff shouldn't really care, just copy a few bits and profile if you must
 
@TemplateRex why in/out? I don't understand... what's "out" about a value you want to set? The caller needs nothing back
 
@AndyProwl I mean expose the handle to the big data member
 
@TemplateRex Sorry, my brain's probably fried
It's going too abstract for me
I have troubles following all the ramifications of the conversation
 
@AndyProwl std::move on vector/string just does pointer swapping,right?
 
@TemplateRex right
which is why I'd like rvalue vectors to be moved instead of being copied
 
9:20 PM
 
C++ developers cannot handle pointers. No matter 32 bytes or 2GB, it HAS to be copied at least twice.
 
@AndyProwl why not hold a std::unique_ptr<std:;vector> and set that in your setter?
 
@AndyProwl They are.
 
@LucDanton I know. But they're not if you take by const&
@TemplateRex because I don't need reference semantics
I want simple code which behaves reasonably efficiently in most cases by default
 
@AndyProwl your rvalue big data factory returns unique-ptr to whatever, just pass it by value and done
 
9:22 PM
Also, if a thread lock is held during a 2GB copy, so mutch the better.
 
@AndyProwl Accept the word of Abrahams!
 
@TemplateRex why unique_ptrs? I don't want to think about that
it's not what we were talking about
 
@AndyProwl ah but you want single overload doing two things well, lvalues and rvalues
 
@LucDanton I'm trying hard...
 
that's too much too ask unless you know it's actually doing only (or mostly) one of the two
 
9:23 PM
@Template no, he does not.
 
@TemplateRex "reasonably well"... and I think a single overload taking T does better than a single overload taking T const&
 
@AndyProwl under certain assumptions, yes, the question is are they typical enough to warrant the status of default?
[and I don't know]
 
The option that only works if you know it's actually only one of the two is const& because it just can't move. At all.
 
@TemplateRex I guess I don't know. I think most of the time setters are sinks
 
For std::vector<T> you should know. It’s fine to guess in other cases, but when you do know, do it.
 
9:25 PM
@AndyProwl I have very few setters, so I haven't thought about it
 
Don’t let your hesitation in the general hinder you in the particular.
 
@TemplateRex I don't have many either, but if I'm told there's a significant change in a widely adopted idiom, I'm concerned
 
@LucDanton but for default choice, only the general counts
 
And in general you want to not move at all?
 
and then the question remains: if you want to move, why not add the extra T&& overload?
it's a one-line setter
 
9:26 PM
Not it does not.
 
@R.MartinhoFernandes according to Herb's data (for std::string), that's a better loss than performing dynamic allocations when you don't need
 
The by value overload can do both.
 
I think I book Fawlty Towers for my GF :S
 
@R.MartinhoFernandes at a small cost for xvalues, const T& + T&& is optimal
 
@Andy clearly the best evidence for providing general advice.
 
9:27 PM
@R.MartinhoFernandes precisely my feeling
 
@TemplateRex Doesn’t scale well for N arguments, note.
 
@LucDanton we are talking single arg. setters
 
it does have some point though: if move is fast, then it's because there is some kind of buffer being held on the heap through a pointer, which means capacity can be reused when copying
I just find it counter-intuitive
 
My point is that single overload with const& is a silly option that will be begging for the extra overload.
 
@TemplateRex You're special casing a 'general guideline' :v
 
9:29 PM
@R.MartinhoFernandes that is a good point
 
@Rapptz A recurring trend.
 
@LucDanton hm?
 
@TemplateRex ?
 
I wonder if this problem really can't be solved at the language level
 
@LucDanton what other examples?
 
9:30 PM
by simplifying perfect-forwarding somehow
 
3 mins ago, by Andy Prowl
@R.MartinhoFernandes according to Herb's data (for std::string), that's a better loss than performing dynamic allocations when you don't need
 
I'm starting to see what Jerry meant when he said that Herb is the Oracle of Wrong.
 
@R.MartinhoFernandes at least he is still above the Wong of IBM
@R.MartinhoFernandes btw, what do you think of Herb's smart pointer passing advice? I recall you chafed him about earlier stuff on his blog?
 
Is he the one that recommends shared_ptr const&?
 
rings a bell
 
9:34 PM
If so, I think it's flat out wrong.
 
@Rapptz I don't see how it's special casing: herb's slides only talk about single-argument passing, not about the multi-argument case.
 
no he doesn't
he says
'reasonable default when passing parameters'
that implies any N arity of parameters
just because his examples use a single parameter doesn't mean it's not a 'general guideline' that extends to other N parameter function versions
 
He, however, argues it with the std::string setter example.
 
@Rapptz and he does note the combinatorial problem of the 2 overloads, with the argument that multi-arg functions are much rarer than single args
 
I want my bottlenecks to be in SSO copies.
 
9:36 PM
@R.MartinhoFernandes I want SSO for vector, that would be awesome
 
i like passing strings back and forth
 
@TemplateRex I have the slides open.
I can't find this mention.
 
@Rapptz it's in the video
 
@TemplateRex I don't think 'multi-arg functions' are rare
@TemplateRex I'll take your word for it
Don’t use auto&& for local variables.
You should know whether your variable is const/volatile or not!
@LucDanton ^ that's what I meant earlier
 
@Rapptz I think he says something to the effect that multiarg is more likely for constructors
 
9:39 PM
He says that by value is good in ctors.
 
wot
 
he does
 
I'm not joking.
 
@R.MartinhoFernandes because in constructors there's no capacity to reuse
the object hasn't been initialized yet
 
45 mins ago, by Rapptz
'..except in constructors where you should use T'
 
9:40 PM
so you need the dynamic allocation anyway
his point is that a dynamic allocation for lvalues is worse than a missed move for rvalues
(actually, he claims this comes from Howard)
 
You don't need any allocation if you move.
 
@AndyProwl well Scott's book has been delayed for a month, maybe he has another take on all of this
 
@R.MartinhoFernandes you'll need an allocation for lvalues
 
Scott already said he disagrees with Herb on his defaults
 
while if you take by const& you won't need to allocate anything most of the time
because you reuse existing capacity
@TemplateRex we'll see
 
9:42 PM
By most of the time you mean with vectors and strings.
 
too bad the MVP for VC++ is a closed list
 
yes
I'm trying to play Herb
@R.MartinhoFernandes however:
14 mins ago, by Andy Prowl
it does have some point though: if move is fast, then it's because there is some kind of buffer being held on the heap through a pointer, which means capacity can be reused when copying
^ trying to make a general conclusion
 
> A special attraction of C++ and Beyond in Stuttgart is looking like it might be a full-blown bar brawl between me and Herb Sutter. In recent weeks, he and I have been going back and forth about the wisdom (or lack thereof) of advising people to use pass-by-value in function interfaces. We've exchanged some posts on this topic in comments on my blog and in posts to a Microsoft C++ MVP mailing list, plus there have been some behind-the-scenes email messages, and at this point, having carefully weighed all the facts, it looks like the only thing we fully agree on is that the other person mea
 
Yes, but why the assumption that that reuse is cheap?
 
(and if move is not fast, then we can take by const&)
 
9:44 PM
I have a feeling he looked at buffers of ints for his conclusions.
Oh wait.
He looked at buffers of chars.
 
closing quote from Howard: "process3 looks like the best solution to me. However it does require two overloads. One to process lvalues and one to process rvalues. If for some reason this is problematic, solutions 4 and 5 do the job with only one overload at the cost of 1 extra move construction for glvalues (lvalues and xvalues). It is a judgement call as to whether one wants to pay an extra move construction to save overloading (and there is no one right answer)."
 
I don't want to copy all the Ts in my vector to save an allocation.
 
right
This makes sense to me
perhaps in the case of std::string, because strings are mostly short and bla bla
but in general, I'm not ready for it yet
 
And reusing the buffers means copying chars.
 
ok, time for bed
 
9:46 PM
But when you replace char with T, performing a thousand copies instead of even ten moves doesn't sound so awesome anymore.
 
user1804599
Wee, implicit def boolToInt(b: Boolean) = if (b) 1 else 0 and now I can do " not" * condition! :D
 
night guys
 
@R.MartinhoFernandes vector with dozen ints is cheap to copy, lot more expensive to reallocate
 
@Template vector with dozen Ts is not cheap to copy.
It's supposed to be general advice but I see very few placeholder names being thrown around.
 
@TemplateRex "Item 41: Consider pass by value for copyable parameters that are cheap to move and always copied." was one of the items a while back.
don't know if it'll change or anything but I like Scott
 
9:48 PM
@Rapptz yeah but it came otu before the debate between Scott/Herb, and the upcoming beer brawl in Stuttgart, so I wonder whether SCott has changed his position in the mean time
 
@LucDanton to me too. During an "ask me anything" (2012?)
 
Nothing as specific. I’m impressed by your recall.
 
@R.MartinhoFernandes anything that fits within 1 or 2 cachelines (dozen small strings e.g.) is OK-ish for performance, beyond that you'll get a big hit
 
well I trust Scott more than Herb tbh
 
@Template or anything that isn't a fucking POD
 
9:50 PM
@R.MartinhoFernandes true
 
@LucDanton This is one of the few benefits of video talks for this: it lends (arbitrary) context to these things, which is nice for how my memory operates
 
For an example consider a vector of strings.
 
They were the three of them
 
It's not far fetched at all, and it sticks to everyone's favourite specific cases from which to derive general advice.
 
cache is king
 
9:52 PM
vector<string> const& will prove to be a horrible idea.
You'll be reaching for that second overload in no time.
 
Or anything which has strings in it or has things that have strings in it and so on.
 
As soon as you leave the world of buffers of ints, you're fucked.
 
user1804599
 
A single by-value overload, however, will not explode in your face like that.
 
user3010322
Indeed it won't.
 
user3010322
9:56 PM
Still, for libraries, a useful perfect-forwarding pack would be nice.
 
Thanks for making sort my thoughts about this.
 
I also realized that in any such discussions anyone not throwing around Ts must be stopped immediately and reminded of the meaning of the word "general".
 
Xeo
In general, "general" isn't meant to be very general.
 
10:14 PM
I think I'll take some time off.
 
user3010322
container_bounds_iterator was my best fucking idea yet.
 
See you guys.
 
user3010322
@Sofffia No, get back to work. D:<
 
Ell
evening folks
 
user1804599
Somebody tried to send me a 2GB file on IRC. :v
 
10:19 PM
oh, that could take some time to type out.
 
Best title/question mismatch of the day:
-7
Q: Computer Science

BrittWrite an OpenMP program to determine the vertex(ices) with maximum degree and the vertex(ices) with minimum degree of a given graph. Your input will be as follows: Example Input: 6 1 1 1 1 0 0 1 0 0 1 1 0 0 1 1 Example Output: Vertex 0 has degree 4 vertex 1 has degree 2 vertex 2 has degree 3...

I'm surprised by the lack of, "$300/hr paypal" comments.
 
user3010322
I guess I'm gonna have to do this on paper...
 
Ell
I think you lounge folks should agree on a guideline for parameter passing and return types and the like
I get the feeling Herb can no longer be trusted
5
 
user3010322
Pass by value unless you need optimizations (e.g., for string)
 
@Ell Herb and Scott had a rather long-running...discussion on the Microsoft MVP mailing list about what to recommend. The last time I caught up on it (last weekend) they still hadn't reached a real agreement, but there were really only a couple of situations/points on which they still disagreed.
 
10:34 PM
you guys are still talking about this?
 
Ell
@Rapptz I just wanted to know the status quo :)
 
@Ell I still think the arguments put forth in Abrahams’ advice are as compelling as ever, and I see no reason to change.
 
10:51 PM
Will rust help me program my first unborn son?
@Ell Most of us here agree on pass by value as a default, I think.
 
Ell
okay cool
 
user3010322
@Rapptz All of us, I think.
 
user3010322
Btw HEXES ARE HARD.
 
Ell
because the compiler will optimize copies out?
wait it can't do that o.O
 
user3010322
Because even in the most unoptimized case it's a good default.
 
10:58 PM
it's 2 moves, no copy (for most cases)
 
The scenario is a function where you know you will construct a value.
 
user3010322
It can accept copies or moves, and if the class is move-only then it only accepts moves.
 
user3010322
If you make a class move-only later on (as I have before), pass-by-value won't API break and will properly error on potential copies for a user.
 
Ell
so even if I'm taking an object with an expensive copy and not modifying/storing it, I should still take it by value?
or should I take it by const& then? it's what I do atm
 
user3010322
If you're not storing it yourself, then take a references (const-qualified for correctness).
 
11:02 PM
const& is for using the const interface mostly (which does include copy construction mind you).
 
user3010322
optional<T&> or just T* for a param which is a "maybe I'll use it"
 
Simplifying that to T is when you want your own value. Contrast void foo(T const& arg) { auto my_own_one = arg; … } and void foo(T my_own_one) { … }. The second one does not do more work.
 
32
A: when is const reference better than pass-by-value in c++11

RapptzThe general rule of thumb for passing by value is when you would end up making a copy anyway. That is to say that rather than doing this: void f(const std::vector<int>& x) { std::vector<int> y(x); // stuff } where you first pass a const-ref and then copy it, you should do this instead:...

 
Ell
@Rapptz ah cool, cheers
@LucDanton Yeah
I always think const helps for optimization. but I'm not sure if it does
 
Nope. Except for one case, where you need const for correctness anyway: namespace scope constants.
 
Ell
11:06 PM
yeah
 
user3010322
const unfortunately can't guarantee shit
 
user3010322
Because it's just one const_cast away from being entirely useless.
 
user3010322
const is unfortunately not the way to demand immutability.
 
er
 
@ThePhD that's not the reason. That's your reason :|
 
user3010322
11:08 PM
What I'm trying to say is const is only for correctness when it comes to parameters and friends.
 
Or members etc.
 
@ThePhD Undefined behaviour.
 
The point is, your reference can be to a const object but the object may not be const to all parties
@Rapptz ^ not unless the object happens to actually be const
 
removing const-ness and modifying it is UB
 
I think that's only the case iff the original object was const
 
11:09 PM
@sehe Yes.
 
I see const_cast as a way to interact with C APIs who don't have const signatures
 
On a library level, you have somewhat of a point: the STL considers const to be a promise that nothing changes bitwise for PODs. So if you do the cast and modify it, you may be violating a bunch of library invariants.
 
Anyway const isn't useless. Only an evil library user will just const_cast it away.
 
Ell
yeah I like const
 
You shouldn't fear what evil library user will do because anything he does is undefined as far as guarantees go in using said library.
 
11:17 PM
Hi all, I'm not using chat rooms frequently. But now I have a question that seems best to be discussed here.

We often use the close reason
`Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.`
 
Oh great. Came out of club tonite and found a 'Road Ahead Closed' sign. To cut a long and boring story short, (involving driving 35km), I eventually found out that the sign meant 'Access only'. I only needed access, (and I've very rarely said that:).
 
@πάνταῥεῖ ?
 
Sorry premature enter ...
In the very consequence we're asking the OP, to have debugged down to discovering their problems themselves (which isn't bad advice IMHO).
Is that what leads such questions their way down to be closed and deleted?
 
@πάνταῥεῖ I don't often close vote. I kinda miss the time when we could just basically say "too little effort". That didn't last too long
@πάνταῥεῖ These days it's called "[On Hold]" and it serves precisely to motivate the OP to improve the post.
 
closed still exists
on hold is temporary (3 days) after that it's closed
they're still called close votes too
 
11:23 PM
That especially occurs with just given the c++ tag on questions.
 
Needs citation
 
genius
 
Do you think too many questions are being closed in the c++ tag?
 
@sehe Yeah [on hold] of course
 
who does :)
 
11:30 PM
@sehe Though, my concerns are (may be a bit silly), that with the close reason as stated, we actually ask the OP (sorry): _"Go f**k, solve the problem yourself, it's easy."_
I'm asking about that particular close/put on hold reason cited.
 
@πάνταῥεῖ on the contrary. It's telling the OP "Sorry, it's hard, but we're not psychic. It's even harder using a crystal ball" (or spending 3 years making a workable sscce, which might not exhibit the problem of the OP)
 
@πάνταῥεῖ "Why isnt this code working" is a good close reason and is used in legitemate cases id say 90% of the times, the other 10% might be premature/unwarranted, but IMO it does more good than harm.
 
@Borgleader The real mistake is being a Leafs fan.
 
@Borgleader There are always are these edge cases, where the OP hits 80-90% of the requirements.
 
11:33 PM
I usually don't close-vote I think. I just say something:
I suppose you could post a SSCCE that shows the problem for you then. Maybe we can spot something — sehe yesterday
@StackedCrooked no, I think the base class makes it non-POD
 
@sehe I got one here. The actual miss is, on having the OP debugged that code on their own.
 
hmm, wikipedia must hate c++
 
@Mgetz ??
 
the main c++ article still refers to c++14 as a draft standard... even though it has been approved (but not published). The c++17 article was deleted (alleged copyright infringment)
although reading through the talk page... there is a lot of c++ hate by users that don't use it
 
Ell
Its non pod even without virtual?
 
11:39 PM
@Mgetz Well, complain at the WikiMedia Foundation?
 
0
A: String Concat does not work as intended

seheYou have line end issues. The string contains a carriage return (but no line feed) and hence the cursor is returned to column 0 of the current line before printing ddddd. Note that the string concatenation is fine.

My crystal ball :/
 
@πάνταῥεῖ lol, no worth the time wikimedia would just tell me to fix it myself even though the article is locked
 
Ell
Catching another train tomorrow
Hope I get up in time
 
@Ell something about stdlayout IIRC
 
@Mgetz Protip: You can edit Wikipedia.
 
11:44 PM
@πάνταῥεῖ oh aha. just noticed he edited the question with that point himself. It took me no time at all to develop this hunch from /just/ seeing the broken output. I wouldn't have downvoted this question.
 
@Mgetz Become active in Wikipedia before complaining about it?
 
@Rapptz see bit about locked article
 
I can edit locked articles.
 
I don't really give a shit, I'm mostly amused
then have fun
 
C++11 (formerly known as C++0x) is a version of the standard of the C++ programming language. It was approved by ISO on 12 August 2011, replacing C++03,[1] and superseded by C++14 on 18 August 2014.[2]
nothing to edit
Oh I see now.
 
11:46 PM
@sehe OK, a well written answer. Though does the question in it's actual form deserve to be closed?
 
Nope. Not in my opinion.
 
Ell
> When using inheritance, only one class in the whole inheritance tree can have non-static data members, and the first non-static data member cannot be of a base class type (this could break aliasing rules), otherwise, it's not a standard-layout class.
So it looks like using zeroed is okay because it is standard layout?
Oh wait
 
@Ell It's okay as long as the derived is POD?
 
@sehe In other words: Should a SSCCE / MCVE include all of the debugging efforts of a question, and show relevant snippets and link for the full code outsourced (best) with an appropriate online IDE?
 
Ell
It is standard layout but it's not POD
 
11:51 PM
@πάνταῥεῖ I think the Meta.SO stance is that outside links are BAD. The question should be self-contained and of manageable size. I really don't know what was missing in this question.
 
@EtiennedeMartel Exactly what I was thinking
 
@Mgetz I can't find ISO/IEC 14882:2014 in the ISO page.
if you find me the link I'll edit it for you
 
@Rapptz it seems to be in an odd state
 
@πάνταῥεῖ The code was there, the output, he even bisected the line of code where the surprising behaviour occurred. To me that proves he had debugged it to reach this point.
 
officially approved but not yet published
 
11:53 PM
I looked up the lock reason and date and it seemed valid
not C++ hating
just you know, protecting the page from said people.
 
@Mgetz That's not too strange. That happens with all standard revisions, AFAICT. It's "ratified", then it gets published.
 
@sehe IMHO outside links for online IDE's like coliru aren't that bad reference, and tend to be stable
 
@πάνταῥεῖ Cough. Liveworkspace: dead. Ideone: lost old pastes. Coliru: frequently slow, lost old pastes.
Of course, snippets can go on coliru just as a proof that it actually works. In 99.9% of all my answers I include code both on Coliru (often some variants too) as well as in the answer itself, verbatim (only the main variant).
 
Oh - my favourite close-vote partner has turned up in the Lounge!
 
But to me, Coliru is much more about working answers than "working" questions. As long as stuff is self-contained, I prefer having it in the question.
 
11:57 PM
@sehe Disagree, Ideone and Coliru wor most of the times for me :P ...
 
@MartinJames And he's right on that topic
@πάνταῥεῖ Meh. It's about SO. Content should be in the posts if possible. I hate to have to go browse for the essential information.
 
@sehe I don't doubt it.
 

« first day (1446 days earlier)      last day (3506 days later) »