« first day (2049 days earlier)      last day (2892 days later) » 

user3790646
12:05 AM
 
user3790646
Lol
 
user5378087
@jaggedSpire haha I'm not from USA so I already learned some words... But, I prefer fall deeply in C++ instead use the other programming language that I used to work: delphi
 
well, good luck
 
@FernandoK. Hi Fernando, welcome to the pit Lounge. :-)
 
user3790646
@FernandoK. Oi, Fernando
 
user5378087
12:14 AM
Hi/Oi I believe that someone already knows my nationality
 
pit is where we trap & roast the new piglet
 
user3790646
Consigo perceber um brasileiro em qualquer lugar
 
user3790646
:p
 
@AndreyErick Just be careful--one of our regulars is a native of Portugal.
 
user5378087
@AndreyErick I'll keep writing in english, hence the others users won't be angry xD
 
12:20 AM
@FernandoK. Good call.
 
user3790646
@JerryCoffin He seems smart, doesn't him?
 
@AndreyErick Doing all the right things so far, anyway.
 
12:53 AM
-2
Q: C++ How can I delete -1 from my vector?

nanjero05I currently have this code that does bubble sort: #include <iostream> #include <vector> using namespace std; void bubbleSort(vector<int>& numbers){ bool notFin = true; int temp = 0; while(notFin){ notFin = false; for (int i = 0; i< numbers.size(); i++) { ...

sigh
i should probably sleep instead of looking at shitty questions
 
1:16 AM
I would highly recommend reading a book to reading shitty questions right before bedtime - because shitty questions make you emotional and wanting to comment, both are distractions to sleeping ...
 
1:52 AM
as I recall a paper brought up the fact that everybody and their mother were (re)implementing metaprogramming facilities and used that as an argument that they should be provided by the language
esp. for things like a selector for the n-th thing in a pack, which is easy to write naively but generates linear instantiations
did anything come off out of that? do some implementations actually have an efficient __nth<N, Pack...> ?
 
Hello?
 
> // Extract _From's qualifiers and references and apply it to _To.
heh, I’ve seen that one before @Xeo
 
Hey there, I was wondering if someone could answer me a very simple question (I'm a noob in C++)
 
@MatheusRocha sadly due to paradoxes it is impossible to answer that question
 
Haha... Well... When exactly do I have to manually delete a variable with the delete keyword?
 
2:00 AM
@MatheusRocha Never. Don't use new, and you never have to use delete.
 
True, I haven't used delete in production code since about 2007 or so.
 
Awesome. I also saw a post in which one of the answers the author said that it should be used pretty much whenever that variable survives the end of the scope (he didn't use those exact words). I'm guessing static variables don't fall in this rule, am I wrong?
 
note that the operand of delete is not so much the variable (if any) but the value it holds, if that makes any sense to you
if it doesn’t then don't worry about that too much
 
It does, I got it. Thank you so much! :)
*Thank you all so much. (I just realized those replies came form different people haha)
 
2:07 AM
libstdc++’s tuple_element is still a naive impl, guess that’s my answer
> Lets not make the same mistake we made with std::optional by putting this library into a TS. We waited three years where no substantial feedback or discussion occurred, and then moved it into the IS virtually unchanged. Meanwhile, the C++ community suffered, and we continue to suffer from lack of this essential vocabulary type in interfaces.
I’m catching up on the variant proposal, interesting opening
reason being that someone is helpfully submitting an implementation to libstdc++
> // Use recursive unions to implement a trivially destructible variant.
 
@Cubbi You're right. I have never used new or delete in any of my C++ codes either, but I started to wonder if I should. Now I see that I better continue avoiding it.
@LucDanton Are you still talking about this matter? If so, you totally lost me. I'm noob in C++, remember.
 
nah that’s my own line of enquiry
 
Aah ok haha
You're like me then. People often complain I change the subject in a way they simply don't realize it.
 
hey, you were the one barging in :) (jk, simultaneous conversations is a given here)
 
Hahaha I see that. That's normal.
 
2:19 AM
@LucDanton Threading: the single biggest strength of SO chat.
@MatheusRocha But the ability to press the up-arrow and edit is really nice too.
 
nwp
do things We out order of can!
 
@JerryCoffin What do you mean?
 
is new (this) a C++ FAQ item?
welp, first the Git mirror of GCC is borking up and now the C++ FAQ is timing out
 
nwp
popen isn't thread safe on my system, can't get more than ~117% CPU utilization no matter how many threads I have :(
 
@LucDanton it's an item in Exceptional C++
 
2:33 AM
alternatively I could use an SO question, but it’s rife with placement new nonsense so it’s hard to search
> declval<void>()
heh, that’s new
 
@MatheusRocha new pushes data onto the heap and you have to worry about cleaning it up afterward. You almost never need the headache of cleaning up, so don't use it. When you avoid using new, most of your data goes onto stack and gets cleaned up automatically when it leaves scope
 
oh, declval is specified in terms of std::add_rvalue_reference
 
Hello everyone,

After implementing singleton, is there a way I can actually detect that a user tried to create another object of singleton class?
 
what
 
hello, why do you need a singleton?
 
2:45 AM
@Aaron3468 Need one global instance of a class in the application
 
The function to get the instance is static exactly so that you don't create instance of the singleton class
Inside of it you can put any restriction you want
in C++ you can even use a static object for the function IIRC
Not sure how thread safe that is though
 
@hello You want to store global variables? Don't worry about making it a singleton; just instantiate it once. If the user decides they need two copies, it's their choice. It's surprising how often there's a good reason not to use a singleton, and threads come to mind as one.
 
so the spec calls for variant<int, void> v; to be valid for the sake of generic programming, but then e.g. get<1>(v) isn’t—which of course is annoying in a generic context
 
48
Q: When is Singleton appropriate?

FishtoasterSome hold that the Singleton Pattern is always an anti-pattern. What do you think?

 
of course even if it were valid and e.g. returned void then that would still be unhelpful a lot of the time
of course the variant proposal would come with a monostate which purpose is to be a unit type
 
3:05 AM
@Aaron3468 Aaah... I'll keep on doing what I was doing, and avoiding it. But thanks for that explanation :)
Well, it's 00:05 here and I still have work to do, so I must go now. Thank you all for your help. Have a good night people.
 
Singletons are a waste of time, if you wanted a global variable, just make a global variable.
 
speaking of generic programming, my casual reading of the proposal suggests that zero-size variants are okay
 
sizeof(QVariant) ==0?
 
I never understood why people would hamstring OOP for a marginal benefit and call it progress
Singletons are so backwards
 
I think I get it.
 
3:17 AM
@Mikhail Is that right?
 
probably its false
 
even
class MyTest {};
sizeof(MyTest) == 1
 
nwp
@Nican if you don't do this then iterating over containers of that type would only half work
 
@Nican in GCC that might return 0
See
30
A: Can sizeof return 0 (zero)

Michael BurrIn C++ an empty class or struct has a sizeof at least 1 by definition. From the C++ standard, 9/3 "Classes": "Complete objects and member subobjects of class type shall have nonzero size." In C an empty struct is not permitted, except by extension (or a flaw in the compiler). This is a conseque...

This is why some people say GCC is free as in sizeof(struct)==0
 
3:32 AM
@nwp Hehe, I never thought about that.
 
btw, has anybody figured out the black magic to link a library to the compiler properly (I think I managed it, but the library might have dependencies)? And is there a way to figure out which dependencies the library requires?
 
// To hornor algebraic data type, variant<> should be a bottom type, which
// is 0 (as opposed to a void type, which is 1). Use incomplete type to model
// bottom type.
guess I’m not the only one reading it that way then
hm actually leaving it incomplete does not comply with the spec come to think of it
 
@Aaron3468 In Windows you can use the Dependency Walker
 
Thanks Mikhail, I'll check it out. In the meantime, I'll mess around with a few simple libraries before linking the one I need
@LucDanton Something about the documentation makes me think there's a reason it doesn't comply with spec... A spelling error and comma-splicing
 
the C++ Standard (and assorted proposals) does not in general dictate what comments the implementation should contain, if any
 
3:47 AM
Indeed. I'm just observing that the poor writing brings to question the quality of the code, though the code may be fine.
 
@Aaron3468 perhaps unusually the code is written in C++ and not English
 
Alright, I'll drop it.
 
One place I worked at required that each function live in its own cpp file, and that each file have a paragraph documentation. This did not stop them from having a #define called isFortran 1 that would convert the code into a FORTRAN static analyzer rather than a c++ analyzer.
comments are for n00bs
 
I never was a fan of comments. Legible, efficient code is by far the best, followed by sparing, but effective comments when it can't be
 
//fucked
4
 
3:57 AM
//Concise!
 
4:33 AM
does this need any comments? everything's obvious, right?
 
Maybe a comment or two to establish context \\emulate cellphone keypad, but it's quite self-explanatory
 
@doug65536 I don't see how it answers the OP's question.
 
True, it doesn't repair/diagnose their code. I do think it serves as a great example of an alternative approach though.
 
@Aaron3468 Yes, presenting an alternative approach is fine but first and foremost the OP's question should be answered.
 
my honest response would be "wow. yeah, I wouldn't even try to do it like that"
I was going to do a code review like answer and pick apart their code, but I thought that would encourage continuing with that implementation
isn't "omg don't do it like that" a valid answer?
 
4:46 AM
It is. I think point out the problem, explain that their implementation makes it easy to mess up, and then present the viable alternative for future reference.
 
yeah, it is too terse, you're right
 
But you did get my upvote for really clean, readable use of templates :)
I edited the question so that it doesn't get downvoted to oblivion for being a bit messy
 
I changed aftershave so I gotta ask: is aloe vera supposed to smell like melons?
 
Maybe? I guess you could call it a melony smell xD
...and the first reviewer of my edit says that I should've just copied and pasted the edit as an answer (I didn't answer anything), or told the asker to come again after they fix their own formatting O.o
 
5:02 AM
error: mismatched operator in fold-expression before 'args'
     (foo {} + ... args).member;
that’s an unusually accurate message, given the typo
 
5:17 AM
mmh there wasn’t much talk of Boost 1.61 when it came out but I still missed out on it
 
I sure hope Boost.DLL is nice to use
> Major simplification of the getting started
 
5:39 AM
I’m a bit disappointed that it refcounts so much by default, but oh well it’s nice nonetheless
 
querying symbols in a specified section? really? I've never seen a native thing that allows you to specify a section
what would that even mean? querying .text vs .data? Why?
it lets you dig into symbols as in COFF symbols (for example)??
wow. why in the world would anyone want that for a plugin
 
I suppose it can serve as a basis for really low level code introspection, but I don't think it's necessary
 
5:58 AM
a bit late though. about 5 billion cross-platform DLL loader implementations have been written already
nice to know it is there though, next time
it is so trivial, few hesitate to whip one up
 
Boost is trying to compensate. It's losing its place as the de facto include
 
6:27 AM
I feel more naked on the internet than anywhere else on earth - everything on the internet is pretty spied on by various organizations: NSA, anonymous, various ISPs, other individual high capability hackers. It's like have multiple spy cameras installed all over your house!
Thick skin - your ultimate antidote to all set backs in real life, your most powerful & free tool to your success.
One set thick skin to counter 'em all!
 
> While Hana has better compile-times than pre-C++11 metaprogramming libraries, modern libraries supporting only type-level computations (such as Brigand) can provide better compile-times, at the cost of generality.
food for thought I guess
 
Ven
6:46 AM
Yo
@LucDanton if it doesn't habit anything, how can it be a bottom type?
 
@Ven by definition, but in a setting that handles 0/Void and e.g. non-termination as the same
which is not a given, of course
I’m not sure if I understood your question though
you have to be choosy when it comes to bottoms
sorry I can’t help being cheeky
@Dmitri pls stop being banned I need more audience
sheesh I completely missed that Boost.Test added a dataset feature a few versions back, I wrote complete garbage to work around the lack of that feature
lmao the Boost.Test datasets support joining, zipping, and product, add a flat_map and it beats Boost.Range 2.0 cc @R.MartinhoFernandes
 
7:24 AM
This is hilarious. :D
 
TUL: people actually use door stoppers :p
 
@Telkitty TUL?
 
7:41 AM
Today You learned
:D
 
My favourite is when you buy a Blu-Ray burner and an HDMI cable, and the cable costs half the price of the drive
 
Ven
@doug65536 copy assign vs ctor
 
@Ven yeah, looks a bit silly though for one to work and the other not to work. At least it doesn't default construct then do operator=, though
that would be more consistent but more wasteful in some cases
 
Ven
@doug65536 I know this is a joke because you said "consistent" talking about C++
 
lol
 
7:58 AM
@Morwenn May I suggest the following alternative, which is much more self-descriptive?
int iszero(int x){return

 !!!!!
!    !!
!   ! !
!  !  !
! !   !
!!    !
 !!!!!

x;}
12
 
-3
Q: What happens if one compiles and runs "sudo.cpp"?

Anonymous BookwormSay, hypothetically, that some dimwit (call him Mr. Mee) writes a sudoku-solver and names it, by an act of dizzying thoughtlessness, "sudo.cpp." What exactly happens if one compiles ("g++ sudo.cpp -o sudo") and runs it ("./sudo")? Does this irreparably erase the hard-drive? How does the terminal ...

 
probably because -INTMIN == INTMIN, at least the compiler is not too stupid
 
No, -INTMIN is undefined behavior.
 
well sure, but in reality a CPU can do a neg and the answer is usually just the input, unmodified. but yeah, the compiler isn't required to care what happens, sure
because neg is usually (~input)+1 in hardware
and (~1000...) is (0111...), and (0111... + 1) equals (1000...)
CPUs are free to throw really bad crashy exceptions or whatever, if they feel like it
x86 had an instruction for it even, INTO
raised an exception if OF bit of flags is set, one byte opcode. saved bytes over jno / INT 4
 
8:16 AM
android room has revoked my access privilege ...
😂
 
x86_64 dropped support for INTO IIRC, nobody used it
std::numeric_limits<T>::min isn't constexpr? you can't be serious
 
sure it is:
static T min();           (until C++11)
static constexpr T min(); (since C++11)
 
yeah that sounds right, what about the compiler saying it is non constant in my coliru link above
 
@LucDanton lolwut
 
@sehe I've reached a problem scenario with my PEG parser written in Python (although it's more to do with the fact that it's scannerless rather than PEG)
in the grammar for a toy programming language I'm writing statements are separated by newlines
 
8:23 AM
@Rapptz for docs, is your landing page simply a big ToC or do you do something else? I have a feeling that not doing it that way is going against the grain for no good reason, but I may have overlooked something
 
go ahead (I never use scanners in Spirit)
 
but, inside certain constructs the newlines are to be ignored
for example, inside the parenthesis of a function call
so these are two statements:
 
I can't ping any of android room owners to clarify things so I am just going to comment on their github page
 
a = 3 + 5
a *= f()
but this is one:
a = f(3 + 5,
        "testing")
 
Ven
this shouldn't really be a problem
 
8:25 AM
I see no way around this other than basically defining the entire language twice, once that allows newlines as whitespace, the other that disallows it
 
Nah. Just switch the skipper on the fly, like spirit does it?
 
@sehe my parser is scannerless - it does not have a skipper
 
Spirit Qi is scanner less
 
if it has a skipper, it is not :P
 
boohoo.
 
8:26 AM
either way, I don't have semantic actions either
 
Disagree. No mood for semantics argument. This is your solution. Like Ven said, it doesn't look too hard really
 
how would you switch a skipper in PEG?
 
7
A: Boost spirit skipper issues

seheIn general the following directives are helpful for inhibiting/switching skippers mid-grammar: qi::lexeme [ p ]which inhibits a skipper, e.g. if you want to be sure you parse an identifier without internal skips) qi::raw [ p ]which parses like always, including skips, but returns the raw iterat...

The point is all primitive parsers have optional pre-skip/post-skip
 
@sehe what is pre- and post- in skipping?
 
What is there to "clarify"? They don't want you in there.
You wouldn't want your burglars to "clarify" to you on github when you changed the lock on your door
@orlp Nothing, presumably. It's something in parsing
A question like that cannot be usefully answered IYAM. You're solliciting definitions that don't exist, won't add much and at best will (again) clash with your preconceived parser lingo.
 
8:31 AM
@sehe nah, I'm beyond being pedantic now :P
 
I'm not a parser afficionado. I just know how to do thing in CoCo/C++ and Spirit Qi well
 
I was just pedantic for one thing
I have an idea for implementing a skipper in PEG, but I'm not sure whether it's well-defined with the backtracking
 
I'd say just choose a consistent scheme. That's tricky enough, but not too complicated. You could always reassure yourself looking at Spirit's | operator with skippers :)
 
but seriously, what does pre/post skip mean?
not trying to be pedantic, just don't really get what the pre/post refers to
 
@LucDanton yeah
intro + toc
 
8:40 AM
Hi @Rapptz!
 
hi
 
@orlp For example. When char_ is asked to match any single character, it first skips all input while skipper matches. Some parsers will also skip after the match (I'm not sure whether Spirit does this and when)
 
ah
 
@fredoverflow Now that's sexy.
 
@Rapptz how do you handle the fact that a section ends up in the toc?
 
Xeo
8:53 AM
> Notable changes:

Bugs fixed
More bugs fixed
Removed some broken code
Solved some reported issues
Changed some incorrect things in the game
Even more bugs fixed
Added …
 
@Rapptz oh I guess the intro is a handful of paragraphs and you don’t need sections per se, you can use the document title
 
@sehe I mean, I have trolled 'em for a few days unintentionally. But some sneaky tard revoked my write access when I was on holidays without any explanations ...
 
> unintentionally
 
I went there to clarify some scoping issue but trolled 'em instead
Didn't mean to ... it was a typo
 
9:22 AM
A typo for a few days.
You made bad decisions. Now you have the consequences. Welcome to life.
 
Ell
I made one od them yesterday
 
You know the kind of things that fancy people the most - things that they can not get ...
If I am banned from certain things I would try to get unbanned or evade the ban even though it bears no importance to me
 
You know. We're not surprised.
 
9:29 AM
Go. Do something to end your boredom.
 
Ven
... like chatting in the lounge
 
@Morwenn neat, but what's wrong with moc compilation?
I guess it could be annoying, depending on the build system
 
I am not bored, I am trying to fix certain problem in one of my android apps
why else would I visit an Android chat?
 
@doug65536 Exactly that. Building C++ is already annoying, we don't need even more extra steps.
 
but I think I can fix the problem without their help, I like to ask for help then fixing a problem myself
 
9:35 AM
@doug65536 AFAIK, nothing.
It works fine and serves its purpose.
@Morwenn I build all C++ projects I work on with the same ease: by issuing a single command (be that on the command-line or a keyboard shortcut or a mouse click).
That actually extends to all programs, regardless of language.
 
I just hate when I have to write build files, so the less steps, the happier I am .____.
I guess I'd use header-only libraries everywhere if it didn't have its share of problems.
 
@Morwenn Supporting moc shouldn't require any extra steps. At worst a once-in-a-lifetime investment of a few minutes.
 
The few minutes always turn to hours with me, whatever the project and the compiled library to use :/
 
> qmake contains additional features to support development with Qt, automatically including build rules for moc and uic.
 
qt's ide natively supports cmake, qmake, both of which handle moc smoothly
 
9:39 AM
Anyway, I shouldn't even complain since I never use the C++ Qt.
 
@Morwenn Those minutes are to imbue the build system with rules for moc files. Should be trivial with any sane build system (and it's out-of-the-box with any of the typical ones used with Qt)
Actually, it's trivial even in the popular insane ones.
 
It's bad because I'm lazy and dumb.
 
The friction added by moc is really low. Yes, you have to learn a bit more of syntax, but the same applies to Verdigris since you have to learn their macros. It's the same.
Most arguments against moc are either OCD over some perceived purity of the build system or of the language, or that it is obsolete and the same can be done with macros and TMP.
Honestly, I'm not sure macros and TMP provide a better experience (error messages, anyone?)
 
Surprising realism from the Robot
 
Folks can you help me out with this stackoverflow.com/questions/37455800/…?
 
9:46 AM
I love it
 
I'm really OCD-driven when it comes to annoying things.
 
Oh, and since there's a stable meta-object ABI, moc hasn't been a requirement for a (long) while. You can use any introspection mechanism you can devise for C++; you just have to make it produce meta-objects that follow the ABI.
But just using moc is simpler.
 
I think I might have figured out this screen frozen when used in a moving vehicle issue
 
It Doppler shift on the pixel chromata, right?
 
Sorry, I hate to admit that I'm wrong, so I'll just quit the chat or whatever .________.
 
9:52 AM
(I don't know quite how fast the vehicle is moving)
@Morwenn hehe :)
 
I am calling search function too often when onLocationChanged
doh, that's only a suspicion, I need to log it to see whether that's the case
 
Fuck. I have zero willpower to do $JOB now.
 
> America’s nuclear missiles are still controlled by floppy disk
What a tech clash head line
 
@sehe Now, how are the Russia's controlled? :)
 
Probably well
 
10:01 AM
was it written in cobol though?
 
Ven
it better
 
10:21 AM
@sehe the older the better. A friend of mine has commodore 64 floppies that still work
early EE's were scared to push their luck
 
they were just floppies; there was no diff between commodore/PC IIRC. Just - maybe - different format layouts
 
you are correct. They used a completely different modulation when writing than IBM and later ones
 
@doug65536 that means your friend has access to a corresponding machine to work it with
 
yes. once in a while he modem transfers some floppies over
 
amazed
that a 30 year old computer still works
 
10:26 AM
yeah, they didn't push their luck in the slightest back then. the cpu isn't even pipelined!
a modern EE student makes more complex cpus as projects
hilariously, they added cycles to make sure that a store from the previous instruction won't be missed by a load in the following instruction. even if they are totally unrelated
even if neither has inputs, indicating that a few 10 input gates and a couple of mux units was too much to add
more aggressive designs from today would detect the hazard and insert a nop or something (pipeline bubble) and really modern ones have deep queues
 
nwp
is there a way to catch an exception from a constructor without code duplication?
 
Wrap it in a function
auto x = [] { try { return f(); } catch(...) { return g(); } }();
 
nwp
return a default constructed value when an exception happend?
 
Dunno. What do you want to happen when an exception happens?
 
nwp
continue or return
 
10:41 AM
You can have the lambda return an optional.
 
Is there a way to write to log when an IO exception occurs?
 
Or use that Expected thing
 
nwp
exception handling sucks
@Telkitty if the IO-error happened while writing the log then you need to get around that somehow (clear the error or open a different log and try again), otherwise the logging should be unaffected
 
11:03 AM
user image
5
 
@orlp Really? A start to this when I posted the same already some hours ago?
;_;
 
@wilx didn't see
 
@Mgetz Well, I would not buy a vinyl even if it was for free.
 
@wilx nice to know you're not a hipster
 
11:16 AM
@Mgetz Not that it is not cool, though.
 
11:59 AM
Seriously.
Eclipse's console output window has a limit on the number of lines it keeps.
What the fuck.
This is unacceptable.
What is it with people insisting on letting the RAM I paid for stand there being wasted.
It doesn't even have a sensible default.
10^9 lines is a sensible default. 500 lines isn't.
Idiots. Idiots everywhere.
 
@R.MartinhoFernandes Its probably one of those old settings that never got updated. Remember when you ran into MSVC's string literal length limit while working on nonius? Also, your fault for using Eclipse :P
 
@wilx what does it mean?
 
Under what circumstances will an std::ostream flush? Can it happen if .flush(), << std::flush or << std::endl are not used? I'm implementing an underlying streambuf and I want to have a good idea of when its .sync() might get called.
 
I'm not an expert on streams (please wait for the local expert while annoying music is playing...), but my answer is: whenever it can
 
who is the local expert? puppy?
 
12:14 PM
I have an output device, which can only output in visually distinct units. The output is meant to be read by humans. Imagine that it prints separate sheets of paper.
 
rightfold
 
I want to use a streams interface with it. I am not sure if "flushing" is an appropriate way to signal the end of a unit.
The user could just <<flush or <<endl to trigger the actual printing.
I want to avoid premature flushing not explicitly requested by the user.
 
I'd say Dietmar but I haven't seen him for ages here
 
At the streambuf level I control things, so I can ensure that an overflow won't flush. But I don't know if std::ostream does anything on its own that would trigger flushing in a way that would be surprising to the user.
In practice things seem to be working well ... but that doesn't guarantee that it won't get derailed at some point.
 
@JohanLarsson What does what mean?
 
12:38 PM
@Szabolcs At any time. Some streams flush constantly.
 
@wilx I don't get the hodör meme
 
go watch Game of Thrones
 
thanks
 
@JohanLarsson What @milleniumbug says. You need to watch the last episode to get it.
 
@Szabolcs Any output sent to std::cerr is immediately flushed.
 
12:40 PM
@R.MartinhoFernandes But I'm not talking about just any std::ostream. I mean one I created as std::ostream out(&mystreambuf).
 
and mystreambuf can be attached to std::cerr
using .rdbuf()
 
@milleniumbug I'm talking about the case when I implement the underlying stream buffer myself ...
 
@Szabolcs If you're writing a streambuf, you should expect to be used by any potential stream.
 
@Szabolcs me too
 
@Szabolcs Which means you don't know which stream will use it, which means it can possibly be cerr.
 
12:43 PM
@Szabolcs std::ostream os; os.rdbuf(std::cout.rdbuf()); // now I'm using stream buffer of std::cout here
 
@R.MartinhoFernandes I was trying to explain above why I am doing this and what I want to achieve .... I know which stream will use it. It's an ostream initialized as ostream something(&mystreambuf).
 
and I can access your buffer by calling .rdbuf() on your stream
 
Ven
which was that online compiler that showed the assembly? I'd really like to use it
 
godbolt, also known as "Compiler Explorer"
 
@Szabolcs flush is only called if you close the stream, call it manually or if it's tied to some other stream and if that stream got flushed
so what you have should be good to go
 
12:47 PM
@NaCl Thank you! That is helpful.
 
However, this assumes you just derive from std::ostream and not some more specialized stream
 
@NaCl Yes, that is correct.
 
@NaCl Not true.
Flushing happens in the destructor of sentry, which is run at the end of every member function of basic_ostream.
The destructor flushes if (os.flags() & std::ios_base::unitbuf) && !std::uncaught_exception() && os.good()).
 
Ven
  {
    std::lock_guard<std::mutex> lock(m);
    std::cout << "a";
  }
  {
    std::lock_guard<std::mutex> lock(m);
    std::cout << "b";
  }
Is the compiler not allowed to optimize that to a single lock?
 
@R.MartinhoFernandes Touché, used illformed wording
 
12:51 PM
@Ven Pedantically, it is.
 
Ven
"yes"?
 
@milleniumbug Dietmar Kuhl, Jerry Coffin /cc @JohanLarsson
 
In general (i.e. if you have other threads and if you have some general code instead of those output statements), no, it cannot.
 
Ven
godbolt.org/g/vFnl1C (so, not much code at all)
 
Pedantically, it can optimize your program down to no locks at all.
 
Ven
12:53 PM
mmh, but doesn't with -O3
 
Ven
it doesn't even inline f()
 
I think it does.
It's possible I missed it, but I see no call to f.
 
@R.MartinhoFernandes Could you please give a concrete example? Which specific member function of std::ostream do I need to call to trigger a flush?
 
@Ven That it keeps f's definition doesn't mean it doesn't inline it; removal of unused symbols is done by the linker.
 

« first day (2049 days earlier)      last day (2892 days later) »