Conversation started Oct 12, 2012 at 21:23.
Oct 12, 2012 21:23
for_each(replacer.begin(),
         replacer.end(),
         bind(protect(bind(bind(&ReplacerValue_t::second,_2),
                           _1,
                           bind(&ReplacerValue_t::first,_2))),
              boost::ref(hol), _1));
protect is kinda bad.
I like my answer better. But ^ that intrigues me
TRWTF is alignment style.
@CatPlusPlus What's wrong with that? It'd be what I'd use too
@R.MartinhoFernandes For fuck's sake?
Oct 12, 2012 21:24
It's LISPy and bad.
Fugly like hell.
@sehe Yeah, that thing is just unreadable.
@R.MartinhoFernandes I have a hunch that it could be soooooo much simpler even with Phoenix. You know, apart from the obvious C++03 approach in my own answer
some_func(
    arg1,
    arg2,
    arg3
)
I can decipher the protected expression to be arg2.second(arg1, arg2.first). That's not usual.
@sehe That piece of code makes me cry.
Oct 12, 2012 21:25
@R.MartinhoFernandes Kinda of an achievement. FWIW, I can't compile it, but it's probably something simple I missed. Technically only 45 lines of compiler messages
Meh anything with less than four digits doesn't scare me anymore.
Outer bind pass a ref to hol and (outer) arg1 to the protected expression such that the result is arg1.second(hol, arg1.first). Am I right?
@R.MartinhoFernandes Well, try it maybe? I'm also not easily intimidated (Spirit, remember?) but I didn't see a clue in the compiler messaage.
@LucDanton No clue, I haven't used protect ever before. And it looks like I will keep it that way, if this example is indicative at all
@LucDanton Oh god you're trying.
Looking at the actual question and answer, I think I got it right. So much for 'trying'!
Let's try some fun Phoenix features.
Oct 12, 2012 21:31
I'm surprised there isn't a way to list open windows in C++ without using a callback
@LucDanton Ah yeah. I was going to as well. I bet you'll be quicker to it
@sehe: what does that even mean
Replace C++ with C everywhere.
Do any of you know of any good Pacman ANSI art?
When I tell Google Maps I wanna go to Texas from the Netherlands, it tells me to travel all the way through Russia. That makes no sense.
Oct 12, 2012 21:34
@Kian "good ... ANSI art" is an oxymoron.
I hope no one decontextifies that message.
@Borgleader s/C++/C/; and there's your reason: win SDK didn't want to impose any data structures on any client programs. To me that might be one of the very few design choices WINAPI got right
@R.MartinhoFernandes Fixed. Ah. Your message :)
I just want something that looks like Pacman chasing a ghost and nomming pellets
There are programs that generate ASCII art from images.
@Kian Looks like you have got some drawing typing to do. Really, Ascii art is not difficult. Just tedious
Oct 12, 2012 21:36
Hmm I see. Would have been nice to have the synchronous option though.
AFAIK, it's synchronous.
@Borgleader Wait, they are synchronous. They just use a callback. An output iterator is no different, really
Err by synchronous I meant, without using a callback.
@Borgleader I take it you hate std::copy, std::transform etc. too?
Oct 12, 2012 21:38
@daknøk it doesn't seem to know how to cross the Atlantic
@sehe: there are callbacks in std::copy?
@MooingDuck by plane??!
@Borgleader Yes, *out++ calls two user-supplied functions.
@Borgleader Never used std::ostream_iterator<T>?
I remember some day Google Maps told you to use a kayak if you needed to cross the Atlantic.
Oct 12, 2012 21:39
352. Sail across the Pacific Ocean 6,243 km
364. Sail across the Pacific Ocean 4,436 km
@daknøk google maps doesn't do planes
I see your point, I just didn't consider callbacks the same as "here's a function, apply it to all these elements" (in the case of for_each)
@MooingDuck ah sucks.
By the way; I gave a speech to a group of computer science students today at a college
@daknøk Actually, that's a good thing. It certainly should be doing spherical geometry, not plane.
I was very surprised that none of them even knew what a pointer was.
What are they teaching in schools these days anyways?
Oct 12, 2012 21:42
@IDWMaster java
@KillianDS Why?
@IDWMaster iPads
@sehe iPaid for the I notation from MS-COM. (Apple)
:)
@IDWMaster if they're first years just learning maybe...
Oct 12, 2012 21:44
@MooingDuck What about juniors in an "advanced data structures" class?
@IDWMaster Burn the place down
College juniors?
@Pubby Yes
@IDWMaster realistically: it was most likely a communication error of some sort
@IDWMaster I have no clue, I just noticed that almost every school here java is the default language, with some exceptional courses in C/C++ or scripting languages.
Oct 12, 2012 21:46
because even Java guys know pointers (if by a different name)
@MooingDuck "references" was how they were taught
Not really correct naming though
Even though Java spec calls them pointers.
But also, many students are lazy, so it could very well be they just didn't want to react if you asked "does anybody know what a pointer is?"
Java has NullPointerException.
@IDWMaster it's a pointer by a different name
Oct 12, 2012 21:47
@KillianDS I even gave the students a sheet which explained what pointers are, introduced them to C++, and went over inheritance, polymorphism, slicing, etc.
Prior to my talk
@KillianDS At least here there's some variety, even if it's all static typed languages.
I wonder if any of the students even read my handout
> error: no type named 'map_type' in [ overly long type ]
nvm im an idiot
overly long int x = 100000000000000000000000000000000000000000;
Oct 12, 2012 21:48
@IDWMaster Did you have "This will be on the final test" in large, bold type at the top of the page? If not, they undoubtedly ignored it.
@R.MartinhoFernandes really really long long x = 99999999999999999999999999999999999999999999999999999999999999999999999999999999‌​999999999999999999999999999999999999999999999999999999999999999999999999999999999‌​99999;
@Borgleader AFAIK, WinAPI callbacks are well-designed, i.e., they take a void* for user data.
loooooooooooooooooooooooooooooong int = 1000000000000000000000000000000
@LucDanton typename?
@JerryCoffin No, the professor in that class apparently never has exams or tests.
Oct 12, 2012 21:48
@R.MartinhoFernandes: oh is that what the LPARAM thing is for?
Instead they're graded based on labs
@Borgleader I don't know details, but I do know they have that. Lemme check the docs to confirm.
@LucDanton map_type? reminds me of key_type/mapped_type in std::map (in addition to value_type)
@MooingDuck lol. The error points into Boost code.
@IDWMaster In that case, just showing up is probably more than you could have expected.
Oct 12, 2012 21:49
@sehe Ya, tried to use let + local variables -- a map makes sense.
@JerryCoffin What is with today's US education system anyways? Even at private schools.... wow!
@Borgleader Yes, that's exactly it.
@IDWMaster It's simple efficiency -- they're smart enough to ignore anything that doesn't directly affect their grades.
Ah cool tyvm :)
(What kind of type is an LPARAM?)
sbi
sbi
Oct 12, 2012 21:51
It's rare nowadays, but once in a while it still happens: I just turned on the radio in the bathroom for brushing my teeth and happened to catch the last 70secs of a song — and those few secs swept me off my feet. I only caught that they're a Scottish band, and that their album is a somehow intelligently misspelled "Something For The Weekend", so it took some googling, but I found this.
I have no idea if the rest is any good, but I so want this now.
@R.MartinhoFernandes void* usually
@MooingDuck For the record the usual error message in that case is 'type/value mismatch'. It's very telling.
Well, after so many times it is.
@IDWMaster It's not a void *. From MSDN typedef LONG_PTR LPARAM;
#if defined(_WIN64)
 typedef __int64 LONG_PTR;
#else
 typedef long LONG_PTR;
#endif
So LPARAM is a type that is large enough to contain a pointer to a long
anyone know under what conditions windows will appear to "randomly" choose a program to open a file with? Various .wav files on my computer open with audacity, WMP, or another program, seemingly randomly chosen.
Oct 12, 2012 21:57
hi, im juan orozco from mexico, im doing an interpreter for class (something like windows cmd) but im having some troubles to do a copy command
@Prætorian not so. LONG_PTR is a long (i.e., some sort of int) large enough to hold a pointer, not a pointer to a long.
@MooingDuck Even if you shift+right-click, open with and set default?
@Prætorian I just did that now
but I was wondering why it wasn't consistent.
@R.MartinhoFernandes: It worked perfectly, ty again.
@JerryCoffin Isn't that what I just said?
Or meant, at least :)
Oct 12, 2012 21:58
@Prætorian well it's not what you said
@Prætorian Maybe what you meant.
im using the code from this post stackoverflow.com/questions/10195343/… especifically the COPY-ALGORITHM-C++-WAY
@LucDanton If you ever come with something remotely palatable using Phoenix, I'll upvote it unconditionally. I'm giving up right now, I don't think it's worth it (beyond illustrating the limits of Phoenix vs. the merits of c++11 lambdas)
Oh, large enough to hold a pointer, not necessarily pointer to long
its great to copy text, but if the file is binary (lets say an exe) it dont copy the full file just the first 1k, any ideas how i can solve this?
im using vc++ 2008
Oct 12, 2012 22:00
@JuanAntonioOrozco If you're going to go from that post, use the "KISS-C++-Streambuffer-WAY".
but it works whit text and binary data as well?
@JuanAntonioOrozco yes
@JerryCoffin But if that's the case, why have UINT_PTR, ULONG_PTR etc?
And their signed counterparts
@JuanAntonioOrozco It's up to you to specify std::ios::binary when you open the files, but yes. Since you're just copying anyway, you might as well always use that though.
Oct 12, 2012 22:03
im using std::ios::out | std::ios::binary | std::ios::trunc for output and std::ios::in || std::ios::binary for input
@JerryCoffin I don't know whether it matters since you're using rdbuf() directly?
oh im thinking i found the error already, just letme check
@sbi hmm.... I'll have to give that a proper listen when the GF is not trying to watch TV
@sehe let(_s = first(arg1), _f = second(arg1)) [ bind(_f, ref(hol), _s) ]
The trick was to use bind instead of operator() to 'call' _f apparently.
@LucDanton I did that. My problem was I couldn't find phx::first/second? What header are they in?
Oct 12, 2012 22:07
Uh I hand-rolled them. TTBOMK they're not provided.
Was quick to prototype in C++11 mode.
Want a C++03 implementation?
any way, time to hit the sack
see ya'll
@LucDanton I'm also in C++11. I thought in my naivety that this would work:
    auto first  = phx::bind(&Replacer::value_type::first,  arg1);
    auto second = phx::bind(&Replacer::value_type::second, arg1);

    std::for_each(replacer.begin(), replacer.end(),
            phx::bind(first(arg1), phx::ref(hol), second(arg1)));
It's definitively not unreasonable to think so.
I tried it with phx::lambda[] for first/second too. I bet you need BOOST_PHOENIX_ADAPT_CALLABLE but it didn't appear to work. Again, I'd be missing an header, maybe
Except you hit the protect problem I guess: too many arg1s.
Oct 12, 2012 22:10
O wait. There phoenix::function<> these days, right
Yeah, that's what I used.
@sehe Probably doesn't matter, but using std::ios::binary certainly won't hurt anyway.
@LucDanton yeah. I just thought to try
@JerryCoffin True. Code with explicit intent :)
well i tried both changing std::ios::in || std::ios::binary for std::ios::in | std::ios::binary and COPY-ALGORITHM-C++-WAY works with text files but no whit binaries ones (i jusk getting the first 1k) and KISS-C++-Streambuffer-WAY giveme just tre characters (no one from the original file), what else i can try?
I have constexpr auto first = get<0> {}; as operators somewhere just for the convenience!
Oct 12, 2012 22:11
@Prætorian To be honest, I think largely that's largely a mistake on their part. Having signed and unsigned makes sense, but INT_PTR vs. LONG_PTR really doesn't (and I'm pretty sure in all cases those are really the same type anyway).
@LucDanton Oh. My. How did I miss the pair-is-also-just-a-tuplelike-sequence thing
Ell
Ell
She's a fucking whore
Fu k hwr
Her evwtrrbovy
@Ell Pardon us?
Also std::array!
Ell
Ell
Sues a common wgir
whorw
Whilee
whore
Oct 12, 2012 22:13
@Ell you've been drinking
Ell's finally gone bananas.
Ell
Ell
ucje here
I suppose providing first and second out of line defeats the purpose of the exercise though.
Oct 12, 2012 22:13
To the flagger: No need. Just ignore Ell for today
As a drunkard, I am very good at identifying drunk people.
@EtiennedeMartel Sadly those epic skills weren't really required in this situation
Ell
Ell
I'm Larry :( I have drabbk.
@sehe One day, they shall come in handy. Mark my words.
Ell
Ell
I qwhllc lea e you in pea e nwo
Oct 12, 2012 22:14
"I will leave you in peace now"
2
Maybe I'll validate the flags. This is inappropriate
(Drunk text translation, ha)
@EtiennedeMartel Just in time. I was going to honour the flags
lol
I love how many answerers did not notice that.
@sbi Is that supposed to play something? It doesn't seem to work here.
Oct 12, 2012 22:17
I wonder if clang considers whitespace and mentions stuff like that. it should
@R.MartinhoFernandes I was pinging him for this - stackoverflow.com/questions/12193170/…
@R.MartinhoFernandes Too many Python fans.
@LuchianGrigore Yeah, I know.
We didn't see eye-to-eye on that one - this is proof that it does happen.
@Ell please hold your thoughts in check @ell. because you're lying to yourself (most likely), and self-deception is ungood.
Oct 12, 2012 22:17
@sehe Try bind(first, ref(hol), second). Although I think you messed up your reminiscing, I recall the functor being in the second position.
@R.MartinhoFernandes wat. How could you have known that?
A second
@LuchianGrigore Well, maybe not that particular comment, but I know his particular views on that matter.
ah. 'aite
or is it aite'
ok... 'aite' just to be sure....
So when you plinked him, I figured out immediately why it was.
Oct 12, 2012 22:19
@LucDanton Erm. What reminiscing? I'm lost
@LuchianGrigore At that point, you might as well shorten it a bit more to just '' :-)
I think it's a'ite.
@LucDanton oh right. That! Functor is the 'second' in the pair
You put the apostrophe where you skip stuff.
Interesting. Now the error message suggests that the nested bind expression is too protected.
Oct 12, 2012 22:22
@R.MartinhoFernandes so... a'i't...
@LucDanton Oh ahah. This worked after all:
    auto first  = phx::bind(&Replacer::value_type::first,  arg1);
    auto second = phx::bind(&Replacer::value_type::second, arg1);

    std::for_each(replacer.begin(), replacer.end(),
            phx::bind(second, phx::ref(hol), first));
Can't get it to work on my end.
@LucDanton We have a saying here that goes something like "all the protection is not enough".
@R.MartinhoFernandes But I want less of it!
@sehe Now that doesn't look bad at all.
Oct 12, 2012 22:24
Hm.
Fuck... accidentally deleted the wrong partition.
Now if I can get an elegant C++03 definition for first/second. What header has get<>?... Damn. I'm slow today
@sehe Can't you just #include the whole Phoenix shebang?
@R.MartinhoFernandes I used the main header, phx::get not defined
Ah.
#include <boost/phoenix_shebang.hpp>
Oct 12, 2012 22:26
@sehe None of them! From what I can tell. get is my own thing as well.
@LucDanton I think I need at<> from phoenix/fusion.hpp
Ya that's worth a try.
Note that you would need first(arg1) this time! Getting the hang of nested bind expressions yet?
hmmmm... bounty on 4-year-old Q -> stackoverflow.com/questions/331536/…
@LucDanton Nope. Not endeavoring to, anyways. I'll write a functor if it gets this far :)
@LuchianGrigore It's urgent!
LOL Urgent... silly bear
Oct 12, 2012 22:30
I add a comment with "@abeschneider" but this part gets removed from the comment, what am I doing wrong?
Aw. Gist of it is that if you define first to be bind(&value_type::first, arg1), then arg1 is already involved. A placeholder always denotes the final parameter to the final, outermost bind expression. Never a 'local' parameter to the current bind expression.
@MichaWiedenmann Your replying to a post by abeschneider and no one else is participating in the comment thread.
@MichaWiedenmann you need to move the implementation to the header.
@LucDanton Only for boost::bind, IIRC. std::bind doesn't do this
This is what makes things like bind(foo, arg1) == bind(bar, arg1) work, too. Conceptual equivalent to bind(operators::equal_to {}, first_bind_expression, second_bind_expression).
@sehe No, same rules. All the binds are really, really and I mean really similar.
Oct 12, 2012 22:32
@LucDanton Hmmm. I remember running into this difference once. Let me think.
Anyways, that settles it. This works: C++03
std::for_each(replacer.begin(), replacer.end(),
        phx::bind(
            phx::bind(&Replacer::value_type::second, arg1),
            phx::ref(hol),
            phx::bind(&Replacer::value_type::first, arg1)));
I've tried making the rules different to e.g. allow for ref(f)(42) instead of the silly-looking ref(f)(arg1)(42), but it gets weird really quickly. Also I don't remember what are my current rules lol.
it is easier to define new languages in lisp
:)
Yeah, now I get suspicious when I think 'hey, if I tweak rule X then I can get Y!' for that EDSL.
There's a way to solve that: write them down.
Oct 12, 2012 22:36
Oh btw how are the elections in the state going? Any debates left? Who's winning?
@R.MartinhoFernandes I have.
Plus the unit tests. I'm checking right now.
Apparently I've kept the feature. I don't know what that 'costs' me, i.e. I expect some corner cases to fail that would be accepted by Phoenix.
Oh, perhaps something as simple as ref(f)() is different I think.
evening fellas
Ohai
@n.m. I also fought for a good hour and came up with a Phoenix bind incantation that looks slightly less daunting :) — sehe 5 secs ago
@TonyTheLion Hello.
Oct 12, 2012 22:42
^ @LucDanton fruit of labour. Lemme credit your help :) Editing
 
Conversation ended Oct 12, 2012 at 22:42.