« first day (433 days earlier)      last day (4514 days later) » 

8:35 AM
@IntermediateHacker you must have a very poor memory
morning :D
 
string* s;
*s += *s;
is it UB ?
or string::operator+= has special case for it
 
Hello everyone , good afternoon :) Mighty slow room today !
 
8:52 AM
@Abyx Your string is not initialized so it's definitely ub.
 
@StackedCrooked it's initialized. I'm asking about *s += *s;
 
Apart from that the code would be equivalent to: string s; s += s; which is fine.
 
why it's fine?
 
Why not?
 
what about T t; t += t; ? Is it ever fine?
 
8:54 AM
it would be the same as saying int i = 2; i += i; which is easy to see that it will result in i = 4
yeah...
 
Indeed.
 
take the current value of t... add it to t
there is no doubt about what is happening
 
but operator+= usually get const reference of rhs
this_t& operator+=(const this_t& rhs)
 
yeah... so the RHS is a const... the left hand side can still be modified
 
there is no copy created
 
8:57 AM
@Abyx You have to use copy/swap for safe assignment.
 
that just means that += can't edit the value that the RHS points to using the refernce to RHS
 
so, every += should create a copy, or check if &rhs == this
 
// I think this will do.
std::string & operator+=(const std::string & rhs)
{
    swap(*this + rhs);
    return *this;
}
 
@Abyx No!
There's no point in that.
Usually you can write the function such that such checks are not needed.
 
@RMartinhoFernandes There must be a copy somewhere.
 
9:02 AM
for example, this code generates segfault (#AV)

    #include <iostream>
    #include <string>
    using namespace std;

    struct str
    {
        char buf[100];

        str(const char* s) { strcpy(buf, s); }

        str& operator+=(const str& s)
        {
           strcat(buf, s.buf);
           return *this;
        }
    };

    int main()
    {
       str s("test");
       s += s;
       cout << s.buf;
    }
 
That's because you use strcat.
 
@RMartinhoFernandes The problem is overlapping data. A copy must be made somehow/somewhere to prevent this issue.
 
There is no overlapping data.
 
buf == s.buf
 
I can replace strcat with loop
 
9:04 AM
@RMartinhoFernandes he's trying to so: std::string s = "test"; s += s;
 
string& operator+=(const string& that)
{
    // assume no reallocation is done/not needed
    for(int i = 0; i < that.size; ++i) buf[size+i] = that.buf[i];
    size += that;
    return *this;
}
Just don't use the crappy C string library.
 
@RMartinhoFernandes Yeah, assuming no reallocation is needed. That's easy.
 
@StackedCrooked If reallocation is needed there is no problem.
(The reallocation solves the problem just like your copy would)
 
can someone reccomend a good searchable online reference manual for c++ ? (One with class and method descriptions ?)
 
google :P
 
9:07 AM
@thecoshman You know , google is not always the answer to every query !
 
@angryInsomniac sure it is :D
 
@thecoshman :P If only that were so !
 
string& operator+=(const string& that)
{
    char* newbuf;
    if(size+that.size > capacity) newbuf = new char[size + that.size];
    else newbuf = buf;
    // I believe std::copy has same semantics as memmove
    // if not use memmove :P
    std::copy(buf, buf+size, newbuf);
    std::copy(that.buf, that.buf+that.size, newbuf+size);
    buf = newbuf;
    size += that;
    return *this;
}
Should use a smart pointer ;)
 
@angryInsomniac but it is so
 
9:15 AM
@thecoshman Am I doing it right? google.com/#q=what+do+women+want
 
@RMartinhoFernandes nope
doing it right is NSFW
 
0
Q: Reversing order of elements in a priority Queue

angryInsomniacI am pushing stuff into a priority Queue and I've made a comparison method for elements that go in there , when I checked the order , I realized I wanted elements to go in the other way around , so I went and changed all the boolean returns from my comparison method to be opposite of what they o...

Can anyone help me explain this ?
 
:2184529 you forgot to increase capacity
also, it should use resize(), so it would be

    if (size+that.size > capacity) resize(size+that.size);
    append(that.buf, that.size);

but compiler may generate this code:

    char* temp  = that.buf;
    if (size+that.size > capacity) resize(size+that.size);
    append(temp, that.size);
 
So, Markdown wins again?
:P
 
(seems that I should read a manual of this chat =)
 
9:23 AM
@Abyx No, it cannot generate that code. That code does not behave the same as the other one.
 
what about append which calls resize?
append(that.buf, that.size);
 
That won't happen: you already resized.
And the second code you showed is UB.
You cannot assume a compiler that injects UB where there is none.
 
string& operator+=(const string& that)
{
     append(that.buf, that.size);
}
void append(const char* s, size_t size); // calls resize()
 
Not even Hell++ does that.
@Abyx So what's the problem then?
 
@RMartinhoFernandes that.buf is copied and becomes invalid after resize called
 
9:27 AM
But why would you do that?
 
why not? it looks as good code, if forget about x += x
 
Sure, so you write:
if (size+that.size > capacity) resize(size+that.size);
append(that.buf, that.size);
 
wait, but if I have public: void append(..), it WILL resize
 
so why should I call resize before append?
(I already forgot about x+=x;)
 
9:30 AM
Because you're passing data to append that you know may become invalid.
 
there is const string& that, it will not be modified, I don't see how it can become invalid
 
Weren't you talking about appending itself?
 
anyway I believe somewhere lives a class with operator += which can't be used in x+=x expression
 
oh god I really want to have nachos!
nachos are what I NEED for dinner
 
@RMartinhoFernandes we can pass functor to std::priority_queue constructor?
 
9:41 AM
I think so.
 
@RMartinhoFernandes :) , Thanks
btw my new avatar pic is awesome :D
@RMartinhoFernandes you're finished with greed?
where to get it's source?
 
10:05 AM
@FreakEnum No, I'm not :) I have a repo on bitbucket. hg.tumtumtree.me but I haven't touched it in a while.
 
@RMartinhoFernandes cool , looks big project , Thanks
 
 
1 hour later…
11:16 AM
0
A: Flash games hack, score is 49700?? How to improve flash games security?

aalamis there any secure way to prevent hacking ..? we are running the monthly tournament and all time games are hacked and we loose good amount of money each month .. plsss help .. Fakira.aalam@rediffmail.com

lol
 
@FreakEnum Oh, I'm sure @keith wants that too.
 
@RMartinhoFernandes why is that so? :)
 
Hehe, you should ask him. But please do so while he still cannot punch you in the face over the internet.
 
morning
 
11:21 AM
Hi.
 
@RMartinhoFernandes KK :D
 
"Santa, I want the ability to punch you in the face"
 
lol, NameCheap is giving discounts on domain transfers with the coupon code "SOPAsucks".
 
some are giving discounts against GoDaddy too
BYEBYEGD
 
Epic :D
 
11:32 AM
for it's support of SOPA
 
I love it
 
so... what's the state of SOPA, are they still putting of actually saying anything about it?
 
o btw robot
my LOC has gone from 2230 to 3400 and I'm not entirely sure where on earth the extra code came from
 
Err, $ hg diff?
 
11:46 AM
@DeadMG: diff -Ewbu | diffstat
 
lol
 
Or some equivalent GUI shenanigans.
 
good point, I ought to commit & push
 
in that case, do git diff HEAD -- filename
of git diff -- filenameif not staged yet; add --staged if already staged
 
He uses hg.
 
11:48 AM
I c
 
There's no stage.
 
Someone else was reciting 'git push origin master' then
 
But you can diff without committing.
 
@RMartinhoFernandes That's pretty redundant after He uses hg
 
yeah
but I ought to commit anyway
wouldn't want to have to re-spend a day fixing things up
 
11:49 AM
@sehe How could I know if you knew that? ;)
 
Yeah. That would suck: need to commit before reviewing the commit? It would be good for commerce at the local Donut shop
@RMartinhoFernandes Everyone knows only git has 'complicated' staging area
Allthough... TFS work-areas actually can contain the shelfs, IIRC
 
TFS shelves suck. Unshelving doesn't merge, it simply overwrites.
On my previous job I had to fix some bugs more than once because of that.
Woah, I just generated a virtual credit card whose CVC is 999.
 
lol
 
12:04 PM
@RMartinhoFernandes I had exactly that.I quickly turned to using Git in guerilla DVCS mode
The shame was it was a 10yr-old MFC application with all of the database schemes in MFC binary-serialization archives. Laaaarge files.
 
I'm not unhappy that I got assigned to a different contract. Doing C# mainly, but it is ok when using ViEmu+Resharper. Quite productive :)
 
Yeah, those two are really awesome.
 
12:18 PM
here's a question
how do I friend a function that isn't declared when the class is defined?
 
Friending declares it I think.
However, if it's on another namespace, you need to declare it.
 
it's a private implementation function and I'd really rather not have any declaration anywhere near my header
 
No deal.
namespace detail?
 
eh just passed out the private data members as references
uglymatic but it works
 
12:35 PM
damn, MSVC doesn't have a hash for u16string?
 
12:46 PM
is it possible that a decoded JPG into RGB is 400+ mb in size?
 
Yes.
Now, how big is the JPG?
 
a bit over 3mb
 
hmmmmmm
 
hmmmm
 
@TonyTheLion So 3MB plus 1bit?
 
12:50 PM
if I have const wchar_t* + UDT, where there is in the global namespace operator+(const UDT&, const UTD&), and UDT defines an implicit constructor from const wchar_t*, that should be legal
right?
 
@FredOverflow hahah no, bit bigger than 3mb
 
I've seen JPGs being ~1% of the raw size, which kind of matches your values. But it depends on a lot of factors.
 
right, well the img is 4000x3000 something pixels
 
Then it should be 36 MB.
 
now a raw RGB isn't a bitmap is it?
 
12:51 PM
4000x3000 *12bytes is 144,000,000
 
RGB only needs 3 bytes.
 
ah yes, colours on the GPU are 4byte per channel, but on the CPU they're only 1byte
 
I'm actually trying to convert my jpeg into bmp, not RGB, but haven't found how to do that with CImg
not even sure it can be done
 
A BMP has aligned rows, I think. But that would only add at most 3x3000 bytes.
 
12:53 PM
@FredOverflow technically, RGB can be done with just three bits. Note that I have no idea about the context of what you said
 
@TonyTheLion .NET can help you
 
@Abyx I'm not using .NET
 
note: This is the C++ room
 
so what? .NET it not a language
 
12:54 PM
is n't dot net a frame work...
 
it's a framework, and it's not used by C++ in any remote way
 
Hosting the CLR to convert images sounds like overkill to me.
 
lol yes
 
exit
oh... sorry
 
C minus C++!
0
Q: C - C ++ Embed Makefile inside program

JohnI'm trying to embed this 'Makefile' inside my program, so I figured out how, but i'm facing a little problem. My code works if i program this in command line tool in xcode, but if i choose to program it as application using the SDL library, the compiler dosent generate or export the (.o) fi...

 
12:56 PM
ok, now what should I use to convert JPG to BMP
 
tried to exit out of one too many shells :P
 
cause all the libs I've tried so far don't seem to have an option
I want to do it in-memory, so no saving files to disk
 
A BMP is easy to build from the raw RGB values.
 
@RMartinhoFernandes ah
interesting...
tell me more?
 
have you found a library for decompressing the jpeg?
 
12:58 PM
@thecoshman yes
 
It's just a header (whose format you can find from a WinAPI struct somewhere), and then a bunch of RGB triplets, with a bit of padding on each row.
 
@RMartinhoFernandes hmmm
 
and now you just want to write your image data to bmp?
 
yes, I want to convert
 
Can you use the WinAPI?
 
12:59 PM
yep
 
well, if you have a decompressed image it would be an array of pixel values... a BMP is not much there header data followed by pixel data
just read up the spec on wikipedia
 
right, I'll have a look into that
 
you won't will ya :P
 
@TonyTheLion I know that structs for the headers are defined somewhere, possibly in wingdi.h or something. Look for BITMAPFILEHEADER and BITMAPINFOHEADER.
 
oh right
cool :)
afk
 
1:05 PM
@thecoshman Well, BMP has several simple compression formats, I believe. RLE and stuff.
 
@FredOverflow there are a few version though I think... BMP is a rather loose format if I'm not mistaken
 
cpx
Just found that you get extra flag points if you mark a question as spam with low quality.
 
Well, to build by hand the uncompressed one is easier :)
 
RLE is not exactly hard to implement ¬_¬
 
am I the only guy who isn't spamming for flag weight?
 
1:08 PM
but yeah, as with many things, it's easier to not do it
 
@DeadMG If you spam you will lose rep!
 
what is flag weight and why should I spam for it?
 
cpx
Imaginary points
 
What else?
> Password (max 20 characters) :
I'll never understand this crap.
 
@RMartinhoFernandes they keep plain text passwords in DB
 
1:18 PM
@TonyTheLion: perhaps don't decode into 128bit RGB?
 
1:33 PM
0
A: convert 64-bit binary string representation of a double number back to double number in c++

Daren ThomasOh dear, I thought this would be a no-brainer, but I'm a little stuck in lala-land. Good thing is, though: You can inspect lala-lands code! Try: Perl: pack/unpack Python: struct These do what you want. Now you just need to check how they did it in the source ;)

lolwut?
 
lol
I'd increment in the loop condition instead of embedded in the assignment.
Makes the loop progress easier to evaluate.
Or better, make it a for.
 
@RMartinhoFernandes But then you would miss the first bit ;)
 
:)
I'll just leave it as it is, changing a while into a for is not worth the edit :)
 
1:55 PM
@RMartinhoFernandes I wish I could downvote, but my rep is divisible by 10, and I don't want to ruin it :(
 
amagad
my code compiles!
this must be illegal
 
@AggelosBiboudis Nice avatar you got there :)
 
@FredOverflow ;) Some pure FP in our lives is always good!
 
2:19 PM
I hate hate hate hate this
even on basic questions I always overdo my answer, and gain nothing.. can someone please kill me, right now?
(figuratively, that is)
1
A: Memory realloc risk

refpCan I lose data if I use it correctly? No, there should never be any data loss when using realloc, it should be the syntactically the same as doing the below. new_memory = malloc (new_size); if (new_memory != NULL) { memcpy (new_memory, old_memory, old_size < new_size ? oldsize : new_si...

 
@refp What do you mean, kill you? Do you want a downvote or something?
 
Nhaa, I was too quick to judge.. I wrote my post, waited for a while, saw a thousand other posts and got sad
 
How wrongly did I expressed my question? I didn't ask about polymorphism or array covariance in C++. I didn't asked if pointers are good or bad, whether containers are good in contrast with pointer arithmetic for array types or not.

Hmmm...

http://stackoverflow.com/questions/8615238/how-to-deal-elegantly-with-abstract-factory-and-arrays-as-a-return-type-in-c
 
@AggelosBiboudis What exactly did you mean when you wrote "return a wider array of buttons"?
 
@FredOverflow Maybe it is a matter of my expression after all :P
@FredOverflow My question is just this: what am I supposed to do when I need to return arrays instead of a single item in C++, in the abstract factory pattern?
 
2:31 PM
@AggelosBiboudis return array of items, what's a problem?
 
You never want to return arrays in C++. You want to return vectors.
 
@FredOverflow std::array ?
 
@FredOverflow I hate using arrays, I use vectors whenever I can.
 
@IntermediateHacker see above
 
2:32 PM
anyway, what's "an intelligent" ?
 
@IntermediateHacker this is not \b....
 
@IntermediateHacker It's an amalgamation of bad grammar from people's posts.
 
1
Q: How to infer correctly?

JanitorHow do AI based agents infer a decision that are not necessary rational but logical correct based on previous experience. In the field of AI how do experts system infer, what kind of maths and probabilities are involved here? I plan on creating an intelligent, but don't no where to start. Poin...

 
Also, you can use words.
 
@Abyx If the size is known at compile time, std::array would work as well.
 
2:34 PM
@FredOverflow Nice one :)
 
But note that you cannot move arrays, only vectors. Well, moving arrays moves its elements, but moving vectors leaves the elements untouched.
 
@AggelosBiboudis You're not.
 
@FredOverflow It is known in my case.
 
I can't comprehend retarded grammar and it is suck...
 
@DeadMG Thank you for the answer.
 
2:35 PM
@AggelosBiboudis std::array<std::unique_ptr<Button>, 2> it is, then.
 
"Moving" is a misleading term I think. It's basically a shallow copy that invalidates the original.
 
Depends on the type.
 
You can't move memory.
 
@StackedCrooked would be cool with a unique reference type
 
@StackedCrooked What about memmove? ;)
 
2:36 PM
What about a shared_array of boost?
 
<--- this person is retarded.
 
"Eviscerate" is much more accurate.
 
that always "moves" upon assignment, will probably cause developers to write code that are filled with bugs, but shiznit
 
@RMartinhoFernandes std::disembowel
 
@refp What are you talking about?
 
2:37 PM
lol
 
@FredOverflow I'm trollin', that's all I do in here
 
@StackedCrooked That's too easy to pronounce.
 
@RMartinhoFernandes Maybe.
 
@FredOverflow a reference type that always moves, dances, throws up and then pass out in your sisters bed
 
@refp that makes the two of us.
 
2:39 PM
Anyway, I think WideC should have "creators" and "destroyers" instead of "constructors" and "destructors".
 
@refp I don't have a sister. And she doesn't have a bad.
 
I think "stealing" would be a nice term.
 
Too mainstream. Make it "pilfering".
 
Stealing from an anonymous victim which cannot complain.
 
I think WideC should have "maters" and "abortion"
 
2:39 PM
Abortions are exceptions thrown during construction, right?
 
I think I'm incredibly glad that I control it and not you
 
swap_internals
 
@StackedCrooked You mean std::swap?
 
@FredOverflow Sometimes, ... I guess.
 
2:41 PM
2 hours ago, by R. Martinho Fernandes
Zing.
Zang!
 
I think I'm gonna go and grab a smoke
 
smoking causes cancer.
 
@IntermediateHacker You're two hours late.
 
B O O O O O O O O O O M
yeah, you guys use lazer pointers.. I use BOMBS.
 
@RMartinhoFernandes damn. :(
 
2:41 PM
I won!
 
^^^ this person is retarded
 
^^^ that person is a game boy.
 
^^^ this person is a gradient
 
<-- that person took that as a racial remark since he is indeed black
 
<-- this person is black too.
 
2:44 PM
0
Q: Is specializing std::swap deprecated now that we have move semantics?

FredOverflowThis is how std::swap looks like in C++11: template<typename T> void swap(T& x, T& y) { T z = std::move(x); x = std::move(y); y = std::move(z); } Do I still have to specialize std::swap for my own types, or will std::swap be as efficient as it gets?

 
cpx
Abortions?
 
@cpx you accidentally?
 
anyway , @refp lol.
 
cpx
Throwing an exception during abortions i think is undefined behavior.
 
use the pill operator
 
2:46 PM
@IntermediateHacker black people don't laugh, we use gunz.. aight? shiznit..
 
it's faster than abortion
 
pending cigarette, afk
 
@refp I'm black as in skin color, not black as in from african-american origins.
damn... my aunt's come to visit. :(
 
Oh noes, here we go again. Can't you just talk?
 
pictures are more expressive.
 
lol, broken link
 
It was there when I copied it.
 
anyway, can someone change the caption? (the new cap should have correct grammar)
 
You can't downvote my answer for properties of the question. I can't fix the question without not-answering it.
Besides, it is not as if I didn't 'denounce' the interface or something.
 
"It works without modification"
it does not work at all, in the slightest sense of the word
it compiles, but that's not the same as working
 
2:59 PM
Yeah, when you work you get paid and all that.
 
(The OP doesn't do this interface. The OP was just wondering whether covariance applies to arrays being returned by value. Which it does. That works without f-ing modification
 

« first day (433 days earlier)      last day (4514 days later) »