« first day (89 days earlier)      last day (4851 days later) » 

12:00 AM
maybe that syntax got ditched
 
throw up();
 
no thanks
 
Kos
[&] is like [] but indicates that all local vars used in lambda are automagically part of the closure, iirc
or something like this
 
yes
I know what it means
 
Kos
maybe there was also [*]
 
12:01 AM
Is it just me that hated the C++0x lambda syntax? *runs*
 
Kos
gotta check
 
I have a conformant compiler
yes
lambda syntax is excellent at what it was designed for - nice and concise
 
Kos
@jweyrich, could it be that thou desirest a new keyword?
 
[] is an absurdly small amount of overhead for a function definition
 
Kos
DeadMG, haskell still does better, tho :D
\a b -> a+b or something
 
12:02 AM
there's nothing haskell does better
at all, and especially not in the realm of syntax
 
sbi
@Kos Borland C++ had once a bug where it would allow almost arbitrary special characters to close a template argument list. This was known as the "emoticon bug" back then, because it allowed funny things to compile that looked like emoticons.
 
Kos
oh come on
 
Haskell's syntax looks like a guy vomited on his keyboard and the syntax became all the keys that got stuck
 
@DeadMG that's my problem with it. C++ wasn't supposed to look like Brainfuck.
 
Kos
@DeadMG, don't say that... haskell conquers all the hearts of young romantic programmers
 
12:03 AM
C++ doesn't look like Brainfuck
the reason that lambda syntax works is because it's isolated
[](), done
Haskell's syntax, you have to do that for every function and all the rest of it
 
Kos
Foo(int a, int b):a(a),b(b){} i love it in c++
 
besides, an empty-capture lambda? who would make such a thing?
my lambdas usually look like
 
[&, this](decltype(*container.begin() arg) {
}
 
sbi
vector< vector< vector< int }:) x;
 
Kos
12:04 AM
@sbi, nice :)
 
sbi
@Kos Well, unless you wanted to do template stuff with the compiler...
 
@sbi I'm planning to use [di|tri]graphs on my next job. Hopefully nobody will ever touch my codez.
 
Kos
@jweyrich, just make sure to have a fake account on version control for those changes - or I'm afraid they might hunt you down even years after you quit.
 
I wonder if
in C++0x
 
@Kos lol. good advice
 
12:06 AM
you could template metaprogram a parser
that would actually parse and compile the code
at compile-time
 
Kos
of course
turing-complete
 
doesn't make it feasibly doable
 
Kos
oh, you've just added "feasibly".
nvm then.
but with D templates there's already a compile-time raytracer.
 
yeah
 
Kos
quite a nice one, even though not the fastest
 
12:08 AM
but so what?
 
Is it considered yucky to embed lambdas within one another?
 
no
 
Kos
rather 'creepy'.
 
no, no
 
Hey, I can dig creepy. :)
 
12:09 AM
nested lambdas are a fact
 
Kos
but they indeed do hit the WTF/min counter by quite some.
 
if you have to have nested for loops that are std::for_each, you need nested lambdas
that's just how it works
 
Kos
i'll just boost::foreach, thanks.
 
oh man
you can return lambdas from lambdas
I'd forgotten about that
 
Kos
... can you?
oh.
 
12:10 AM
sure
 
[](){ [](){return [](){}}()};
 
though it doesn't have to look that ugly.
 
defines a lambda which has a nested lambda that returns a lambda that gets called
it could only be more awesome if I could remember how to pass them as arguments
 
I just learned that libtcmalloc and valgrind massif do not play nicely with one another.
 
DeadMG, I've been using std::function with the appropriate types.
 
12:11 AM
yeah
 
or auto
 
but that would look ugly
I could take decltype([](){})
 
auto lambda = [](){ ... };
I've used that a lot
 
[](){ [](decltype([](){}) arg)([](){});};
 
You like ugly code don't you?
No wonder you like DirectX
:P
 
12:12 AM
@Runcible tcmalloc doesn't play well with anything in my frustrated experience.
 
lol
 
All they need to do now
is allow lambdas to be passed as template arguments
 
@jweyrich: I kept trying to figure out why massif taking zero snapshots of my running program. Recompile without tcmalloc -- problem goes away.
 
(without a wrapper, obv)
 
well
lambdas ARE a type
you could do
 
12:14 AM
yes, they are.
 
template<typename T> void func(T t) {
T()();
}
right
it's srsly time for me to go to bed
 
Sleep well, man.
 
I won't
 
Kos
so is a lambda a type or a value?
clarify that for me.
 
well
it's a value.
typedef std::function<void(int)> SomeType; // here's a type
SomeType a = [](int a) { std::cout << a; };
and a value
 
Kos
12:19 AM
I'm not really familiar with functional programming facilities
std::function is a wrapper, right?
 
@Runcible the problem with that is both massif and tcmalloc are required to replace the built-in allocation mechanism, and you can't have 2 of them simultaneously.
 
It's not exactly a wrapper, to my knowledge. I haven't delved much in to the STL.
 
Kos
can I say "what is the type of [](int a) {return a+5}" ?
 
But the fact that the compiler allows one to assign a lambda to it
I've never tried to compare them, to be honest.
 
Kos
hm
 
12:21 AM
well
 
Kos
is that 'assign' or 'initialize with'?
 
actually
This was a question I asked on SO not so long ago.
when I wanted to put these types in a vector.
but the compiler threw up because it couldn't compare them
 
Kos
[lurks]
 
so I had to put them inside a shared_ptr.
 
Kos
got it
4
Q: Vector of std::function<>

Moo-JuiceHi guys, Say want to store the following: typedef std::function<void(int)> MyFunctionDecl; ..in a collection: typedef std::vector<MyFunctionDecl> FunctionVector; FunctionVector v; This is possible, but if I want to find something using std::find: FunctionVector::const_iterator...

 
12:22 AM
that's it :)
 
Kos
this all seems so crazy to me
c/c++ functions were never first class values
and i've now got to reconfigure my whole thinking
 
Well
It's not that you need to do that, but it;s very powerful. Rather than have little member functions everywhere as callbacks, if the situation is appropriate, you can save yourself some space.
For example
(how do I format code here?)
(<pre>?)
 
Kos
does markdown work? bold
code { }
more code [ 1 2 3]
works.
 
{ void Socket::connect(const String& _host, Port _port)
{
// Anon function for resolution of the host-name and asynchronous calling of the above
auto anonResolve = [this](const boost::system::error_code& _errorCode,
boost::asio::ip::tcp::resolver_iterator _epIt)
{
// raise event
onResolve.raise(SocketResolveEventArgs(*this, !_errorCode ? (*_epIt).host_name() : String(""), _errorCode));

// perform connect, calling back to anonymous function
if(!_errorCode)
this->connect(_epIt);
};

// Resolve the host calling back to anonymous function
 
Kos
but doesn't prettify
 
12:26 AM
ugh, didn't work
 
Kos
4 spaces indent. have fun doing it manually :)
 
anyway, if you put that in notepad or something
I use a lambda to track the boost:asio resolving host names
rather than having a function to do it.
 
@MooJuice nice example.
 
ty :)
 
Technically, a lambda is a functor. Nothing special except the fact it can be defined in arbitrary locations of your code. Someone correct me if I'm wrong.
 
Kos
12:32 AM
that would likely be true but that itself cannot account for closures
you can't extend a local var's scope via functors in c++03 as i understand
...and C++0x's lambdas/closures do it, right?
(/me confused)
 
Well
It's all about where you define it.
If you're in a member function, you can bring in "this" and local variables
at the end of the day, they all arrive correctly when called.
 
Kos
think of when you have a global function which has a local variable and returns a lambda which closes that local variable.
 
Providing, of course, those objects have not gone out of scope, or have been deleted.
 
Kos
so to have a similar solution in c++03, that var's scope would be global actually, right?
or... no.
not global, field of the functor
 
Then you have the same issues as if you'd referenced that local variable and returned it by reference, for example.
Whatever you pass in to the lambda, must be valid when it is called.
 
Kos
12:35 AM
No, no, no. That would kill the whole idea of closures
i mean, C++ closures would be fake closures if they can't extend the lifetime of a local var
 
I'm not saying that
 
Kos
that's what people do all the time with closures in javascript or python
 
I am saying that if I pass 'x' to a lambda and pass that to something, then 'x' needs to be valid when it is called.
Just as if you'd passed 'x' to a regular function pointer
You might chastise me for this
but I see lambdas as merely inline-functors :)
but keep in mind the execution of them
 
lol @sbi
don't worry xD
@DeadMG is not valid...
 
Kos
can i have something like this with C++0x lambdas?
 
12:40 AM
yes
 
Kos
treat bar() like a lambda, even though i defined it as a nested function... all same in python.
look that 2 copies of 'a' are created
and both instances of bar() in that code, bound to a and b vars, can be copied and will still refer to same 2 copies of closure variable a
...I think
 
Well, let me try it
hang on.
 
Kos
..no, disregard that very last part
but the basic question still holds
 
LOL
In an attempt to replicate it
I have gone in to serious territory.
(how do I format code again?)
 
@MooJuice if it's multiline, then click "fixed-font", otherwise, use the common backtick.
 
12:50 AM
The only issue I'm having with that example
is 'return bar'
@jweyrich, where is the fixed-font button? <-- chat noob
 
@MooJuice it only appears when you have a multiline text on the typing box.
 
#include <iostream>
#include <algorithm>
#include <functional>

int _tmain(int argc, _TCHAR* argv[])
{
	auto foo = []() -> std::function<void()>
	{
		int a(10);
		auto bar = [&a]()
		{
			std::cout << a;
			a++;
		};
		return bar;
	};

	foo()();
	foo()();

	return 0;
}
got it.
this doesn't actually work like your example.
I'm getting close, though
I don't think a lives long enough to be useful.
However!
making a static
and not passing it in to bar
makes the output 10 and 11
 
@MooJuice If I'm not wrong, there's no way to get the same behaviour without an extra object because that code translates to a.a and b.a. Each one has it's own copy of a.
 
Kos
The whole point is to make each call of foo() yield a "different bar()", i.e. with its own closure
 
Oh, agreed.
I'm just trying to get that for you :)
@jweyrich, I see what you mean
 
12:58 AM
Weird stuff going on on stackoverflow.com/questions/4675145/… today.
Noah Roberts posted a bunch of incorrect answers, downvoting correct ones without leaving comment. Then, when faced with a standard quote, he -- after a delay, and again silently -- removed downvotes. He then edited his original fallacious answer to contain nothing but a single line of interesting but unrelated C++ code, again without comment or explanation. Weirdo.
The problem with stackoverflow is evidently that you can amass reputation regardless of whether or not you're a moron. :)
 
@MooJuice you might get the same with struct { int a; void operator() { your foo here } }, I think.
 
Yeah, I think you're right.
I guess this answers Kos's question
If it was a type, we could instantiate it twice.
but we do little else but store and call it
@TomalakGeretkal, it's a shame many people cannot just admit they are wrong.
 
@MooJuice It's a shame that someone with 12.4k rep on StackOverflow can even be so wrong in the first place, on such a fundamental topic. :)
 
There's some funny types here. In general, I think it is an awesome community. But then you get the odd-sock that downvotes correct answers, upvotes incorrect ones... and you never know why. It goes with the territory.
I generally keep my stupid answers to remind myself why I misinterpreted something
but
I have been known to delete answers where I completely misread the question :)
(my own answers, that is)
 
Yea, me too, if I noticed within a couple of minutes.
 
1:05 AM
@TomalakGeretkal the real shame is when they think full of reason. Dogmatism has never caused any good.
Darn, I keep editing my messages. My english is BAD today.
 
Kos
@TomalakGeretkal @TomalakGeretkal, actually Noah wasn't really wrong on his original answer before the edit.
Actually, that was a damn correct answer.
He just misunderstood the question... "why does this code compile" isn't really a well-stated one
He ignored the "1234;" part as obvious (for him) and instead tackled the problem why #include <stdio.h> instead of <cstdio> works... which was the real mistake in that code, if we're talking about c++.
(Or not the real mistake, if stdio.h is really also allowed by the standard. :))
 
@Kos, yeah, this is what happens when questions are phrased badly: stackoverflow.com/questions/4642030/display-xml-using-php/… :)
 
Kos
:D
 
Anyway, time for my bed. Good night all :)
 
Damnit the Objective-C room is slow.
We're way past them, here we're already learning how to stfu.
speaking of which.
Anyone knows how to play a sound in Cococa with Objective-C?
Something simple for starters. A system sound maybe ...
 
1:15 AM
@wilhelmtell does NSBeep() count? :P
@wilhelmtell if you want something more complex, check the samples provided in GS_MusicAudio or CoreAudio (you find them in the Mac OS X reference library).
 
@Kos How was he not wrong? He was arguing that <stdio.h> is non-standard, which is false.
@Kos: That plus it wasn't the question that was asked; he answered that question incorrectly in several comments throughout the thread.
 
Kos
Uncool
 
Indeed.
I've been told elsewhere that he's drunk tonight; I certainly hope so!
 
@jweyrich figured it out. way simpler than I expected!
NSSound *sound = [NSSound soundNamed:@"Bottle"];
[sound play];
Sorry for contaminating the board with non-C++ spam.
 
@wilhelmtell yup. that link I mentioned has more on this.
 
1:28 AM
lol, "Hurry, hurry, go tell your buddies in the chat chan!"
/me waves Hi Mom!
 
@TomalakGeretkal IRC user detected.
 
@jweyrich Valid observation observed.
 
Kos
@TomalakGeretkal Valid observation observation observed.
 
@TomalakGeretkal if it's not UB, then I'm fine with it.
 
@jweyrich If what's not UB?
 
1:37 AM
@TomalakGeretkal oh, nevermind.
 
@jweyrich: :)
And, no, I can't be assed to keep clicking on the little reply button.
 
Kos
I wonder what would happen if we continued to recurse into that "observation of observation" line.
I believe we'd cause a StackOverflow...
oh wait.
Check the page title. It's already here.
 
@Kos Good job on the joke there
 
@Kos what do your work with?
 
Kos
@TomalakGeretkal Thank you, I appreciate that- I used my best abilities on that pun over there.
@jweyrich nothing, at the moment
 
1:48 AM
@Kos :D
Someone's going around downvoting all my answers from this evening.
With no comments.
Noah Roberts nerdrage?
 
I can recommend [comp.lang.c++] instead. No downvoting there. No upvoting either. :-) The only reward is to learn something.
 
Kos
no badges = no fun
It's fun how trolling works on SO
 
Kos
people want to troll in order to earn badge X -> people sit and write lots of good answers.
 
@AlfP. freenode##c++ works pretty well for me.
 
1:54 AM
Well, there are some kinds of virtual badges. You can get promoted to a "regular" by the community. ;-)
 
Kos
Always reminds me of xkcd.com/810 .
 
IRC is so new-fangled. No no no.
But, as some of you may or may not know, the old relay net of BBS-es is still up and running! And can be accessed via Telnet! :D
 
Really?!
 
@Kos haha. great strip.
 
1:58 AM
it is
ok, the moronity is getting a bit much now. I'm off to bed. night kids
 
Hm, it's been years since I looked at that stuff. But I seem to recall in the old days there was even a kind of ham radio packet switched network. Perhaps it's still up and running in Arizona or Australia or something.
 
2:34 AM
:-) I successfully logged on to one of the BBS'es using Windows HyperTerminal. Nobody there, not even the sysop. But I'm guessing it's different in Russia.
 
2:46 AM
In Soviet Russia, BBS logs into you!
 
 
1 hour later…
3:55 AM
He he :-)
 
4:18 AM
lol
@TomalakGeretkal someone downvoted some of my questions too, incidentally only a few hours after noah discovered the talk about him here!
or was it minutes. i dunno but it really felt it was him lol
 
4:59 AM
Perhaps it was punishment for our attempted conspiracy :-D
 
5:55 AM
Ugh. I wish it was possible to edit comments after five minutes. I'm constantly finding comments I wrote months ago that are grammatically incorrect or have a typo in them. :-|
Since we most frequently point beginners to the Book List, perhaps we should move the All Level Reference texts below the Introductory books so that Introductory Books appears first?
 
 
2 hours later…
7:36 AM
ah, the quiet time
 
Shhhhhhhhhhhhhhhh
 
Is it just me, or is everyone copying the example from my answer? ;-)
 
Nah. Mine is unique (unlike the nested typedefs!)
Though, I have to fix it, because it's also wrong.
And by "wrong" I mean its correctness was deferred.
 
@JamesMcNellis <strike>You mean the lookup rules won't find it?</strike> Oh wait, I see it now.
 
7:51 AM
No, I mean that if you declare int a = 42; and then do a == 42, function templates won't even be considered.
The nontemplate friend should work.
 
/me goes back to check own answer.
I could do with a timer telling me how long before someone else answers so I know how detailed an can be while still getting the top answer. 8 seconds late this time.
 
You could set up a botnet and DDOS stackoverflow.com while you are composing an answer. </not-serious!>
 
I think a big flashing red banner: "Warning: James McNellis is 7 seconds away from clicking 'Post Answer'."
Come to think of it, where is my minority report?
 
I think GMan has one of those. I swear, it drives me nuts the number of times he has posted a better answer three seconds before me.
 
@Nawaz has changed his comment on my post: "I think this explanation is better than James's explanation. Concise and precise. +1". Na-Na! :-D
 
8:08 AM
I think your example is better.
 
@JamesMcNellis: Do you ever write answers that you are sure are good and never get any upvotes?
 
@CharlesBailey Well, all of my answers are good and some of my answers do not have upvotes, so, yes. ;-)
 
@JamesMcNellis Not just me then. And good to find someone else, all of whose answers are good.
 
Ha ha
@CharlesBailey Seriously, though, I post a lot of answers that I think are good or useful that then get very few upvotes (two or less).
 
Oh well, back to coffee and work.
 
8:17 AM
Have fun
 
 
2 hours later…
10:38 AM
5
Q: What's wrong with const?

DeadMGWhat are the known shortfalls of const in C++ and C++0x?

I was the fifth to vote for reopen, but it's still closed...? :(
 
@FredOverflow maybe it was closed in between
 
@JohannesSchaublitb you mean 1 second after i voted to reopen, 4 more people voted to close?
 
why not
would be more funny if vote close/vote open would work like a battle. once it hits 4, it is closed/opened xD
4 / -4 that is x
 
I don't think Jeff Atwood and Joel Spolsky aim for funny features in SO improvement :)
 
I don't think Joel Spolsky knows what funny means
 
10:56 AM
As far as I know, close and reopen votes are now accumulative
i.e. the score could well be 100 to 150.
 
@TomalakGeretkal have a look at the "turtle question" haha
 

« first day (89 days earlier)      last day (4851 days later) »