« first day (333 days earlier)      last day (4614 days later) » 

12:03 AM
High Frequency Trading, inside look. Rather scary, I'd say.
 
12:14 AM
hello?
 
@TonyTheLion At one time 1 MB was a lot of RAM to have in a PC. It was more than would ever be needed according to Bill Gates. And now the OS alone requires 1 GB RAM, it can't function with less, and applications are more memory-hungry than the OS.
 
real quick question about
STL vectors and pairs
using std::find, how would I find a value in the second value of an std::pair<int, int> in an std::vector<std::pair<int,int>?
 
@AlfPSteinbach quite a big change eh
 
@sbi I do find text interspersed with bold italics all over a bit harsh on the eyes. Personal opinion aside, I find it rude to go and edit someone's answer just for the purpose of changing that. Let me express myself with my style.
 
@RMartinhoFernandes do you ever sleep?
 
12:21 AM
@Rabenholz google "std::find". that gives you reference.
 
@TonyTheLion Robots don't sleep!
3
 
I'm just getting kind of caught up in the syntax
 
Yes, I do sleep. Don't tell anyone.
 
I have
std::vector<std::pair<int, unsigned int>> attrib;
std::vector<std::pair<int, unsigned int>>::iterator it;
 
@Rabenholz personally, i think it's silly to waste time on adapting STL algorithms, when you can just write a for loop or something. The directly written code is easier to understand and faster to produce. Plus it's generally also more efficient.
 
12:22 AM
@RMartinhoFernandes lol
 
@AlfPSteinbach hmm
I guess what I'm wondering is how to read the second value of a pair, while it is in a vector
do I have to return the pair first?
then read the second value of that?
or is there a more efficient way?
 
@Maxpm 1) Books become out-of-date quickly? Consider a book on C++03. It took 8 years for it to become out of date. 2) Web-based resources also become out-of-date.
 
@Rabenholz v[i].second or, if you want range-checking with exception (possibly best for beginner), v.at(i).second
 
what if I want to use an iterator to access it?
 
You do it with the same syntax you would use if the iterator was a pointer: it->second.
 
12:37 AM
they looked better, not as fragile
 
@RMartinhoFernandes Ohhhh, okay
thanks
I guess I just didn't understand what the std::vector<>::iterator was making
its just a pointer to the value in the vector, right?
 
Technically, no (it could be implemented with a pointer under the covers though).
 
21
A: Why is this program erroneously rejected by three C++ compilers?

Robin DuckettOCR Says: N lml_�e <loJ+_e__} .lnt Mk.,n ( ln+ _rSC Lhc_yh ) h_S_ _l s_l . co__ <, " H llo uo/_d ! '` << s l� . ena_ . TP__rn _ | _| Which is pretty damn good, to be fair.

Look at the comments.
 
But the syntax for using them is the same.
 
okay
I guess I'll look more into templates and the STL iterators then
I'm fairly new to all this
thanks for your help
 
 
4 hours later…
Needs more cowbell.
 
7 hours ago, by Maxpm
3) I'm catching a cold.
@Maxpm Any idea who threw it? ;)
 
I poke over old unanswered questions from time or time and if anything's been sitting around and I feel like I might get some awareness out of it, I'll try and learn enough to answer it.
So I learned Lua and poked around with VLC playlist parsing to answer this:
4
Q: VLC Scripting with Lua: Jump to a specific time in a file?

PaulThis seems like it should be simple, but I'm coming up empty handed here. I'm trying to make a simple VLC script that checks if the "random" button is on, and if so when it jumps to a random file, instead of starting at time=0, it starts at a random time. So far, it's looking to me like it shoul...

I can now induct another mediocre glue language into the annals of "languages I don't see the point of"
 
Says a lot about the compactness of Lua!
@HostileFork The runtime you embed is smallish!
325kB is small right?
(For a static library.)
 
Computers these days have a ton of interpreters, if people would just agree on one that had decent coverage then we'd be a lot better off.
 
5:12 AM
@HostileFork Is the problem then not with implementations and not languages?
 
I don't know if I can point to a single thing as "the problem" but instead of making languages that are syntax-compatible subsets of one that already exists people just make up new nonsense
 
@HostileFork I just liked the guitar playing, when I went to high school. Yes it's that old.
 
Starting comments with two dashes instead of two slashes, or whatever.
 
@HostileFork That doesn't sound like what Lua is.
@HostileFork This style has existed since the 70s or so.
For the record Lua is an 'accident' in that it was a language for non-programmers. It became popular quite after the fact.
 
Anyway, looked around in the sources for VLC too
All this straight C code saddens me
 
5:24 AM
In need of some queer C?
 
@HostileFork Look in the source for gcc and you'll find not only C, but K&R C. Or at least it was that way. It's enough to make you wonder, what language is this?
 
I hope someday things do get rebuilt on a better and more "beautiful" bootstrapped foundation. Not holding my breath.
 
At what level would you start? Hardware? Firmware? Kernel? Higher?
 
1
Q: Binary AND and OR operations

ycshaowhy this code gives me 1 rather than 0?? a || b should give me 1 and 1 && 0 is 0, right? I don't think logical operations evaluated from right to left. int main() { printf("%d\n", 1 || 1 && 0); return 0; }

 
5:32 AM
^ dancing in the ruins, from 1986
@jweyrich there's an old C example of precedence, I think it goes x? a : b = 87 he he
 
Got downvoted by someone who claims the operator precedence is important there. The operator isn't evaluated because of short-circuiting. Hopefully my last comment clarifies.
 
@LucDanton - Well, I'm a fan of (large parts of) the fringe Rebol project's design. It's written in C and its "kernel" is closed source. But an open source fork of it is being pursued by people with more ambitious goals to bootstrap it through a "system dialect" that's a subset of Rebol chosen for the domain.
 
@jweyrich but short-circuiting would not come into play for that Q except for (effective) precedence
 
@AlfPSteinbach what do you mean by "except for (effective) precedence"?
the expression is evaluated left-to-right. It doesn't matter if && has higher precedence than ||. 1 || x is 1.
 
5:38 AM
@jweyrich (1 || 1) && 0 would not short-circuit out the &&
 
@AlfPSteinbach correct, but () have precedence over the other operators. They answered that && has higher precedence than ||, which is a correct assertion, but it doesn't matter for that example where the short-circuit takes place.
 
@jweyrich well i was just simulating other precedence. i mean with other precedence you would get different result. yes?
 
@AlfPSteinbach yes. But for the original expression, && has higher precedence than ||, but it won't be evaluated.
 
I mean consider if || had higher or same precedence as &&. Then the evaluation would be (1 || 1) && 0. With result 0. Different. Because of different precedence.
 
@AlfPSteinbach no, because || short-circuits (if there's no parenthesis).
 
5:45 AM
I like the example I gave, x? a : b = 87. If assignment has highest precedence, this should be evaluated as x? a : (b = 87). But is it?
@jweyrich || short-circuits but the result would be different.
also && short-circuits
 
@AlfPSteinbach think as each operand as a function (returning the same values). f1, f2 and f3. Suppose || has higher precedence, then f1() || f2() && f3() would still be 1. f2 and f3 wouldn't be called.
 
no you don't need to convince me, you need to find out what's making you not see that you're wrong. i don't know because i've already given you the facts. there's some blind spot thing here.
ok let's say that f1() returns 1, f2() returns 1, and f3() returns 0. as in the OP example
and we let || have highest precedence
then
f1() || f2() && f3() is by precedence equivalent to (f1() || f2()) && f3()
in the first sub-expression short-circuiting comes into play, so f2 is not called
the result of first sub-expression is 1
this left operand prevents short-circuiting of the &&
and so f3 is called, with call result 0
 
ah ok, you mean that f3 would still be called then.
 
and total result 1 && 0 which is 0
 
ok, I see what you're saying now.
 
5:50 AM
yes
 
ok, I think I should remove my answer then.
 
didn't you already?
 
thanks for helping me to think this way.
 
you're welcome
 
Ahh! I just caught the source of mystery OS-sounding jingle noise on my machine! It's a malfunctioning power management feature in a VM...and the reason I never see anything is that it only kicks in when I have the window minimized or in the background.
 
6:00 AM
oops, 3am, I better get some sleep. cya
 
 
1 hour later…
What kind of shell uses '%' for the prompt?
 
c-shell perhaps? yes, oui, da, confirmed
 
7:32 AM
@LucDanton Any of them can. Most shells allow you to set the prompt.
@LucDanton try echo $SHELL
 
@TuxD Err, I get /bin/bash, as it should. My prompt has always been '$', I was just reading some session.
 
@LucDanton It varies a lot. Try export PS1=My Prompt>
 
@TuxD I like $ better, although if you have a nice suggestion I'm all ears.
 
PS1 is the variable used as the prompt. You can set it to anything. It can even be dynamic. A lot of people set it so that it is the current directory. See here cyberciti.biz/tips/…
Or hostname is popular if you use ssh a lot onto other systems.
 
7:47 AM
[\u@\h] \[\033[01;31m\]\w #\[\033[00m\].
 
@CatPlusPlus Missing space makes me go crazy.
 
Missing where? After #? There is, I copied from echo $PS1.
 
@CatPlusPlus You suggested SCons to me some time ago and now I'm in build heaven (a place I had no idea existed).
 
8:10 AM
@LucDanton :)
 
8:37 AM
Me too!
Also, hi.
 
Hi.
 
Me too!
Wait, did the chat post something I said twice?
 
I posted something on CodeReview last night. I'd be grateful for any feedback :)
 
@RMartinhoFernandes Just starting to read it, but would it be that inconvenient to support move-only keys?
 
8:44 AM
hmm, I should probably start using that site. Could be nifty
 
@LucDanton I wonder how meaningful that would be.
 
sbi
Yay, @jalf solved my problem! Please upvote him!
 
@RMartinhoFernandes Two ways of writing generic code. Either specify up-front the requirements on types and then use that, or write the code and then figure out the tightest requirements that can make the code valid. Top-down vs bottom-up. Obviously you're using the first and there's nothing wrong with that, I just want to know if that requirements can be tightened out of curiosity.
 
There's something about the idea of moving something into a "get" function that I don't like, but I'm open to persuasion.
 
You mean how weird lookup[std::move(key)]; looks?
 
8:47 AM
Right.
 
@sbi Done :)
 
lookup[fetch_key()];
 
sbi
@TonyTheLion Thanks. His answer was a bunch of long shots, and one hit right on target. I love it when that happens.
 
@sbi The tags made me run away, sorry.
 
sbi
@LucDanton Yeah, they would scare me off, too. Unfortunately, I just have to fiddle with this stuff. :(
 
8:51 AM
@sbi Cool ;)
@RMartinhoFernandes Are you just implementing that for fun or is that part of production code?
 
@TonyTheLion It's going to be used in my BitTorrent client.
 
@RMartinhoFernandes Are you on a specific side of the unsigned vs signed debate?
 
@RMartinhoFernandes oh kewl :P
 
@LucDanton Sorry, I don't understand what you're talking about.
 
@RMartinhoFernandes Okay; why are you passing and storing std::size_t for the capacity?
 
8:53 AM
Because size_t is the type for size related things?
 
Right; but it's unsigned.
 
Or is it badly named?
@LucDanton That hurts?
 
@RMartinhoFernandes One side of the debates advocates using unsigned types for bit related stuff only.
Unsigned types come with unsigned arithmetic which can hurt around 0.
 
Oh, I see. I'm not on that camp, then.
 
The other side wants to be able to use unsigned types for quantities that are not meaningfully negative.
 
8:56 AM
@sbi wow, that was a complete shot in the dark :)
 
Like most things it's a heated debate but the only things that matter is that you are consistent and do not mix signed with unsigned types.
 
Oh, I don't mix them. Past bitings got my eyes sharp for that. :)
 
sbi
@jalf Well, svn blame found me the guy who checked that in. I'll pester him now...
 
@RMartinhoFernandes Ah well, now perhaps you'll notice I even use int for things like get.
Is there a traditional interface to LRU stuff (like pop and push are traditional for stacks)? I would have named evict evict_one.
 
Don't know about that.
Note that evict is private. The only parts of the client interface are get_or_add and flush.
 
9:00 AM
I spend a lot of time on names :)
 
I noticed :)
 
Also I'd rather talk about names in chat than in a review if I get around to writing one!
I feel like there's a problem when it comes to your empty list and size 1 list situations.
 
Why?
Note that the list can only grow, or be reset (hard) by flush.
 
does Anybody know a good third party string class which has functions like "StartsWith()" "IsDigit()" "SubString" and "EndsWith" ?
Something like the C# System.String.
 
@IntermediateHacker The Boost string algorithms include lots of stuff like that.
 
9:05 AM
@RMartinhoFernandes Thanks
 
@RMartinhoFernandes Heh, I think the current review makes a better point than I could ever do regarding the list stuff.
It just takes too much to reason about the list right now.
 
I considered and discarded a circular list idea because of the need for a sentinel. I didn't want to add a DefaultConstructible requirement. But maybe I oversaw things a bit.
 
Aren't there circular lists without sentinels?
 
In that case, I need the null checks anyway.
 
Anyway, my only problem is with push_front. I keep rereading it and each time I know it's correct but my brain is nudging me.
 
9:14 AM
Remember/notice that it is only called with an entry that is out of the list.
Can you put that itch into words?
 
Well
All I want is stare away from the code, not think about it and do something else.
 
Note that you can write the cache_entry constructor as cache_entry(Key key, T value): key(std::move(key)), value(std::move(value)), ...
 
Good point. And I don't really thing it would take a lot of work to support move-only keys.
 
9:23 AM
There is such a thing as std::hash<std::unique_ptr<T>> after all!
 
I don't think I'll be using them, though.
I'll give it a try anyway.
I'm doing this to learn, after all.
 
I wish there was a reasonable way to name your get_or_add member operator[].
 
I'm not passing a tuple!
 
To what?
 
Oh damn, I forgot to pass the Pred thing to the std::unordered_map.
@LucDanton To operator[].
 
9:27 AM
That would be silly. I did say reasonable.
 
Right. I tried to, but didn't waste much time on it.
 
I think there are 3 reasonable-ish ways to do it, each with their drawbacks.
 
Fire away!
 
The one that is used with e.g. Luabind is for operator[] to return a proxy.
Such that o[key] = val; will insert.
And object p = o[key]; will return the value.
Drawback is that auto p = o[key]; has to be taken into account now.
 
Right, nasty.
 
9:30 AM
i.e. p.some_member(); won't do what the user will expect.
 
But o[key] = []{ return blah; }; doesn't look that bad.
 
Second approach is to publicly admit that you're returning a proxy.
i.e. yes, object p = o[key]; o[key] = val; auto p = o[key]; all work, but you'll need to do p->some_member(); if you use the last form.
Drawback: strays from the conventional uses of operator[].
Third approach is requiring default construction.
 
Of keys, values, or both?
Values, right?
 
values, the key is passed to operator[].
 
I'll be caching mapped_regions at some point. Out of the question.
 
9:35 AM
The last approach is what std::map does, more plainly.
 
Oh, regarding the first two. Note that usage equivalent to x = o.get_or_add(k,v); would be x = o[k] = v;. A bit weird, don't you think?
 
Either is in my opinion.
I suppose what I really cared about is providing operator[] along, not straight replacing the member.
I think I use find much more than operator[] on maps.
 
I mostly use find for retrieval and operator[] for insertion, if the values are default constructible.
I wonder why there's no map::insert overload that takes two arguments instead of a pair.
 
I think list initialization is a better fix to that problem!
 
Oh! I keep forgetting about that!
In map.insert({ key, std::move(entry) }) the compiler would deduce this correctly to a pair?
 
9:44 AM
Just had an idea — overload operator() instead of operator[], and throw all the arguments into a single composed hash function. Then as well as a cache, you have a memoization functor adapter.
 
Well, those are two ideas.
 
9:57 AM
hello
 
yizzo
 
10:12 AM
read up on the cats of war, you
 
ok now I am terrified
creepy
They shouldn't use animals this way :O
 
Yeah, sending all those homo sapiens to war sounds barbaric.
 
they are intelligent and capable of moral decisions.. Was their choice but common, cats
 
Still sounds barbaric to me.
 
Oh please, don't tell me you're taking this seriously.
 
10:20 AM
Stealthy killers… they're the natural choice. Cats have no remorse.
 
I mean, if you can believe in cat paratroopers, there's no hope for you.
 
Hope nazi!
 
10:34 AM
lol
 
2
Q: To "if, if, if" or to "if, if else, if else, else"

qonfI am writing some code for data analysis, and have to exclude samples base on some criteria. In practice i end up writing code such as: bool Test(SampleType sample) { if( ! SubTest1(sample) ) return false; if( ! SubTest2(sample) ) return false; if( ! SubTest3(sample) ) return f...

I like the title.
 
@RMartinhoFernandes How come you implemented your own list instead of std:list or std::forward_list, using splice/splice_after?
 
@Potatoswatter Mine is intrusive :P
(And yes, I tried Boost.Intrusive first.)
 
hmmm. malloc is a bitch.
 
10:42 AM
I wonder if you can create an Allocator that obtains storage from a container, to sidestep the pointer islands without intrusion.
Since allocators can officially be stateful now.
 
@Potatoswatter Yeah, would have to be std::deque though.
What with the invalidation guarantees.
 
I need intrusion for functional reasons too. I need to obtain a list node (or an iterator if I were using a std::list) from a map iterator in the touch function.
 
(Of course it can be node-based containers too but meh.)
 
@LucDanton How is deque any different from list? Neither allows you to allocate an array, i.e. more than one object at at time.
 
Whoah, you just changed your requirements. First it was about storage, now it's about arrays. Don't blame me!
 
10:45 AM
Hmm… list node into map for evict… map into list node for touch
 
sbi
@LewsTherin Stupid question!
 
@LucDanton Then I misunderstood why it would have to be deque. What's does deque have that list doesn't?
 
@sbi But which one is easier to read and maintain?
 
@Potatoswatter Better locality (up to QoI).
 
sbi
@RMartinhoFernandes For me it's the one where everything is nicely aligned under each other (if if if). But that's certainly debatable.
 
10:47 AM
really? mmn
 
sbi
Anyway, the only good answer got downvoted. Stupid SO.
 
Downvote worthy? Maybe not. But it doesn't address the readability/maintainability, that the question also mentions.
 
But it's an incomplete answer.
 
What's up kids?
 
Nuffin.
 
11:03 AM
I can't believe I wrote this comment and it's relevant.
 
how boring.
 
> I like ice cream. – R. Martinho Fernandes just now
 
11:25 AM
With SCons is there a smarter way of doing env.MergeFlags(env.ParseFlags(blah))?
 
MergeFlags will call ParseFlags if blah is not already a dict.
 
Oooh forgot about that.
 
Found an issue with move-only keys. I'm duplicating the keys!
 
@RMartinhoFernandes What key type is that?
 
It's not an issue with the keys, it's with my code.
cache_entry entry(key, std::forward<Tf>(value));
auto item = std::make_pair(key, std::move(entry));
The entry should just keep a pointer or something.
 
11:32 AM
And the entry needs the key to remove itself from the map or something?
 
@LucDanton Yes.
 
cache_entry entry(std::move(value));
auto inserted = map.insert({ std::move(key), std::move(entry) });
inserted.second->iterator = inserted.second;
Then later you can map.erase(entry.iterator);
 
it.second->iterator = it;
 
Sorry, std::map::insert doesn't return an iterator.
 
Right, that's what'll be doing.
@LucDanton The iterator comes first though.
 
11:35 AM
Huh.
Can't edit now!
 
So, it's inserted.first->second->iterator = inserted.first;. Bit on the ugly side :(
 
inserted.first the second time, too?
 
Right.
Damn, pairs are confusing.
 
Stupid pairs.
 
My excuse is that I'm doing all that from memory :p
 
11:37 AM
My excuse is that I'm doing auto it = map.insert({ std::move(key), std::move(entry) }).first.
 
Also inserted.first.second->iterator I would think
 
@LucDanton No, inserted.first is an iterator.
 
Well I can't remember how those work.
 
It's a mess.
 
Ah, operator->() to an std::pair*
 
11:38 AM
True multiple return values FTW.
 
So then inserted.first->second.iterator.
 
Oh god, it never ends!
 
To be honest I just came up with the name iterator on the spur!
 
Iterators all the way down.
 
It might not be the most appropriate here, as our confusion shows.
 
11:40 AM
Well, it's faster to write get<2>(* get<1>(inserted) ).
 
Haha, but it's 0-based. Joke's on you!
 
oof, VC team is taking a beating over their C++11 support in VC11
 
yeah, it's too late for me
 
@jalf A well deserved one, IMO.
Wait, iterators are default constructible?
 
11:44 AM
Yesh.
 
yes
 
Ah, forward iterators are.
 
> 24.2.1/5: Results of most expressions are undefined for singular values; the only exceptions are destroying an iterator that holds a singular value, the assignment of a non-singular value to an iterator that holds a singular value, and, for iterators that satisfy the DefaultConstructible requirements, using a value-initialized iterator as the source of a copy or move operation.
Just scanning the text, there's a mention that some aren't
 
Oh, nasty.
> (...) using a value-initialized iterator as the source of a copy or move operation.
 
Not really so bad… if you want to validate it, then provide a default constructor.
 
11:47 AM
Nasty? It's allowed, isn't it?
 
Otherwise, uninitialized pointers are fine to copy.
 
'the only exceptions are...'
 
Oh, right, that lists exceptions.
 
Let me check what happens if I remove the default constructor of my input iterator.
Mmmh, apparently I need one for a range-for?
Ah nevermind, error on my end (literally).,
 
@RMartinhoFernandes definitely. But I also feel kind of bad about it, because from everything I know, they're working their asses off. But when they apparently have one compiler guy, and one STL guy, is it any wonder they're falling behind? The number of supported feature is ridiculous, but I'm not sure it's fair to blame the VC++ grunts
then again, they're the ones sticking their heads out and communicating with users. Kind of hard to see who else this feedback should go to
 
11:51 AM
Well looks like the Boost concept for InputIterator doesn't complain if I make the default constructor private!
 
@jalf Why is the team so small? That's definitely a "management smell."
 
@jalf It's a two people team?
@LucDanton InputIterators don't require it. Only ForwardIterators.
 
@RMartinhoFernandes no, there are others, but STL keeps referring to himself as "the only person working on the STL"
 
Why does that paragraph refer to value-intialization for constructors? it would seem default-initialization is more relevant.
 
@RMartinhoFernandes I'm probably keeping it in though. After all std::istream_iterator also is default constructible.
 
11:54 AM
Em, this is something baffling... I have a function in the base class that does something..but when I call that function from a derived object..the data of the variable int Base::x contains garbage..shouldn't it have used the x of derived class
 
@Potatoswatter int*?
 
and they've referred to Jonathan Caves (I think that's his name?) as "the guy working on the compiler" before
 
And I didn't override it
 
I don't know how big the team is, but it certainly sounds understaffed
 
I didn't knew/noticed that. If that's the case, I can't really blame them.
 
11:56 AM
@LucDanton Right… a declaration such as int *iter; is default construction. Although copying default-constructed (uninitialized) pointers is OK, that paragraph is asking for int_ptr iter = int_ptr(); for an appropriate typedef.
 
@RMartinhoFernandes well, I'm just basing it on a few remembered remarks from them
 
@Potatoswatter Well int* p = alias<int*>(); is UB so they can't make the exception work otherwise.
 
Although STL does say he's the only guy working on their STL implementation in the current comments thread
 
What's alias?
 
Gah
Let me rewrite that it's wrong (using value init here).
int* p; int* q = p; is UB and using default init.
So you need value init.
 
11:58 AM
Really?
 
IIRC the only thing you can do with an unitialized fundamental type or whatever the nomenclature is is to assign to it.
No copying.
And yeah, not a lot of implementations go boom when it still happens.
 

« first day (333 days earlier)      last day (4614 days later) »