« first day (2135 days earlier)      last day (2819 days later) » 

12:03 AM
@sehe Hahahahaha
 
Ven
12:18 AM
@Mikhail what do you mean?
Overloadable postfixes?
 
12:31 AM
@jaggedSpire hello~
@R.MartinhoFernandes This is getting pathetic at this point...
"We can't see past our money colored glasses and we think ya'll too dumb to notice."
 
1:06 AM
 
1:27 AM
@Borgleader :3
 
 
2 hours later…
3:25 AM
@Ven So, imagine every function has an optional finally block, which is always ran...
 
Ven
callee or caller side ?
 
the code lives in the function...
 
Ven
oh.
Even ruby has that.
def foo
  code
ensure
  code
end
 
yeah
 
you need to be exceptional for the finally block to be executed ...
 
3:29 AM
that didn't stop me from throwing from the constructor, or even the destructor
 
exceptional thrower, I like that ...
creator of UB
 
I'm pretty sure the compiler's job is to make the UB
 
compiler wouldn't make UB unless you allow it
 
idk, just invoke it
 
Ven
It's undefined whether it's the compiler's job; or if you're just getting on santa's naughty list
 
3:36 AM
I'm pretty sure santa's naughty list is reserved for -fpermissive
 
how do you know santa uses list, maybe santa uses arrays :p
 
nwp
because the list needs to grow?
 
Ven
Definitely a vector, needs to grow enough to fit telkitty
 
realloc comes to the rescue ...
 
std::realloc, else its C
 
3:39 AM
I mean, maybe santa does C
santa is fairly old ...
 
C++ is older than me
 
 
1 hour later…
I have just spent an hour to finding some mismatching bracket
 
No wonder China has invaded Tibet. I would too, just to stop this insanity.
 
6:15 AM
@wilx kill me
kill me now
 
6:30 AM
@набиячлэвэли Nope.
 
@AndreasPapadopoulos from someone else, titled "PvP right now"
 
 
2 hours later…
8:36 AM
Okay, I have a weird need. I need a way to tell the compiler that I want a particular virtual function to be overriden in all derived classes, but at the same time it can't be a pure virtual function, because I need the top level type to not be abstract :|
 
@Griwes can't you just make the base class method virtual and override it in each derived class separately?
 
@ChemiCalChems I want the compiler to yell at me if I don't override it somewhere.
 
@Griwes oh
you could assert in the base class whether the function is being called from the base or not
and if it's being called from a child class, it'd yell at you
 
eh, that's waaaaay too late :/
I thought about that, but I want a compile time guarantee :|
 
8:40 AM
It's not that I can't live without it, but tracking some bugs where I forgot to do something will be irritating without this. :/
 
8:52 AM
@Griwes wait, can't you static assert whether typeof(*this) == typeof(Base) or whateve?
 
@ChemiCalChems ...of course not?
 
@Griwes it's not constexpr, true
k
 
ADG
9:32 AM
hello people
 
@ADG sop m8
 
ADG
@Chem not much
still working on oop project
can't get what does it mean by 'no match for 'operator==' (operand types are 'X*' and 'const X')'
 
@ADG you cant compare a pointer to an object
do you mean *obj == obj2?
 
ADG
i have a vector<X*> vec
 
cool, those are pointers
not objects
 
ADG
9:43 AM
i am declaring an iterator vector<X*>::iterator it = vec.begin()
 
you have to dereference the iterator, and then dereference the pointer
**it
that gives you the object pointed to by the pointer in the vector pointed to by it
 
ADG
oh lemme try that.. thanks
 
@ADG np
 
ADG
@ChemiCalChems it worked
@ChemiCalChems in a function returning X* i have a switch case statement wherein i return various X* depening upon function's parameter but i gurantee that the paramter is only specific values so i don't have any default case or other case so it is natural by the compiler to warn me that function returnin X* not returning anything, so what should I do?
 
10:47 AM
@ADG return a nullptr as a default
that's what i'd do
i don't really know why you'd return a pointer, but if you are gonna do it, return nullptr as a default
 
nwp
this kinda stings
@ChemiCalChems because polymorphic types and factory pattern and all that unmaintainable nonsense
 
@nwp makes sense
then yeah, return nullptr
 
11:12 AM
@ChemiCalChems That's a terrible plan.
you should throw an exception.
 
@Puppy hmm...
 
returning nullptr just ensures that if the unforeseen should occur, your application will crash with no useful diagnostic information.
and that's if you're lucky
 
depends on what the function does, tbh
 
so your function has no point of failure?
 
his description clearly indicates that this condition would be a precondition failure
it's not the kind of thing you want to silently whoopsie
 
ADG
11:20 AM
hey i'm using this simple function:
template<class T> X* Foo::getX(int index, const T predicate) const {
	vector<X*> vec = getConstantVector(index);
	vector<X*>::iterator r = find_if(vec.begin(), vec.end(), predicate);
	return *r;
}
 
@ADG i'd say nullptr then
 
ADG
but the problem is the destructor of vec is called befor exiting function, so *r become some garbage value
@ChemiCalChems yes i did ... thankx
 
if you don't find the value you want, you don't rage
you simply don't return a value
 
that is a tremendously dumb thing to do
 
@Puppy don't see why
 
11:21 AM
you should only not return a value in cases where you explicitly permit it as part of the contract.
 
does std::find throw an exception? it doesn't
 
ADG
it will never occur
i prompt user to again enter a valid index
 
@ChemiCalChems That is for a totally different contract.
 
ADG
i just wanted that compiler could understand that ... hmm
 
@ChemiCalChems Unless the data cannot be retrieved, but the lack of data is data (web services for example), there should never be a point that the data becomes null; throw an exception when it cannot be made...
 
nwp
11:22 AM
@ADG can you not just return a X instead of X *?
 
@Puppy if it is, i obviously don't undestand why
 
@ADG This has nothing to do with it.
the value of *r will be retrieved before the vector's destructor runs.
 
ADG
@ChemiCalChems but it isn't working don't know why :(
 
if you're getting garbage out, the destructor of the local vector has nothing to do with why.
 
ADG
i used gdb and the pointer location changed after destructur
 
11:24 AM
@ChemiCalChems It's about being strict about what's permitted. std::find always returns a value- the iterator. Furthermore, std::find has explicitly as part of its contract that it may return the end iterator. If you have a function where it is not part of the contract that it can return nothing, you should never return nothing.
 
@Puppy understood
 
@ADG what does getConstantVector(int) return?
 
if there's some unexpected problem, always throw an exception.
 
ADG
@puppy oh.
@Chem when it is on line `return *r` the value of r is 0x62f3c0 and then it goes to line `vector<X*> vec =...` then r changes to 0x7ffff7839b78
 
nwp
@ADG who cares about r? You only care about *r which you return which should not change.
 
ADG
11:27 AM
oh @nwp
i checked it again became 0x62f3c0 out of the function where X* = getX(...)
 
@ADG Are you by any chance using a 64-bit computer? 0x7ffff7839b78 is the pointer address it is returning
 
ADG
@Aaron3468 yes
recently i faced a problem with running my code on 32bit pc
 
What was it?
 
ADG
hmm
but i think r was destroyed so it changed.. but *r was returned correctly
 
r is destroyed but only after *r is read.
 
ADG
11:32 AM
oh
how to declare two 100 line functions which are exactly same but one has const return type but the other doesn't
 
@ADG copy and paste
 
ADG
@ChemiCalChems any other smart way?
 
@ADG not that i know off, but @Puppy may destroy me with knowledge
 
templates maybe
(not sure what's the conversation about, haven't lurked enough)
 
Yeah, I'm thinking templates would be the best
@ADG What is the project you are making?
 
ADG
11:40 AM
c++ oop roombookingsystem
it's my first time anything more than simple for loops etc
but im very proficient in java
its for university
 
Ah, I see. Why do you need pointers?
 
if not facing with infinite rooms, you could make an std::map<Room, Client>
 
ADG
i am using std::vector<Room*>'s for Room and it's derived classes
 
@ADG oh, there is more than one room type
 
ADG
@ChemiCalChems it only includes bool booked not something more than a Client who booked it
 
11:42 AM
i see
 
ADG
i am trying to learn c++ through this assignment
 
std::vector already points to the objects in it; you are making a set of Room**
 
ADG
and still trying to make all of it on my own
 
Just do std::vector<Room> and you should be fine
 
@Aaron3468 he knows, that, i explained it to him before
what he could do is store std::unique_ptr to rooms
i'd say
 
11:44 AM
Alrighty then, carry on
 
ADG
@Aaron3468 no i want to do something like ((Lab*)rooms[2])->labVirtualFunction()
maybe with vector<Room> it might change to (*(Lab*)&rooms[2]).labVirtualFunction()
 
you do need Room* for polymorphic room types
 
ADG
bye. ThnakYou All of you for your help : @nwp @ChemiCalChems @Aaron3468 @Puppy
 
 
3 hours later…
2:44 PM
I can't think of ways to speed up this inheritance implementation without deliberately frontloading.
 
Ven
hi
 
/cc @jaggedSpire
 
pretty colors :3
 
Please make your comments better targeted next time @πάνταῥεῖ — sehe 9 secs ago
Again.
 
2:59 PM
@Borgleader If you run this script it will look like this. Handy as a quick references since I don't understand the color coding system at all.
 
neat
 
Ven
3:15 PM
..using the same text for each line is stupid :|
 
3:26 PM
I have a suggestion for his list: Beginners often define operator overloads in the global namespace because they think that's needed to make them visible to other namespaces.
I think learning the basics of name-lookup and ADL is useful even for beginners.
 
It's not useful to experts, because they already know
This was, obviously, only to be expected https://www.youtube.com/watch?v=Y4Zdx97A63s - I personally worry about the hormones of male presidential candidates
4
Imgur's summary imgur.com/gallery/PLXoF
 
user406009
3:41 PM
@sehe one issue is that those bad beliefs are much more prevalent in the middle East, as shown by pewforum.org/2013/04/30/…
 
user406009
Yes, there are idiots in the US ( and everywhere), but those surveys are very scary.
 
@sehe Oh my...
 
@StackedCrooked don't beginners want everything to be a member first?
 
Oh, yeah they do.
 
 
2 hours later…
6:45 PM
@Borgleader Choo choo, all aboard the 1080 train.
 
7:16 PM
@Borgleader :P
 
7:32 PM
Hello, Cruel World!
 
Windows users with bash. Linux users with PowerShell. FreeBSD users with WiFi. It's been a crazy year.
6
 
7:48 PM
cute girls with curly hair in avatars. cats and dogs living together
 
Ven
7:59 PM
OBVIOUSLY there's no VTC reason that's "move to codereveiw"
because clearly stats.SE is a more useful move location than codereview.SE
 
@Code-Apprentice Oh hey, you're around again!
How're you?
 
Yah, I've been around a little more the last few weeks. Doing pretty well. How about you?
 
I'm okay.
About to enter my last year.
Struggling with the menial classes, loving the hardcore classes.
 
1 message moved to bin
@Ven This annoys me everytime
 
8:44 PM
@ThePhD What's your favorite class right now?
 
Ven
rogue
 
9:42 PM
@StackedCrooked My suggestion: "writing a specialized operator< for a custom type in order to make it usable as keys in std::map instead of making a custom binary predicate comparator for the map"
 
Ah, I do that :)
 
Especially when it's not clear what semantics such operator< can have
 
Implementing a comparator template is such a burden.
 
I've never used those binary predicates. Always in-class operator.
At least that seemed a lot easier.
 
Sure, but I mean the cases where it either a.) it isn't quite clear what operator< should do b.) it does a weird thing, like comparing a person by how many items he has
Otherwise when it's quite obvious what does a comparison mean, then sure, go ahead
 
9:49 PM
@orlp I don't understand.. It's not interpreting that code live right? The music also plays if I introduce syntax errors..
 
@StackedCrooked That "emplacing a smart pointer" quite surprised me, tbh
 
I had heard it about it before on a boost-con vid.
I rarely use emplace.
There's one fun case though:
 
Not a fan of emplace either
 
std::vector<std::pair<int, int>> vec;
vec.emplace_back(3, 4);
This I like.
I've also used it with vector<thread>. But not 100 sure if that's the best way to do it
// only recently learned that starting threads can be delayed like this:
std::thread t;
t = std::thread([]{...});
 
lol, I almost exclusively use emplace.
 
9:54 PM
Honestly in C++11 there isnt really a reason to use push_back
afaik
 
emplace_back allows you to bypass explicit constructors. That's a scary thing.
Also Scott warned us that emplace will be slower when used on node-based containers in case of duplicates.
map[key] = value; // take that emplace!
 
@StackedCrooked Incidentally it's also the reason I don't use it by default
 
@StackedCrooked How is that "bypassing"? It's literally explicitly in-place construction, no?
@Borgleader aggregates
 
I mean it removes the need for being explicit.
 
Hmmm, now I wonder, how does emplace_back handles aliasing with the container itself
 
10:04 PM
@Mysticial I favour it. But gcc4.6 doesn't support it thoroughly. Soon ... we'll have ditched that version
@StackedCrooked It doesn't. It is /just as/ explicit.
 
It did actually lead to bugs according to the presenter. (I think it was David Stone.)
 
My tingly senses are telling me it probably doesn't
 
You just have internalize that emplace constructs value_type
@milleniumbug Aliasing?
I love how emplace_back can magically inject the needed (stateful) allocators when using scoped_allocator_adaptor. And it recurses
 
@sehe v.emplace_back(v[2]); when v has to reallocate
 
@milleniumbug Hehe. That's evil. I'd like to think it's UB
Because, as I see it, it would forward value_type const& into the copy constructor for value_type, but it will do the reallocation first. Making it a dangling ref
 
10:07 PM
Most likely
BTW .push_back explicitly supports this case
 
^ Found it.
Not saying it's absolute truth.
But he made a good point.
 
10:27 PM
@StackedCrooked He makes a "correct" point (if you pass 1 argument and don't want to get conversions, use push_back).
But it's very very meh and moot as there literally never was any reason to call a constructor besides copy/move in that case, making emplace_back clearly irrelevant.
Emplace back is expressly for constructing, i.e. it is explicitly calling constructors. Don't be surprised if it... you know, call constructors.
If you just want to copy/move, don't do that.
 
Yeah.
My current approach is to choose push_back by default unless there's benefit in using emplace_back. If both are equally fine, then I use push_back.
I've noticed a colleague starting to use emplace_back everywhere.
There's the belief that emplace is magically faster than push_back.
And I hate this code where stuff is sprinkled with magic dust to make it go faster. Like he used to put throw() on all his functions.
And now he discovered constexpr. Everything is constexpr.
I recently optimized a very important bottleneck in our codebase by replacing his low-level sem_post trickery with a simple mutex and condition variable. That felt pretty good :)
I did really fine tune it though. Only calling notify if the container was empty before. And not notify under the lock. And use batching. All the stuff I toyed with on coliru last two years :)
Speed went from 6Gbit/s -> 9.4 Gbit/s :P
Anyway.
So that's why I don't like emplace_back.
 
This is cracking me up youtu.be/VLaY4sLXNBM?t=501
Stupid thumbnail. It's a timed link. Not the thumb
@StackedCrooked Yeah. That makes sense 100% of the time. It's just good to always /consider/ it.
 
Sure.
 
@StackedCrooked It can be :) It's not always applicable. It's just more of "say what you mean" and in [l|x|r|pr|...]value land you'll always have options
 
It makes those times when I do use it all the more special :)
 
10:42 PM
> And not notify under the lock
That's ... only a smart choice if you don't ever expect to starve threads.
@StackedCrooked Indeed. I think people who over-use emplace try to cut down on the "thinking" part. Which is nearly always a bad choice, unless (a) you don't need c++ anyways (b) you have the proper abstraction hiding the performance sensitive things anyways
@StackedCrooked Tell me about it :|
 
The problem is that if you notify under the lock then the thread that wakes up will need to lock the mutex. And it will fail, and go to sleep again. Perhaps the kernel is smart enough today to avoid that. But I heard it can be a problem.
 
@StackedCrooked I love emplace_back. You should too. I don't like mono-thematic thinking coworkers.
@StackedCrooked It can't. Of course the woken thread automatically gets the lock, as guaranteed by the kernel. Anyhoops, that's assuming std::condition_variable::wait_until(lk, lambda) interface
 
@sehe Very often he does things that makes code slower. Like adding an empty destructor with throw() to pod-like types. (He once heard that throw() can sometimes make the compiler optimize better.)
He likes to see his magical speed sprinkled everywhere. He'd be better of by measuring stuff and learning proper C++.
 
Teehee. The worst I do when I'm not sure about which things are still auto-generated, is adding (potentially redundant) =default; special member decls
 
Yeah. Me too.
 
10:47 PM
@StackedCrooked Not on trivial destructibles (because nothing beats a skippable dtor)
 
Adding a destructor removes both trivially_copyable and trivially_destructible. Those are big ones.
@sehe Exactly.
 
@StackedCrooked I fully admit that sometimes I cop out because my mind doesn't have the capacity to remember the 12x12 matrix of autogeneration scenarios :)
But at least I know what I know and when to look it up.
 
Also using bitfields. Like a single bool with a single bitfield.
 
There's something to be said for that. Unless it's actually true/false semantically, of course
 
It was a member variable that indicated ownership (whether or not he needed to delete a pointer in the destructor.)
Which is also bad thing IMO.
Optional ownership is eew.
 
10:50 PM
I think it's in the >>1 vs. /2 realm there; the compiler will optimize both equally well. Of course bitfields have less features - but that makes it the stricter contract, which has some merit
@StackedCrooked Code smell to begin with
 
@sehe Luckily he hasn't learned that one yet.
 
@StackedCrooked Very much so. Our code base has this smell and it hurts analysis
 
@sehe I recently read some Linux kernel code and they use that everywhere. (>> 2 and stuff).
 
Linux kernel is C. And supports antiquated compilers, probably
 
@sehe I briefly used it and then switch it to be always non-owning. It made the code so much simpler.
 
10:54 PM
Yeah. I hate when things have umpteen flavours just because the (lib) devs couldn't make up their mind.
Less is a lot better. Especially when un(der)documented
 
Recently encountered this:
/* --- this MUST be deleted here */
// delete obj;
The delete was commented out :P
Also this one:
    // NOTE: It was clean to lock the interface here, but it is too expensive and not required.
#if 0
    ScopedLock lock(mInterfaceImpl.mSendMutex);
#endif
 
That's just hilarious.
what is "clean" about locking? And if it turned out to be unneeded, then why didn't you just delete the code?
Fix the code and clean it up.
explicit VlanHeader(VlanId myVlanId) noexcept {
    this->vlanHeader[0] = 0x81;
    this->vlanHeader[1] = 0x00;
    // --- OK to reinterpret_cast + write the value (no compiler optimization issues):
    //     Since this->vlanHeader will not be returned or used in further code in this method
    *reinterpret_cast< std::uint16_t * >(this->vlanHeader + 2) = htons(myVlanId);
}
^ Compiler warns about strict-aliasing.
If the compiler warns about strict-aliasing then you don't counter-argue. You fix the code!
So stupid.
Like the compiler is gonna back down and say Oh hey I guess you're right.
Code base is full of stuff like that.
 
@StackedCrooked they felt safer... but someone convinced them it was not necessary?
@StackedCrooked It's the same everywhere.
Improve the world in baby steps
Or stop using c++ :)
 
If you are not sure about whether or not a lock is needed then that's a really big issue. You need to manage that stuff really tight.
Causing a memory leak should feel like a personal failure.
:P
@sehe Luckily, I have good colleagues too :)
 
11:05 PM
Phew
 
I love this:
Such a great summary.
Generality is intriguing me. I need to think more about that one.
I suppose generality matters a lot if you are going to design a system like unix.
@sehe Dude, you should see the Java code.
 
Are you sure
 
You probably should not :P
 
I'm thinking the same. At least for the day.
Wow. This is some strong stuff. buzzfeed.com/michelledean/…
You hear about Munchhausen-by-proxy but the actual stories are rare. (Halfway now)
 
@sehe Damn that reads like a horror story.
Stopped reading it for now.
 
11:16 PM
Yeah. We can probably count down to the film
 
Ven
11:32 PM
if I write
template<class T> struct s{};
template<class T> struct s<T, std::enable_if_t<std::is_same_t<unsigned, T>>> {};
template<class T> struct s<T, std::enable_if_t<(decltype(struct s<T>{}, std::is_integral_v<T>) && std::is_same_t<T, void>>> {};
that'd be an infinite loop. Can the compiler detect that the decltype throws it in an infinite loop and instead evaluate the 2nd part (which is gonna be false, and thus stop recursion)?
 
Only with sfinae
Implying partial specializations (or constexpr overloads with tag dispatch)
 
Ven
yeah, it's with SFINAE
I'm "answering" this:
0
Q: Infinite recursive template instantiation expected?

bluescarniI am trying to understand why a piece of template metaprogramming is not generating an infinite recursion. I tried to reduce the test case as much as possible, but there's still a bit of setup involved, so bear with me :) The setup is the following. I have a generic function foo(T) which delegat...

but I wasn't sure the compiler was allowed to "detect" the infinite loop and instead of evaluate the rhs of the &&
 
@Ven I thought you meant as a boolean shortcut in costant context. That can't work, because it already is an instantiation error. (Would be nice to have decltype_or<void>(expression) that returns void if expression is an instantiation failure)
 
@StackedCrooked You ARE interpreting that code live!
 
Ven
wait, that's totes wrong. void f(...); just takes over template<class T>...
Okay, let me rewrite my answer.
 
11:39 PM
I don't have proper error handling in place (it doesn't show you syntax errors unless you open the F12 console).
if you introduce syntax errors it just keeps the old version loaded
just so the music doesn't randomly disappear
but the second you enter error-free code and hit ctrl+s the music changes
and it saves the current time you are at, so you can have live changes during a song (for example adding extra reverb)
@StackedCrooked the code runs on your GPU
GLSL is the opengl shader language
 
Ven
@sehe no, I'm still wrong. fuke me
@sehe (also, would require compiler support)
I still don't understand how the compiler does it; then.
 
Are you saying it somehow works? I didn't look too closely. If so, there might be partial ordering magic. That stuff is tricky
 
Ven
it does; and I don't understand why.
 
To keep things easy for my self I always make every instantiation condition explicit and tend to group overloads into classes. Overloads of member functions do not exhibit partial ordering semantics found elsewhere, and it gives me peace of mind that I can forget about it then.
Disclaimer: I'm not a big fan of meta-programming. I find C++ treacherous enough as it is.
 
Ven
well, mh. Not sure...
struct foo_impl<T,std::enable_if_t<has_foo<unsigned>::value && std::is_floating_point_v<T>>>
And since has_foo SFINAEs on foo_impl, the lhs of && should infinite loop...
 
11:58 PM
@orlp Ah, I didn't see the Ctrl+S message.
I see it also uses the Ace editor :P
 

« first day (2135 days earlier)      last day (2819 days later) »