« first day (377 days earlier)      last day (4562 days later) » 

8:00 PM
what's "not that obfuscating" for experienced people like you and I and what I'd teach to a bunch of newbies are quite different things
 
Newbies using vector? WOAH.
 
@CatPlusPlus vector isn't that hard
 
@codemaker wow a lot of shit just to send "hello world" to the client
 
Xeo
@sbi I upvoted the operator one, because I seem to have forgotten to do that when I first read it :)
 
sbi
@DeadMG Well, in the companies I have been in the last 15 years, 80% of the developers would have WTF'ed about that swapping variant.
 
8:01 PM
@LewsTherin yup. click one of the packets and then click "follow tcp" from the analyze menu. That will show you just the data
 
now you're just massaging my ego :P
 
@codemaker lol it did
 
sbi
@Xeo Ah. Just the question or all of them? But then, as I said, that operator overloading FAQ has been a constant cash cow for me, so I didn't really took those into consideration.
 
Xeo
question + answers
 
@sbi I didn't get the f().swap thing. Can you point me to something that would help me?
 
8:03 PM
@LewsTherin you don't really need to understand how TCP works to use it, but looking at the packets there, you can see what we were saying earlier. The TCP protocol handles all the details of retransmitting stuff and ordering stuff and you just see the data
 
sbi
@vivek I suppose @DeadMG would jump in? He considered it basic knowledge, after all. :)
 
indeed
 
@codemaker I don't see it... that's the thing I can't translate it
 
it's pretty simple
you start that vector has value semantics- when you copy a vector, it copies the contents, which involves a dynamic allocation, which is slow
ergo, we write our code to avoid copying vectors
with me so far?
 
@LewsTherin if you look in the packets you might be able to find some little snippets of your character strings in there, like a "Hel" or something.
 
8:05 PM
@DeadMG :( no
 
sbi
@vivek May I? :)
 
@codemaker the packets are the list of source and destination address right?
 
of course
 
If I click on one it shows me the frame ethernet all that garbage
 
The Professor can fill in this gap
 
sbi
8:06 PM
We start with this:
 
@LewsTherin you dont want to read that
 
sbi
std::vector<std::string> val = f();
 
ok
then
 
sbi
This will put a copy of the std::vector<std::string> into val.
 
@vivek i have to. lab stuff
 
sbi
8:06 PM
Copying, however, is expensive.
 
yes,
@LewsTherin what's your aim ?
 
but we don't actually need to copy the contents
because the result of f() is about to die anyway
 
@LewsTherin eh?
 
so if the contents of the result value of f() just disappeared, nobody would notice or care
 
@LewsTherin yeah, it shows you the mac address, the ip, the port, all of the fields in the packet
 
sbi
8:08 PM
What's especially wasteful about this copying is the fact that the vector we copy from (the return value of f()) is going to be destructed after the assignment. So, actually, it doesn't need its data anymore. We could just steal the data from it.
 
@sbi Ah..
 
@codemaker that's the middle frame, the last frame shows the binary representation of the data in hex
 
@LewsTherin you don't need to worry about any of that stuff to actually get your app working though
 
"swaptimization" is where you just swap the value and the result of f()
avoiding the copy
 
@codemaker so what is it for?
 
sbi
8:09 PM
Enters std::vector<T>::swap(std::vector<T>&). It can swap the innards of two vectors in no time.
 
so how we steal it ?
 
@LewsTherin right, the data is there to
 
technically, this no longer retains value semantics, because we mutated the result of f()
but since f() is about to be destroyed, nobody cares
 
@LewsTherin just to help you visualize what happens when you call read() or write() on your network socket
 
Its clear now
 
8:10 PM
@LewsTherin although since all of that stuff is abstracted away, looking at what actually happens might actually make things worse...
 
sbi
What we do is to take a freshly constructed vector, and swap its content with what f() returns. Now our vector has the data of f()'s result, while that temporary has the empty vector's data.
 
I was actually confused that how f() would have a swap member function, now I noticed that f() = vector object
 
@codemaker lol that doesn't sound like it will help. I have to cook :(
Brb man
 
@LewsTherin don't worry about the details :)
 
sbi
At the end of the full expression, when all the temporaries are trashed, f()'s result dies taking the data of an empty vector with it, while we have the result of f() without having it copied.
 
8:13 PM
@sbi @DeadMG : So now that I understand it, I can use swap instead of copying, no downfall right ?
 
except when you actually need to copy things, of course
 
sbi
@vivek You can steal the data from rvalues, because they are going to die anyway. Move semantics does that built-in. Much better.
 
swapping regular variables is perfectly OK, just be aware of what it is and does
 
I'll leave it to move semantics for now
 
sbi
Anyway, @Dead, I think this demonstrated my point rather well.
I consider anything obfuscating that a newbie with minimal exposure to the language cannot understand right away. C++ is very guilty in that regard anyway, there is no need too worsen that sad state of affairs with premature optimizations. (And unless you know that the compiler fails to optimize this copy operation and that it uses a significant amount of runtime when your app is fed with real-world data, this optimization is premature.)
 
8:16 PM
tis true
 
Have you used std::mem_fun (from functional) ?
 
sbi
Could you guys please consider helping to close this question. IMO it's too vague to be answered here. See my comment.
 
@sbi I'm 2453 rep short for doing that
 
std::function and std::bind (or boost::) are better than std::mem_fun.
 
sbi
@vivek Then keep growing! :)
 
8:24 PM
@CatPlusPlus where is std::function ?
 
functional.
 
@codemaker back
 
@LewsTherin k
 
It's C++11. For C++03 there's boost::function.
 
@codemaker wireshark isn't doing any good. I am sending stuff to my computer's ip 192.168.1.3 ... but it uses both source and destination for the same ip. I know it is right
But I wish it'd differentiate it. If I use 127.0.0.1 both src and dest are the same ugh
 
8:27 PM
@LewsTherin if it is confusing you, give up on wireshark for now and just focus on your code
 
Wireshark is a specialised tool, not something you use to learn how networking works.
Also, that's the nature and the entire point of loopback that source and destination is the same thing.
 
it's useful if you want to see what is happening behind the covers
 
@CatPlusPlus mmn what if I use external addr?
 
any place where I can read about it ?
 
wow wtf it won't let me connect to my external ip
 
@LewsTherin yeah, that depends on how you have your system setup
 
thank you'
 
@LewsTherin i wouldn't worry about it
 
@codemaker it worked before...
 
8:31 PM
@LewsTherin were you on the same network? It should work fine with localhost
 
@vivek You probably want bind as well, especially for member functions.
 
@codemaker yep, before I decided to write it from scratch. It worked when I was talking to @RMartinho not anymore
 
@codemaker it works fine with localhost
 
@CatPlusPlus What I want to do is to use for_each with a member funcition
 
8:33 PM
@codemaker I can't even talk to my router! What the hell! :S
 
std::for_each(foo.begin(), foo.end(), std::bind(&X::foo, &obj));
 
@LewsTherin you can talk to us. How are you talking to your router?
 
@codemaker lol I mean connecting to my router 192.168.1.1 doesn't work
 
Those expressions can get more complicated, but this is the basic case (X is a class, X::foo is a member taking one argument, obj is an instance of X).
 
@LewsTherin with your app or with your browser?
 
8:34 PM
@codemaker my app
 
@LewsTherin are you connecting on port 80?
 
@LewsTherin You're not supposed to talk to your router like that. Don't connect to 192.168.1.1, instead talk to some external IP.
 
@LewsTherin your app probably wont do anything useful when you connect because your app isn't speaking HTTP
 
There's one thing to watch out for — when the object is a value or reference, using std::bind(&C::foo, obj) will create a copy, so you need either &obj like above, or std::ref(obj).
 
@codemaker right... I wasn't listening at 80..
IT WORKED
omfg..it worked
lots of HTml stuff :S
 
8:37 PM
@LewsTherin boom!
 
@codemaker but it said bad request :(
 
@CatPlusPlus I'm calling for_each inside a member function of the same class so I should use this , right ?
 
Yeah.
Also code is better than italics.
Backticks.
 
@CatPlusPlus yes,
 
@vivek To reiterate the Cat's warning, you should (in all likeliness) use this and not *this. Just making sure.
 
8:40 PM
@LewsTherin naturally, your app isn't speaking HTTP
 
but bind didn't work like mem_func
` error C2825: '_Fty': must be a class or namespace when followed by '::'`
 
@codemaker yeah... what are headers? Just like little information or something?
 
Code.
 
for_each(an_island->cells.cbegin(),an_island->cells.cend(),bind(&nurikabe::fill_adjacent,this));
 
@LewsTherin in HTTP? The headers are basically key value pairs. They contain information such as what is being requested, who is requesting it, the content type, and so on
 
8:43 PM
Also, don't do using namespace std;.
 
@CatPlusPlus I thought it's fine as long as you didn't do it in a header file
 
It's never fine.
 
@codemaker key value pairs? What is that?
 
In headers it's just double not fine.
 
@CatPlusPlus any specific reason ?
 
8:44 PM
Flattening namespaces defeats their purpose, which is protection from name collisions.
 
@vivek Are you doing Stephan Lavavej's videos?
 
@LewsTherin whaaaat?!!! Like in an std::map, or a python dict, like "a = 1, b = 2, this = that"
@LewsTherin each key corresponds to a value. In some cases one key can correspond to multiple values.
 
@codemaker oh right like an assoc array
 
As for the error, more code. And full error message.
Associative array is such a stupid name.
 
@LewsTherin yes, exactly like that
 
8:47 PM
@codemaker Well HTTP is the next protocol I'm reading.. argh my head is a melon about to implode
 
@CatPlusPlus STL errors are huge.
 
@LewsTherin HTTP is not hard at all. good luck
 
associative arrays are a pile of BS, really
 
@codemaker I don't know about that]
 
they're some nothing concept that really means std::map<std::string, something>
 
8:48 PM
@DeadMG not that again.
@codemaker when I'm requesting a webpage, I'm using both tcp and http?
 
@LewsTherin yes. HTTP layered on TCP
 
@codemaker what happened to IP?
 
@LewsTherin IP/TCP/HTTP
@LewsTherin and there is stuff below IP. Ethernet for example
 
The Internet Protocol Suite is the set of communications protocols used for the Internet and other similar networks. It is commonly also known as TCP/IP named from two of the most important protocols in it: the Transmission Control Protocol (TCP) and the Internet Protocol (IP), which were the first two networking protocols defined in this standard. Modern IP networking represents a synthesis of several developments that began to evolve in the 1960s and 1970s, namely the precursors of the Internet and local area networks, which emerged during the 1980s, together with the advent of the Wor...
 
@LewsTherin you only deal in ip tcp and http though. The ip stuff is used for addressing from the programmer's perspective.
 
8:50 PM
@codemaker So HTTP is a top tier protocol
 
@LewsTherin you can think of it like that
 
@codemaker So it replaces the application layer?
or is it the application layer?
 
@LewsTherin I never learned the OSI model, give me a sec to brush up
 
@codemaker a second? Wow.
 
I am vaguely familar with it
 
8:53 PM
OSI is a theory, who cares, really.
 
@LewsTherin wikipedia says HTTP is in the application layer
@CatPlusPlus yeah, it doesn't map directly to real stuff
 
Internet doesn't really respect it, anyway.
 
@CatPlusPlus easier to understand things without it
 
@codemaker is in the application layer? What the hell does that mean?
 
@LewsTherin unless you have a test on it, ignore what it means
 
8:54 PM
@CatPlusPlus I do, for exams
 
Exams are silly.
 
@codemaker aww lol that's exactly why I can't
 
@vivek But important.
 
@LewsTherin in that case, just know HTTP is at the application layer. Learn the definition in your text book
 
@CatPlusPlus should I make an so question about it ?
 
8:56 PM
@codemaker It didn't say it is in an application layer, it said it is an application layer. Are you trying to confuse me ;)
 
Well, you can always do that.
 
I am just worried about the length of the code I'll have to post
 
Layers are theoretical abstractions, HTTP is a protocol.
So you'd say "HTTP works in application layer", or something like that.
 
practicality is based on theories. no?
 
It's nonsensical to say it is a layer.
 
8:58 PM
oh I see what you mean
 
come with me to my secret application layer
 
You filthy layer.
 
I meant appalachian lair, my appalachian lair
 
@vivek Try to minimise it.
 
@codemaker lol
 
9:01 PM
I'll post the whole code on ideone.com and show only the important parts on SO
 
if http is not an application layer, tcp is a protocol yet it is a layer..so ?
 
@LewsTherin no, these things just map to the layers in the model. TCP is a protocol and HTTP is a different protocol that works on top of TCP.
 
what layer does TCP map?
 
@LewsTherin according to wikipedia it doesn't map directly to one layer
 
@LewsTherin transport
 
9:09 PM
@LewsTherin TCP also has properties found in the session layer. All this stuff should be in your book.
 
It fits both the transport and session layer.
Because it's not created with OSI model in mind.
 
sehr cool.
 
It's transport layer in TCP/IP model.
 
so basically a protocol isn't a layer but one that can be mapped to a related layer
 
I have this method in my Tetris class: std::vector<Block> getNextBlocks(std::size_t inCount);
You may notice that it is not const.
The reason is lazy evalution.
 
9:14 PM
mutable, damnit
 
Not really lazy, it's just unreasonable that I would pre-allocate an infinite amount of blocks.
Probably should be mutable now.
However, in the past I was using a combination of read/write locks. A read lock returned a const object so I could only call const methods.
 
I feel like there was some earlier conversation about this I'm currently missing.
 
I don't remember having this conversation before.
 
Just a feeling. Carry on. :P
 
It's really tricky. If you use read locks then you're not safe by only providing const access. There may have mutable variables.
 
Two concurrent calls to "getNextBlocks" would result in two potential writes leading to a race condition.
So I ditched read/write locks. I sucks.
 
yeah
 
Evening
 
const is semantic, read/write locks are binary
 
What's up?
 
9:18 PM
so they're not strictly compatible
 
Also, the system needs to maintain a list of all active read-locks. This kind of bookkeeping counters the potentially improved performance.
 
@vivek Oh, right, the placeholder. I don't know why, but I had partial application on my mind. Derp.
 
ok, I have an interview with a big telecom company sometime next week
with their R&D dept.
 
Belgacom? Telenet?
 
9:28 PM
nope
Orange
 
@CatPlusPlus Do I have to include any header for using placeholders?
 
No, they come with bind.
 
A deadline is not a schedule
 
9:31 PM
yea and?
 
and it took me a long time to realize that
 
@CatPlusPlus VS din't recingnize _1 so I used std::placeholders._1
 
The boost::bind placeholders _1, _2, etc.. are global names (they are in an anonymous namespace, which is pretty much the same as global I think) and they start with an underscore. Isn't this forbidden?
 
but then I get this 'placeholders' : illegal use of namespace identifier in expression
 
@StackedCrooked It's not forbidden but easily results in an ODR violation when using them in a header.
 
9:33 PM
I got it
should be std::placeholders::_1
 
Hey guys remember when I asked if I could debug two things at the same time
 
@LucDanton so one should avoid "boost/bind.hpp" in header files?
 
and you didn't really help
I found out how to do it
 
@StackedCrooked Well, I don't know. Using bind is fine, only the placeholders are problematic. Plus that's the kind of ODR violation that gets unreported and may or may not break the program. Your call.
 
We have lambdas now, anyway.
 
9:37 PM
I never thought about it before. Never got burned. The boost guys probably wouldn't have done it if these names were already taken in other much-used APIs.
 
@CatPlusPlus You mean we have our hand-rolled polymorphic, perfectly-forwarding, decltype-ing, lazy expression templates. Well I do anyway; who needs Boost.Phoenix?
 
@CatPlusPlus We have them on paper. Most companies have a conservative attitude to compiler upgrading.
 
Joke's on you, my company doesn't use C++.
Or something.
My brain isn't working properly today.
Anyway, I now want automatic partial application.
 
I want function hooking :)
 
@CatPlusPlus I have that!
Well, I think. Let me try.
 
9:46 PM
 // How can this be made thread-safe?
Dictionary & GetDictionary()
{
    static Dictionary dictionary = GenerateDictionary();
    return dictionary;
}
 
By not using static?
 
And returning by value?
 
Mmmh, automatic partial application doesn't seem to work but I'm optimistic that it's because SFINAE isn't kicking in. Error being either on my part or GCC's.
 
im out
 
// Should work, but ugly
Mutex gDictionaryMutex;
Dictionary & GetDictionary()
{
    ScopedLock lock(gDictionaryMutex);
    static Dictionary dictionary = GenerateDictionary();
    return dictionary;
}
@sbi "Rule #1 for writing a list class in C++: Do not write a list class, because C++ already has one." I broke that rule on the programming test of my first job interview. I spent all the time on that so I didn't have time enough to do the actual exercise itself. And the list didn't work either.
@sbi Still got the job though :)
 
9:52 PM
now that vscanf is part of official c++ standard, perhaps will be there also in msvc... :-)
 
@codemaker Is that a declaration for an output variable?
 
@StackedCrooked: you made a good impression anyway
 
sbi
@StackedCrooked For educational purposes (and an interview is meant to check your education), even string classes can and should be written. Also, sometimes writing containers does have merits. (Like a vector clone using alloca().) But in general, it's not a good idea.
 
But there must be some better way than this, with msvc 10.0
    inline int scanf(
        CodingValue const* format,
        void* a01 = 0, void* a02 = 0, void* a03 = 0, void* a04 = 0, void* a05 = 0,
        void* a06 = 0, void* a07 = 0, void* a08 = 0, void* a09 = 0, void* a10 = 0,
        void* a11 = 0, void* a12 = 0
        )
    {
        int const   nArgs = !!a01 + !!a02 + !!a03 + !!a04 + !!a05 + !!a06 +
                            !!a07 + !!a08 + !!a09 + !!a10 + !!a11 + !!a12;
        BasicCodingValue const* const   f   = format->ptr();

        switch( nArgs )
 
9:55 PM
@sbi Also they didn't allow using std library at the test and they also didn't allow me to use a debugger. They reasoned that this would give candidates with a knowledge of them an unfair advantage.
 
... and then the Guy (highly likely) downvoted me. silly
 
@AlfPSteinbach Accelerated C++ was still fresh in the back of my head and I had just finished a 3 month internship that involved intensive C++ coding. I also had scored well on the multiple-choice C++ test. Also mentioning books like Effective-C++ on my CV helped.
@JohannesSchaublitb I think he doesn't know what he is talking about.
 
yeah seems like he's drunk
 
9:58 PM
i tried that perfect forwarding c++11 thing, but it seems not supported by msvc 10.0?
uh, @johannes, "access checking is done on names" -- but constructors don't have names and how is then access to them checked?
am i dumb now?
 
@AlfPSteinbach the Standard doesn't say how access to them is checked
hence I'm saying that likely the Standard is underspecified
 
hm. i just say -- hm
 
@AlfPSteinbach It should work.
 
you "call" constuctors using a class type name
 
@CatPlusPlus I tried with the ellipsis before and after X in template< typename X... > void foo() {} and it just barfs at it, syntax error
 
10:02 PM
so the accessibility of the class type name is important. but also the accessibility of the constructor. however for implicit calls to constructors, there is no class type name used, so it's not clear how such things behave with private virtual inheritance
 
@AlfPSteinbach Oh, it's not an issue with perfect forwarding, MSVC doesn't support variadic templates.
 
but I suspected, and I still stand at that suspicion: "For the compiler to default initialize the subobject, it just has to call its default constructor - there is no need to lookup the name of the base class first (it already knows what base is considered)."
 
Yes, it's very argh.
 
@AlfPSteinbach a reasonable assumption is, I guess, that access checking extends to constructors and destructors. that any code calling a constructor must "have access" to it (i.e if you would replace the constructor calling by a normal function calling, it must have access to the name of that function).
 
10:10 PM
It must seem like I'm living in the past for doing things like this.
 
@StackedCrooked oh, i have done that kind of thing on even more futile scale :-)
 
@AlfPSteinbach I read your about your arg packs.
 
@StackedCrooked i meant even earlier, like this: code.google.com/p/alfps/source/browse/…
 
@StackedCrooked You can generate those overloads.
I tend to use Boost.PP for this.
 
@CatPlusPlus How? Macros?
 
10:14 PM
Well, or with an external tool.
 
@StackedCrooked was OK?
 
@CatPlusPlus I undoubtly used Vim macros.
 
ALFS MAY THROW. LITBS WILL CATCH.
 
@AlfPSteinbach I tried to use it, but found it a little inconvenient. I don't remember the details exactly. I think it was that the base class had to support argpacks or something. I didn't give it a fair try though, should have experimented a little more.
I hear this chat's ping message in my mind sometimes.
 
10:17 PM
@StackedCrooked Boost.PP solution has the advantage of configurable arity.
 
(Googling "configurable arity".)
 
Also, auto_ptr sucks.
Number of arguments.
 
But boost pp macros don't really allow for variable number of arguments. I least I remember that much from when I was frantically writing that enum generater in Boost PP.
Or you had to explicitly pass the argument count as a first argument.
 
Well, no, but you can change max. arity with one parameter. Look at that make_unique.
It's a bit different here, you're generating overloads for [0..n] arguments.
So n is configurable thing.
 
I'm not really following.
Just found this code sample on SO:
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
@FredOverflow attempted to implement make_unique himself.
 
10:22 PM
This is for when you have variadic templates available.
 
It was @FredOverflow aha!
 
When you don't, you need several overloads for different number of arguments.
 
@CatPlusPlus your code
Does the Boost compatibility version work just the same as the C++11 version?
 
Well, it's all C++11, because it uses std::forward. But the Boost.PP version is for dumb compilers that don't have variadic templates yet.
Yes, they're both equivalent.
Except, of course, that Boost.PP version supports up to PL_MAKE_UNIQUE_MAX_ARGS arguments, and variadic template supports any number.
But if you need, you can bump up the parameter and generate more overloads.
 
@StackedCrooked As it should give them an advantage.
 
10:25 PM
Ah I thought the Boost version worked for C++03.
 
A ## count && arg ## count yields A0 && arg0, A1 && arg1, etc.
So it still needs rvalue refs.
 
@DeadMG It would have given me an advantage. I had forgotten that I had the option to use arrays in C++. That's why I ended up writing my own container class.
@DeadMG but yeah, it's a sucky rule
 
But the real question here is, why the hell are you using auto_ptr.
 
@CatPlusPlus I think auto_ptr is a good choice for the return value of factory and clone methods. I was also using it to pass objects to worker threads. Keep in mind that this is C++03 code.
 
C++03 was so eww, wasn't it.
 
10:29 PM
In retrospect, yes :)
I loved it though.
 
sbi
@CatPlusPlus It was an improvement over C++98, which itself was a huge improvement for those of us who had fiddled with templates before there was a standard, had written half a dozen string classes in a decade, and a few linked list classes as well.
 
Okay, back to OpenGL.
Let's see if I can make this damn bitmap font finally working.
 
C++ is regarded as an old language but it seems to me that it only started to shine in the 2000s.
 
a class with a private and undefined copy constructor (and no move constructors), and with a constructor taking an int. return it by value from a function definition, passing 3 to the constructor!
 
10:40 PM
@JohannesSchaublitb If the copy constructor is private then you can't return it by value.
 
there is a solution
 
I only see closed doors.
Don't reveal it yet.
 
I have no books
crap I only see 451, its not an instruction manual
 
Would you accept this?
 
easy yes.
 
10:51 PM
It horrible but I think it meets the requirements.
 
haha Bar's copy ctor is public xD
I will have to reject it :(
 
@JohannesSchaublitb But Foo's is private. Which was the requirement right?
 
I could easily live with that =)
 
return it by value from a function definition. you returned a Bar from a function definition :(
 
I might be missing something
 
10:53 PM
Inheritance indicates an is-a relationship. So I am effectively returning a Foo as well.
OK, but I'll accept the rejection.
 
I just told my students about raii
 
But I'm out of ideas now.
 
inhertiance is useful but terribly not so much
by value is a beautiful thing =)
 
1
Q: Can we return objects having a deleted/private copy/move constructor by value from a function?

Johannes Schaub - litbIn C++03 it is impossible to return an object of a class having a private non-defined copy constructor by value: struct A { A(int x) { ... } private: A(A const&); }; A f() { return A(10); // error! return 10; // error too! } I was wondering, was this restriction lifted in C++11, makin...

 

« first day (377 days earlier)      last day (4562 days later) »