« first day (374 days earlier)      last day (4575 days later) » 

12:00 PM
foo::foo(bar x) : x(x) {}
Does this look familiar?
 
ah, yes. Seen those before
 
the worlds richest company wouldnt be there today without ritchie. (and all the others by the way, too). and in addition you should know that technological advance is not measured in moneyto that
 
@BPDeveloper That's how you do it.
 
So thats used to initialize objects that has no default constructor when you have them as members?
 
@bamboon It's also not measured in people not having technology.
 
12:01 PM
@bamboon Of course it wouldn't. But dmr would have created something with no value if it wasn't for people like Jobs turning it into something with value.
 
@BPDeveloper That should be used to initialize all members.
 
the value of C, as a construct for making things, is measured exclusively by the value of what people can build with it
and also, unless you want to start travelling to other planets, then I think that money, food, and similar things of real physical value are the useful products of technology
 
Money doesn't have physical value.
Lots of it is just virtual, and paper is worthless.
 
Ah, okey. Thank you. I got one more question since in Java you write "new" for everything, but in C++ I am a litte unsure about when to use it.
 
money does have physical value
 
12:03 PM
@BPDeveloper Rarely.
 
Should I use it to make dogs if I don't know how many dogs I will make?
 
at the most basic level, you can trade it for food
no
use a vector
 
Educational purposes
 
then definitely don't, use a vector
 
but do you say "new" only on arrays?
 
12:05 PM
Ah, I completed section on how to fix Boost.Filesystem so that it can handle general Windows filenames. That's section 5. If you view using Google Docs (it's quite blurry in Google docs, and no table of contents) then that section starts on page 16. Enjoy. Please tell me about errors, misconceptions & possible improvements. Thanks.
 
no
use a vector
seriously
 
Using new will give you nasty problems that you shouldn't be struggling with as a newbie (even as an advanced user, you avoid new).
 
the only thing that you can gain from new is pain
 
Okey, but could you tell me in which cases you would use it then?
 
if I was implementing a data structure
that's it
 
12:06 PM
Yeah, when writing building blocks.
 
actually
 
but you would never say new Dog() ?
 
And even then you could avoid it.
 
arguably, even then, I'd only use new because there's no make_unique()
@BPDeveloper No, never.
 
@DeadMG Easy to write one :)
 
12:08 PM
I'd always use a vector or deque, or, at the very least, make_shared
@RMartinhoFernandes True true. But technically, that qualifies as writing new :P
 
@AlfPSteinbach Oh, cool, that will prove useful when I get to test filesystem interaction in my BT client. I'll have a look :)
 
So new is banned
 
not banned, per say
just, the circumstances in which it is appropriate are exceedingly limited
 
Avoid it if you can.
And usually, you can.
 
virtually all the time, you can
 
12:10 PM
okok
thank you
 
@RMartinhoFernandes "BT" = ?
bit torrent?
 
Yes.
@BPDeveloper If you find yourself not knowing how to avoid new, you can just ask here and we'll be glad to steer you into the path of light :)
 
Thank you, I was just about it because I don't understand it from what I have read
The only thing I read was that if you don't know the length of an array and you need to figure it out runtime then use "new"
and "delete"
 
nah
 
allocates space on the heap instead
 
12:13 PM
that's what a vector is for
whoever wrote that has no idea wtf they're talking about and you should read somewhere else
 
but if you were to use a C array then you would use new?
 
no, I'd still use a vector
that's what &vector[0] is for
 
You can't use new with C-arrays.
@DeadMG Now there's vector.data()!
 
for statically sized arrays, use boost::array<T, N>
also findable as std::array or std::tr1::array with more modern compilers
 
new int[42]; does not create a C-array.
 
12:16 PM
for dynamically sized arrays, use std::vector or std::deque
 
sbi
@RMartinhoFernandes Just ask the @Cat. His country cut off a couple of zeros in the nineties.
 
It gives you a pointer. Which is bad.
 
If you have a list of enums, would there be any good way getting a random enum value? Or is it a proper way of putting each enum value in a vector and generate a random numer and use it as an index fine?
 
Something like enum { x, y, z, w };?
 
@DeadMG new allocates requires the memory for a class and performs the constructor on that class. I wouldn't say they have nothing to do with each other.
 
12:23 PM
Are enum values guaranteed to be sequential if not made explicit?
 
They list is already made
enum Equipment {bone, ... }
I want to select a random enum from it
 
I thought of adding each of them to a vector
generate a random number and use it for index
 
If the names don't have explicit integral values, you can pick a random number between 0 and N-1 (where N is the number of values) and just cast it.
 
Did I mention i hate physics?
:(
 
12:26 PM
No.
 
well... I hate it.
especially O Level physics. :(
anyway , back to studies... :( :( :(
 
using static_cast<Equipment> ?
 
O levels? what country are you from?
 
@BPDeveloper Yes.
 
@DeadMG money having physical value, you have to explain me that.
 
12:31 PM
@StackedCrooked new performs two functions. Those two functions are not particularly related.
@bamboon Easy. You have some money, and you can use it to get food, shelter, etc. If that's not physical value, I'd like to see your definition.
 
money is just an IOU note for some gold, it depends how much you trust the person who wrote the note
 
Right, its value is on the trust.
It's not on its physical presence.
Unlike gold.
 
physical value is something for goods which are rare and important for our culture (like gold etc)
 
gold? important? rofl
the only value gold has is making pretty things
 
Not really.
 
12:33 PM
gold's physical value is based on trust that people will be as shallow as ever
 
turn your pc off if you think gold is not important
 
@DeadMG - I've seen no evidence of people becoming less keen on status symbols
 
uh, the quantity of gold used in making electronics is incredibly insignificant compared to the amounts used financially
 
guess why, the financial guys took it as one of their favourite trading items, because gold is really important
 
Gold is a nice conductor.
 
12:35 PM
same like oil etc
 
It's resistant to corrosion, so it lasts.
 
and it can be made extremely thin
 
yes, I know those things
but they're relatively miniscule uses
 
And it's rare.
 
gold wouldn't be a gold standard as it is today if it was just for it's real physical uses
 
12:36 PM
Unlike the freaking paper.
It's everywhere.
 
in any case
I prefer to think of money as a measure, rather than an actual thing
the money Apple accrued is more of a measure of the value of the products it produced
 
So, no physical presence.
 
statically linking a shared object against libstdc++ is bad right? any good references with an example of why?
 
How can it have physical value then?
 
simple
you walk to the shop and you give it away in exchange for food
how much more physical can you get?
 
12:38 PM
It's paper + trust.
Trust is not physical, and paper is worthless.
 
you make it sound like pieces of paper and trust aren't some of the most important things that ever happened
 
But they're not physical.
Food has physical value.
 
it's not trust any more than it's trust that people will continue to be shallow sacks of shit
 
shit is useless at the end of the day
 
No, it's not.
It has physical value.
Ever heard of fertiliser?
It's used to make food.
 
12:41 PM
shit is converted, via various processes, right back into the food we eat
 
Sometimes I wish I had studies economics so that I would be able to wrap my head around the concept of money.
 
true, i forgot that, but compare that to gold
 
Gold can't make food.
 
technology can do everything
 
If you're an alchemist you can make gold out of food, but the process is not reversible.
 
12:42 PM
i love discussions to which there is no end^^
 
technology can do everything- if you're prepared to wait long enough
 
@bamboon Yes, we have been able to transmute elements since the beginning of the twentieth century. It's just that it's way too costly to use.
And I mean costly in hard terms (energy), not in soft terms (money).
 
i didnt mean it that way, more like: gold is needed for technical things, and those technical things help us to produce more food
 
yes, it is
it's used in industry by 10% production, according to Wikipedia
the rest goes into shallow-sacks-of-shit jewellery and amagad-gold's-valuable investment
 
Well, you can't invest in oranges.
 
12:46 PM
yeah that sucks about gold
 
(But you can invest in Apple.)
 
gold looks shiny and is on the other side of technical high importance
 
well, I'm off to the shop
which I planned to do two hours ago, but hey
 
@RMartinhoFernandes - you can invest in oranges - buy a farm in Seville
 
1:28 PM
Buy a sev in Farmville.
Also hi.
 
hi
 
room topic changed to Lounge<C++>: R.I.P. John McCarthy [c++] [c++11] [c++-faq]
 
@RMartinhoFernandes They work when you only indent with tabs at the beginning, and do the rest with spaces (and no, it doesn't depend on tabwidth — aligning with only tabs do). But yeah, tabs suck.
 
We knew about that 14 hours ago.
 
1:33 PM
@CatPlusPlus Try using them in Haskell. Or to align something other than blocks.
 
@CatPlusPlus Well, I just came home from work, I couldn't have found out earlier.
 
Yeah, it's usually an error in layout-sensitive languages.
But if you have something like that, it'll be well-aligned regardless of tabwidth:
->....abc.=.1
->....d...=.42
 
1:50 PM
0
Q: Should I teach my students alloca?

FredOverflowHow widely used is alloca in the real world? Should I teach my students to use alloca when it makes sense? Or should I teach them never to use it? Coming from a C++ RAII background, the idea of not having to call free manually sounds promising, especially in functions with multiple exit points.

 
I'm expecting this to be moved over to Programmers.
 
I wouldn't care.
Oh, 4 closing votes already.
 
I like alloca in C for a small set of problems
if you are going to teach it I'd mention strdupa too
well strndupa
 
Mmmh, strdupa and strndupa have to be macros or otherwise magical to properly fetch the memory in the caller's frame, don't they?
 
Isn't alloca magical as well?
 
1:58 PM
Intrinsics, probably.
 
on my system it looks like alloca is an intrinsic and str[n]?dupa are macros
because if they were functions that called alloca they'd unwind before returning
 
Luckily C++ has default arguments for that!
(Well that wouldn't work here but for other problems, is what I mean.)
 
T foo(bar& b, void* dont_touch = alloca(42));
Notice the magic value.
Then you use as foo(blah);, magic memory from the caller!
 
Oh.
You can have default arguments depend on other arguments?
Because strndupa needs that.
 
2:04 PM
Nope, hence why it wouldn't work here and the magic 42.
 
isn't the best C++ version of it: template <typename T> T pointless(const T& t) { return T(t); }
i.e. copy construct and return by value
 
Sorry, using alloca as a default argument is something that has been recurring in my own imagination. I'm toying with allocators and especially what changed with C++11. So got caught up in my daydreams :)
 
@awoodland Can't you just write return t;?
 
That would also do a move if available.
T(t) makes a copy.
 
You cannot move from a const T&.
 
2:10 PM
Oh right.
Btw, what's the point of such an "identity" function in C++?
 
Makes a copy for a perfect-forwarding function.
I.e. it can be the counterpart of std::ref if using a perfectly-forwarding convention. I tend to call such a function val.
 
I was going to call it strdupa and confuse a C programmer with it :)
 
std::bind(functor, i, std::ref(j)) would have bind(functor, val(i), j) as counterpart when using a perfectly-forwarding convention.
 
Fuck, it's router nap time apparently. I'll do some reading instead of fighting against 40KiB/s speeds.
 
Does this make sense?
 
2:14 PM
typdef std::string str;
str ou; str up;
 
@RMartinhoFernandes But my lovely example :(
 
@LucDanton what is that std::bind? have seen it many times , any real use?
 
@MrAnubis replaces boost::bind
 
2:29 PM
@MrAnubis I don't know of any fake use.
 
@FredOverflow I think I'll pass on that one(VS, not the video), unless they update the feature set of the compiler.
 
:1744339 Transform a function into a functor when you want to pass always the same arguments but one.
 
@Benoit aah
 
@MrAnubis I think (but I'm not sure) the question that you want to ask is 'what problem or problems does it solve?'.
 
@LucDanton yes the very same
 
2:31 PM
Partial application of functions.
With the placeholders, it also does reordering of arguments.
 
so less writing of code , right?
 
size_t f(std::string x, size_t k) { return k + x.length());
sorry
 
@MrAnubis Yes. Makes adapting any preexisting function or function-like thing (functor, function pointer/reference, pointer to member) to a particular signature easier.
 
keep going please
 
std::vector<size_t> v;
...
std::transform(v.begin(), v.end(), std::bind(f, _1)(std::string("hello")));
will add 5 to every component of the vector
 
2:33 PM
Instead of writing a new function or functor (which would mean writing it far from the site of use), I can write a bind expression.
 
@Benoit and the value of k?
 
@MrAnubis Do you know what partial function application is?
 
@LucDanton thanks , got the good gist
 
I have a struct with a pointer and an int, I want to find one in a vector of these structs with std::find, should I implement operator== for the struct?
 
@MrAnubis std::bind returns a function that takes one size_t as argument and that returns size_t.
 
2:35 PM
Yes. Or pass a customised predicate to std::find.
 
Either that, or pass a comparison function to std::find.
 
I win.
 
dang
 
ok
thanks
 
FYI, operator== is usually implemented as a free function.
 
2:36 PM
so it needs to be a friend to my struct ?
 
Can't you access the necessary information from outside? Sounds like a strange design to me.
 
oh, yea I can
cause all is public obviously
I always forget what operator== should return?
 
bool
 
@MrAnubis My code is plain wrong ignore it
 
Oh noes listhps!!!
 
2:39 PM
std::bind(begin, end, bind(&T::i, arg1) == bind(&T::i, arg2) && bind(&T::p, arg1) == bind(&T::p, arg2))
 
bool operator==(const mystruct& lhs, const mystruct& rhs)?
 
Discussion collision! (Assuming Boost.Phoenix here.)
 
@TonyTheLion Yes, unless the struct is so small that you can pass it by value.
 
@FredOverflow it contains a pointer to an object, and an int
so I guess that's small enough?
 
Small enough in my books, but others might disagree.
 
2:40 PM
@FredOverflow Even when the struct is small, why not pass it by const reference?
 
overhead of indirection
 
can apply operator== to a pointer and know it's pointing to the same object?
 
It's a traditional identity test.
 
What exactly does the struct represent, if I may ask?
 
2:49 PM
it actually represents a square drawn on my canvas, and it contains a pointer to a QRect and a bool (I said int earlier, but it's bool).
just cause I need the bool associated with each square
now, I have this struct and it's called block, in my canvas class I have a function block current_block() but for some reason my compiler complains that it doesn't know block. I'm confused???
 
Is it defined before that declaration?
Also, QRect should be rather cheap to copy.
 
no, it's declared, but not defined.
perhaps that's the issue
struct block; class canvas {}; struct block {}; looks like this
 
It has to be a complete type for that signature.
 
right.
 
If I have one class named Owner that has a member variable of class Dog that has an non-default parameterized constructor. How do I do set it up then? I am soon giving up, feels like I tried all combos.
 
2:56 PM
class Owner { public: Owner(Dog d); private: Dog d; }; Owner::Owner(Dog d)  : d(d) {}
 
@TonyTheLion struct block; struct canvas { block get_block(); }; is fine, except you can't call or define get_block unless a definition of block is visible.
 
excellent WTF today
 
And if the object I need to pass to the dog is in the owner class just like: Bone bone; how would I do that?
 
@TonyTheLion Are you sure you want to compare the pointers and not the QRects?
 
@FredOverflow hmmm valid point. Not sure how I'd compare QRects. Just compare it's size I guess?
 
2:59 PM
QRect a, b; a == b;
 
probably has overloaded operator==
 
@TonyTheLion Depends on the ordering you're looking for in your comparison
 
If you have pointers, dereference them.
 
I don't know the type QRect, maybe it has an operator== itself?
 
@BPDeveloper Same, Owner::Owner(Bone b) : d(b) {}
 
2:59 PM
It does.
Also intersects, going back to yesterday. :P
 
your momma's so fat, she intersects the whole universe!
 
@DeadMG I intersect it too, just that it shrinks.
 
you know what irks me?
when you have a massive Internet connection like mine and there's not enough seeders on your torrentz
 
@RMartinhoFernandes Thank you, you gave me some motivation again. I almost gave up
 
3:05 PM
@BPDeveloper Give in to the power of the Dark Side!! cookies C++!
 
how can I check that the iterator returned from std::find is pointing to something? Just doing if (iter) doesn't seem to work?
 
I want to go back home to Java as soon as possible xD
 
iter != end, as usual
@BPDeveloper Pffft. That's quitter talk
 
oh yea, donno why I keep forgetting that
 
Java is the land of "I only ever write my programs the way the Lord Gosling deemed correct. I never raise questions, think independently, or look outside of the Kingdom of the Virtual Machine. Inheritance is my only God, and never shall I look for other programming tools or paradigms."
 
3:07 PM
 
@TonyTheLion Generally, there is no such thing as a null iterator.
@AlfPSteinbach What is the thing stuck in the fish? Bacon?
 
@FredOverflow yes
 
Well, take away the fish and the bacon and I would probably eat the meal ;)
@BenjaminLindley Hm, the video seems to be quite boring somehow...
 
sbi
@Xaade Igor, that you?
@AlfPSteinbach Why again do you post these?
 
It's the closest thing to porn we're allowed to post here.
 
3:18 PM
@FredOverflow That never seems to stop anyone posting actual porn.
 
it's obviously a lamp, the curve of the legs is wrong for if it was a bikini
 
@FredOverflow I have that lamp
in C#, 4 mins ago, by rlemon
I have a few questions about System.Windows.Forms.DataVisualization.Charting.Chart
 
We've finally deployed that thing I pulled an all-nighter on 2 weeks back.
60 error mails overnight.
And the script that was part of the process supposedly killed the machine dead.
Fun.
DF kind of fun.
 
4:01 PM
lol
 
4:18 PM
Oh, it's a LAMP.
 
now, if I have a bunch of squares on my canvas, and I need to find the one that's closest to the one I'm moving around, to detect possible overlap, is there some existing algorithm I can apply?
only one moving square, the others will be static
 
4:33 PM
Given that you are using squares, can you not calculate the square at each corner of the rectangle (the point can be converted to a square index. Let W be the the number of rectangles in the width, let H be the number of rectangles height-wise.
Let RX be the width of a rectangle, and RY be the height. Let any given corner of the "moving" rectangle, be PX and PY. (PX / RX) will give us the rectangle at a point on the X-axis, call it RESULTX. (PY / RY) gives us a vertical position. call it RESULTY. If the rectangles are stored as a continuous array, you can use [(RESULTY * W) + RESULTX] to get the rectangle in question, otherwise it's as simple as [RESULTX][RESULTY].
Do that test for each corner of your moving rectangle, and use the center of the target rectangle as an origin. Call that OX, OY.
You should have four Tuples now, PX1, PY1, OX1, OY1, etc
pick the one with the least distance.
This is, of course, my "I've already had a bottle of wine" solution.
So I'm happy to be raped with a better equation.
 
Let's assume a simple case of 10, 10 squares and there are 10 width-wise, and 10 height-wise
This means we have a 100 x 100 grid
 
my squares are not guaranteed to be next to each other
I've stored them in a vector<square>
fyi
 
Ok, in which case we will assume you have a bunch of Rectangle instances
or Square, indeed
 
right
 
4:43 PM
for each square, the origin is OX = (Square.X + (Square.Width / 2)), OY = (Square.Y + (Square.Height / 2))
I say origin, I mean center
The difference is (PX, PY) - (OX, OY)
and you can pick the least
but
The issue then becomes when you discreetly drag a top-left corner over the bottom-right corner of another
and yet it is still closer to the center of another.
I think going by the center will give you the best results
buts I admit I have not tried
 
I have a binary file i'm reading a table out of.. the column names are preceded by their number of characters. So while reading out of it using a BinaryReader
            for (int i = 0; i < columnCount; i++)
            {
                int headerLength = bReader.ReadInt32();
                data.Columns.Add(new string(bReader.ReadChars(headerLength)));
            }
   for (int i = 0; i < columnCount; i++)
    {
        data.Columns.Add(new string(bReader.ReadChars(bReader.ReadInt32())));
    }
answered own question while asking it disregard
 

« first day (374 days earlier)      last day (4575 days later) »