« first day (300 days earlier)      last day (4650 days later) » 

12:04 AM
right
I'm off to beddyboos
see you all later
 
@DeadMG G'night.
 
all
12:42 AM
How to get size of object using member function?
 
 
7 hours later…
7:46 AM
@all In case you're still around, return sizeof(*this) should do that (though the general idea doesn't lead to immediate enthusiasm). In particular, if you're using inheritance, this will return the size of the static type of the pointer you're using, not the dynamic type (the size for the object that's actually pointing at).
 
anyone know what this does return ((x != 0) && ((x & (~x + 1)) == x));
where x is an unsigned int ?
it's a little quiz...
 
Als
@TonyTheTiger: Not even attempting that one :)
 
@Als oh c'mon
 
Detect if it's a power of two or something like that.
 
@LucDanton spot on!
 
7:55 AM
'Something like that' because the test against 0 leaves me non-plussed.
 
well the explanation is on that page somewhere
 
> The first half of the expression ensures that x is a positive integer.
But x is declared as unsigned int.
I think it's unwarrantedly trying to avoid rollover.
Is 'unwarrantedly' a word?
My spell checker says it isn't, but that seems unwarranted.
 
yea, seems like its word
as far as Google is concerned
 
sbi
@JerryCoffin sizeof(*this) returns the size of the type for the class it's been defined for, which is not necessarily the size of the static type of the pointer the member function has been called for.
For example, if you call through a Base&, the member function is implemented in Derived1 (derived from Base), but the actual object is of DerivedDerived (derived from Derived), then what you get is Derived, not DerivedDerived (the dynamic type) nor Base (the static type).
 
what's the difference between the statictype and the dynamic type?
 
sbi
7:58 AM
@LucDanton My spill chucker chokes on it, too.
 
is that just whether there is polymorphism involved
lol
 
sbi
@TonyTheTiger If you have a Derived that's hidden behind a Base&, then the static type is Base, while the dynamic type is Derived.
@TonyTheTiger It only matters when there's polymorphism involved.
 
@sbi where do you learn all they funky polymorphism rules?
 
sbi
@TonyTheTiger I learned that long ago from books, articles, and Usenet discussions.
 
Als
@voidmain is not Standard C++ :P
 
8:07 AM
0
Q: What are the C++ things one should know about polymorphism

Tony The TigerWhen using Polymorphism in C++, what are the important facts to know about it. Like, for example, when casting from derived to base, what should one be aware of? When is an upcast possible, and when not? When do you need a 'virtual' destructor and when not? What do you need to be aware of wh...

answer that
lol
 
Uh static vs dynamic type is not obscure, no offense intended. I did notice those quotes though.
 
@LucDanton it's not something I knew
 
Have you had a course in OOP/polymorphism? These things can be helpful to learn/discuss from a language agnostic point of view, then mapped to a C++ concept.
That is, before we mention C++, what do you know in general about OOP?
 
I know know that it's not necessarily obscure therefore, that's why I put the quotes
though, I wanted specifically regarding C++
 
Well okay but I think static vs dynamic type can be simply described as e.g. terminology regarding the implementation of dynamic dispatch in C++.
This may or may not be an acceptable explanation to you, depending on whatever knowledge we commonly share.
 
8:14 AM
@LucDanton yea, well, dynamic dispatch is not something I"m that familiar with, though I've read about it, and heard about it
 
And that's why I think language agnostic ideas would be helpful here, with all due respect.
 
@LucDanton you're free to change the question
:)
 
But I can't know what you and I commonly know :p
 
@sbi Yeah -- I didn't state what I intended to clearly at all. The point is that to get the right size, you'd have to define the member function as virtual in the base class and override it in every derived class to get meaningful results.
 
@TonyTheTiger: I always liked the terms "is-a" and "has-a"...like the old ideas of circle "is-a" shape and "has-a" radius. Note that not all shapes have-a radius, but if something is-a shape it must have a bounding rectangle (for instance).
You only derive class FOO from BAR when FOO is-a BAR. If the set of things you can do to a FOO is not a superset of what you can also do to a BAR then it simply is not an "is-a" relationship and inheritance is not appropriate.
 
8:33 AM
@HostileFork The "is-a" terminology can be deceiving though. The standard example is that a circle is an ellipses, but a circle class definitely should not derive from ellipse (or vice versa). Likewise with square/rectangle, etc.
 
Lot of voices saying OOP is broken, for a while they said interfaces were the answer, others saying completely new models were needed...
 
Instead, the proper criteria is that a derived class can always be substituted for the an object of the base class.
 
But I think within the C++ narrative is-a and has-a works pretty much most of the time for understanding the goings on.
And when to derive vs. encapsulate
 
@HostileFork At least IMO, they're mistaken. OOP isn't broken, and interfaces raise as many questions as answers. The problem is that OOP doesn't fit most people's though processes nearly as well as most people like to think or preach.
 
I'm a domain-specific language person, so I believe in new engines of language design that let one use common subsystems (like arithmetic) while adapting the language to the problems it intends to solve in ways that transcend the generalized constructs. Needs new tech.
 
8:38 AM
That doesn't mean it can't work, just that getting it to work requires you to be very careful about how you think about things. Unfortunately, the same is/will be true of every other competitor as well, for the simple reason that people tend to think in rather "fuzzy" terms, but without a lot of work to make them otherwise, computers don't work that way at all.
 
I wasn't aware that interfaces were contentious. Or is that for instance the 'brittle base class' problem?
@sbi Is it intended that the noob help 'fell off' from the right?
 
@LucDanton They're contentious only to the degree that Java users (for one example) treat them as being a (superior) replacement for multiple inheritance. There's nothing terribly wrong with, but they're not nearly the great new thing some fans believe either.
 
my question was closed as not constructive... meh
 
@TonyTheTiger: Not a bad question to ask, just not the Q&A fit of the site. I had to rewrite an electronics question after it got closed before they'd answer it because it seemed too "open"
On the EE stackexchange
 
"What should I know?" is a tough question to answer to be honest.
 
sbi
8:43 AM
If you are new here, please read the newbie hints. Thank you.
12
@LucDanton No, but pins are unpinned after two weeks. The newbie hints explain that, BTW. :)
 
@TonyTheTiger That's happening a lot more often lately. I don't like it, but it's hard to avoid. When there's too much volume, people start looking for ways to keep it more manageable. On Usenet, people just got anal about topicality. Here, there are other reasons/excuses, but when you get down to it, the reasons and effects are mostly similar.
 
sbi
@TonyTheTiger Link?
 
9:11 AM
0
Q: What are the C++ things one should know about polymorphism

Tony The TigerWhen using Polymorphism in C++, what are the important facts to know about it. Like, for example, when casting from derived to base, what should one be aware of? When is an upcast possible, and when not? When do you need a 'virtual' destructor and when not? What do you need to be aware of wh...

 
Hah!
The quote in the answer:
The exception being handled is rethrown if control reaches the end of a handler of the function-try-block of a constructor or destructor. [...]
Does that mean that void foo() try {throw 1;} catch (...) { } rethrows the 1 from the catch block??
 
@JerryCoffin It's annoying if you ask me. It's getting too much police and too many arbitrary rules thrown in. It is supposed to be a "community driven" site, seems more like a meta police driven site these days. bah
 
@wilx Well foo here doesn't look like much of a constructor or destructor, but if it were then yes.
 
Oh, so it rethrows from ctor or dtor?
WEIRD!!
 
> the function-try-block of a constructor or destructor.
 
9:17 AM
FML!!
I honestly did not know that, it seems counter-intuitive.
 
For constructors though it makes sense.
 
But for dtors?
 
There is something to be said for consistency. Then again those could be removed without making a difference.
Whereas the function try block is a necessary feature for constructors.
 
@TonyTheTiger Like I said, I don't like it much either, but I don't know of much way to avoid it. Part of it is a semi-legitimate response to excessive volume -- but there's also quite a bit that's basically busy-bodies making up and enforcing rules. It's hard to avoid them and even harder to get rid of them...
 
true that
 
9:29 AM
Back in my day... we edited articles uphill both ways. (shakes cane) Now get off my lawn!
 
anyone familiar with boost jam?
 
@TonyTheTiger I've used it, but not enough to give any meaningful advice about it.
 
I've only used it to build boost.
 
9:44 AM
I'm trying to build an open source project, that uses bjam to build, though vs says it can't find bjam
'bjam' is not recognized as an internal or external command
is what VS spits out
 
The bjam executable must be found in your PATH environment variable. Or in the executable paths from "Visual Studio Directories".
 
ah, now I first have to find the bjam executable, lol
 
@TonyTheTiger sounds yummy...
 
boost jam sounds like nutrition for body builders or something
3
 
9:49 AM
Ok, fixed that.
After all those years of doing C++, there is still something that catches unprepared. :)
 
@StackedCrooked where is this "Visual Studio Dirs" in 2010?
 
@LucDanton Without the test for 0, the formula would spit out true for 0, but 0 is not a power of two.
 
@TonyTheTiger Tools->Options I think
@TonyTheTiger sorry in 2010 this no longer exists
 
@StackedCrooked found it, it's under the project properties itself
not in the vs properties
 
10:01 AM
oh hi
 
o
now you have ohio
 
I have no particular desire for any thing or place known as "oh hi o"
 
I will take note.
 
10:13 AM
@FredOverflow I'd swear there's a duplicate of your question but I can't find it.
 
I am trying to develop a GUI toolkit. And am stuck with the design.
I am trying to make a good signal/connection system.
 
@LucDanton We have discussed it in the chat once. Maybe that's what you remember?
 
But can't seem to find the best way to do it.
Can anyone see through a bit of my code?
 
There are only 30 unique_ptr questions. If there is a duplicate, it should be one of those, right?
 
In any case make_shared allocate a block of memory in one go, puts the refcount in one spot, and emplace construct the object in the other.
 
10:15 AM
namespace Nex
{

template <class Wdg> class Event
{
public:
Event() {}
virtual ~Event() {}
public:
void Activate(void)
{
for (int i = 0; i < FuncSet.size(); i++)
{
(*FuncSet[i])(iwdg);
}
}
public:
void Disable(void) { enabled = false; }
void Enable(void) { enabled = true; }
void Register(Wdg& v) { iwdg = v; }
public:
void Connect(void (*Ptr)(Wdg&))
{
FuncSet.push_back(Ptr);
}
void Disconnect(void (*Ptr)(Wdg&))
{
FuncSet.pop_back(Ptr);
}
protected:
bool enabled;
std::vector<void (*)(Wdg&)> FuncSet;
 
@FredOverflow Correct. I might be thinking of a question related to make_shared; perhaps a reference to a tentative make_unique was made. I also remember discussions in chat.
 
Anyway, I would really like a make_unique in the standard C++0x library...
 
Damn, all the indents went away. Doesn't chat support formatted text?
 
@IntermediateHacker Move your cursor with one of the arrow keys, the 'fixed formatting' button will appear.
At least that's how it behaves on my end.
 
you shouldn't paste more than a couple of lines, you should post it on pastebin for the chat
 
10:20 AM
@DeadMG sorry
How do I delete what I have posted?
 
Click the arrow on the left side of your post and click delete.
 
well, you can't get rid of the previous waste of space, but if you click on the bar to the left of the post when mousing over it, "delete" should come up
 
@FredOverflow Pft, can't find anything. I'm guessing it was a discussion in comments in an unrelated question then.
 
@DeadMG thanks
Anyway, Is my code satisfactory for a simple Event Class?
 
std::vector<boost::function<void(Wdg&)>> events;
done
oh and by the way- www.codereview.stackexchange.com
 
10:24 AM
oh. thanks, I will try codereview.
I didn't know about it.
 
Yeah, function pointers will only go so far. Allowing any kind of callbacks and storing std::function (or the Boost version) is that much more powerful.
 
by "function pointers can only go so far" what he means is
no self-respecting C++ programmer would go anywhere near such a disgusting thing unless he was forced to
 
@FredOverflow Ah I notice Kerrek is remembering the same dicussion! Too bad we can't find it.
 
and paid double his normal hourly rate
 
I don't think I really consider 'respect' when I write code.
@FredOverflow Hah, I have a different point of view: my own implementation of make_unique allows me to pass custom deleters and I consider it a defect that make_shared doesn't support that feature!
 
10:30 AM
Why are function pointers so hated? Do they cause type-safety problems?
 
They're not 'hated'. At least not to my knowledge.
 
I try to avoid boost::function because it takes so long to compile.
What I meant was, why shouldn't they be used?
 
@LucDanton Using anything else besides delete would be wrong for make_unique. Just look at the code, it uses new T. Oh wait, T could be an array type...
 
@IntermediateHacker They're not really hated, just excessively restrictive. Most of us use functors a lot, so something that can't deal with them is kind of useless.
 
I think the idea is that sooner or later one callback will need some state to work properly. Another take is that I simply learned to program with closures before I learned to program with function pointers.
 
10:32 AM
@Jerry Coffin excessively restrictive?
 
@IntermediateHacker Can't be used to point to functors and/or member functions. Pointers to members aren't that big of a loss, but being able to deal with functors is (for me, at least) pretty important.
 
@FredOverflow I forgot to mention that my implementation also accepts 'raw' pointers. So the idea is that make_shared is a degenerate, feature-deficient piece of code ;)
 
@LucDanton Your implementation of make_unique accepts raw pointers? But then it doesn't really make the object, it already exists, right?
 
Right, it makes a unique_ptr.
 
@DeadMG Should I really have used a template class instead of a normal class for implementing the Nex::Event? I am beginning to have second thoughts...
 
10:35 AM
I read the name make_shared as 'make a shared pointer', not 'make a new, shared object'.
I suppose I could have gone with allocate_unique to go with allocate_shared though...
 
@IntermediateHacker They're hated because they're incredibly inflexible
you can only pass a free function to them, which is really bad
 
But that would be a lie: my make_unique works with any kind of pointer, it has nothing to do with allocators.
 
no lambdas, no member functions, no nothing
 
@DeadMG I see. Well, I guess I should use boost after all.
 
Yes, you should.
 
10:38 AM
@FredOverflow I almost made a comment of how your use of std::forward is correct and idiomatic, but I'm too lazy.
 
@DeadMG Anyway, should I have used a template class or a normal class for implementing the Event? Wasn't it better to create A base class called Widget and have used a pointer of that for 'Register()'?
 
no
do not use inheritance, ever, unless you absolutely must
 
@LucDanton If you say make_unique(p), how do you decide whether to contain the p or point to the p in your implementation?
 
always use a template by default
 
@DeadMG Thanks.
 
10:40 AM
@FredOverflow Named parameters. Use is make_unique(raw = whatever_kind_of_pointer), notice no need for explicitly passing a template parameter.
 
@IntermediateHacker template<typename T> class Foo is actually a class template, not a template class.
@LucDanton Oh, I remember having that discussion about named parameters in the chat. I also remember totally not understanding it back then :)
Is raw a global object or something?
 
And now I have a completely reusable named parameter solution that I only use for make_unique! So worth it.
@FredOverflow Yes.
 
@LucDanton And it simply remember that it was being assigned to last?
 
Haha, no, that would be evil.
 
Or it sets a flag that can be queried and set back?
 
10:43 AM
I'd expect some kind of template/overloading trickery
 
Think expression templates: operator= returns a new object wrapping the passed argument.
 
@LucDanton I r the WINRAR
 
I see, so raw = xyz does not actually mutate anything? That's tricky.
 
IIRC something like template<typename T> named_parameter<T> operator=(T&&);
 
Have you published your named parameter scheme somewhere? Never seen it before.
certainly interesting
 
10:45 AM
well, there's a nasty problem with it
 
No, I've been considering publishing my code but I've been shopping around for a build system first.
 
i.e., all named parameter objects must be in the global scope, unless you want to do namespace::raw
 
It's at namespace scope, yes.
 
WHat are the advantages of a "Header Only" implementation [boost,win32++] compared with those of a Static/Dynamic LIbrary implementation [WxWidgets,MFC] ?
 
And yes there is a problem but that's one that appears when doing something like int const N = 42; void f(int const& i); template<typename T> void oops(T) { f(N); }
i.e. it's a grey area of the Standard.
 
10:47 AM
What's the problem?
 
is it me or is this a weird way of declaring a pointer int a*?
 
@IntermediateHacker 1) Templates have to go in headers, 2) You only have to set up paths and such in one place instead of two (one for compiler, another for linker).
 
@TonyTheTiger It's illegal. Won't work. Where did you get that from?
 
oops will (or won't, depending on interpretation) result in an ODR violation if it's a header included in more than one TU.
 
@FredOverflow not even as a function arg?
 
10:48 AM
i.e. there is one N per TU.
 
@TonyTheTiger No, unary operator* is a prefix operator, hence it always goes in front of the operand.
 
@JerryCoffin And the disadvantages? (if any)
 
@IntermediateHacker Can lead to long compile times, possible code bloat.
 
@IntermediateHacker: Name space polution.
True especially for Windows headers.
 
@JerryCoffin Does it make sense to perpetuate the code bloat myth?
 
10:50 AM
@JerryCoffin Ah... now I see why boost takes so long to compile.
 
@TonyTheTiger Could be legal in a function def, as long as a was defined (for example) to const.
 
@LucDanton Isn't code bloat being a myth a myth itself?
 
What would you prefer? A header only imlementation or a library (.a/.dll) one?
 
@LucDanton It's not really a myth, just not nearly as serious and/or common a problem any more.
 
@JerryCoffin lol that would be macro hackery
 
10:51 AM
@FredOverflow What Jerry just said.
 
@JerryCoffin I gues thats why we still aren't using assembly.
 
@Tony please post a link to the text that mentions int a*.
 
@FredOverflow It sure would.
 
@Jerry Coffin
What would you prefer? A header only imlementation or a library (.a/.dll) one?
 
@IntermediateHacker With templates, you have no choice. They have to be header only.
 
10:53 AM
@FredOverflow Thanks, that solves problems.
 
@IntermediateHacker I'm not talking about it simply being more acceptable for programs to be bigger. In this case, it's linkers getting smarter, so code that started out duplicated during compilation gets merged during linking. Early in the history of C++ that didn't happen -- and under the wrong circumstances, it still might not.
 
:1236544 void quicksort(int a*, int left, int right)
{
	if (left < right)
	{
		int pivot = partition(a, left, right);
		quicksort(a, left, pivot-1);
		quicksort(a, pivot+1, right);
	}
}
 
@IntermediateHacker If the code doesn't use templates (or not much), I'd generally prefer a library.
 
@JerryCoffin What if 5 out of 14 classes use templates?
Header Only?
 
@TonyTheTiger Again, this doesn't compile: error: expected ',' or '...' before '*' token.
Also, where did you get this code from?
 
11:03 AM
@IntermediateHacker Hard to say for sure. Clearly the templates need to go in headers. For the rest, it depends on the size of the classes as much as the number. 9 tiny classes might as well just stay in the headers. 9 huge ones could belong in a library. I'd generally time compilation both ways, and see how much difference it made.
 
You also have less binary compatibility problems with headers.
 
@FredOverflow Headers are simpler in general. The main disadvantage is having to re-compile them every time you use them. For some commercial development, keeping the source code secret is a big thing too (or charging extra for it...)
 
How about precompiled headers? Never personally used them, but they sound like a great idea when it comes to performance...
 
They are lifesavers.
I have yet to try Boost.GIL with precompiled headers. Even then, I wouldn't recommend using it without them.
 
@FredOverflow They help, but not necessarily as much as you'd like. They can create huge files that (at least with some compilers) get re-created if you look at the compiler wrong. Can still be really useful though.
 
11:26 AM
0
A: Automatically pick a variable type big enough to hold a specified number

FredOverflowSure, it's possible. Here are the ingredients. Let's start with my two favorite meta-functions: template<unsigned N> struct constant { enum { value = N }; }; template<typename T> struct return_ { typedef T type; }; Then, a meta-function that counts the bits required to sto...

I finally converted to spaceless template<blah> style ;)
 
sbi
@TonyTheTiger Your question is pretty much like my operator overloading FAQ ("What is there to know about topic X?"), and that is indeed stretching SO's Q&A style to its limits and then a bit further. The main difference to mine was that mine was posted with all the facts about its topic in place, neatly organized and sorted, while yours would start to assemble a wild mixture of answers an would require a lot of effort to achieve that level of organization.
So I can, to some extend, understand that yours was closed, even though I'd like to have more of those at SO.
@FredOverflow Except that, when you declare an object, * is a type modifier, not an operator.
@FredOverflow Without looking close, what I'm missing in your answer immediately is CHAR_BITS. Wouldn't that be a necessary ingredient for counting bytes of a number?
 
@sbi for a portable solution, yes
@sbi I was arguing via the C declarator syntax ;)
 
11:45 AM
Hah love the title.
 
sbi
@FredOverflow <confused> Which is why your terminology was wrong, no? </confused>
@FredOverflow I never aim for less than a portable solution. :)
@ÓlafurWaage You're buying a book? A movie?
 
@sbi Since dereferencing a pointer p has the syntax *p, the declaration of the pointer p has to look the same.
 
I've actually been considering the syntax type * integer for declaring arrays
 
@sbi Well, since my solution already uses uint16_t and co, there is an assumption about the byte size, anyway.
 
sbi
@FredOverflow No, it doesn't have to. It does, yes, but there's no need for it to do so.
 
11:50 AM
I think it's hilariously intuitive to suggest that an array of 10 T's should be T * 10
 
@sbi "...unless you use a typedef", okay? :)
 
sbi
@DeadMG If you do so, then I seriously hope your language never takes off.
 
heh
 
sbi
@FredOverflow As I said, I didn't look that closely.
 
nah, I'm going to stick with my previous functional T.Array(10) arr; thing
 
sbi
11:52 AM
@FredOverflow It seems we are misunderstanding each other here. And big time, really.
 
@sbi What was the last language that was developed by a single crazy guy that has taken off? Aren't most languages stillborn?
 
sbi
@FredOverflow Yes, but only 0.001% ever take off, so there's a lot of hope.
 
lol
 
Have you considered a syntax that puts the type after the name of the variable?
 
hey, I hope that DeadMG++ takes off
 
11:53 AM
Like var i: int or something?
 
no
 
too verbose? :)
 
I've already got more than enough
and it would be syntactically ambiguous with function definitions anyway
unless I added back in the var keyword, which I am totally wanting to avoid
 
sbi
@FredOverflow My point is that dereferencing could just as well be a postfix operator, xor the declarator be as @Tony asked. Yes, they inventors of C thought the way it is would be less confusing, but (it's not like it makes a lot of difference and) they could have just disregarded that thought.
 
@FredOverflow What? uint16_t is not 16 octet wide.
 
11:55 AM
The C family's notation for function definitions is one of its greatest sins
except for C++0'x trailing return type notation, which actually gets it right
 
sbi
@DeadMG Then don't create another C derivate and make people using it confuse arrays and pointers. Please, have mercy on us.
 
@sbi I don't have T* as a pointer anyway
 
sbi
@DeadMG Yeah, but C and C++ have.
 
obviously you don't keep up with my blog and thought process because I dropped T* long ago
I changed all type declarators to be type member functions, like int.Pointer()
 
sbi
@DeadMG No, I don't keep up with your thought processes. In fact, I'd be glad if I was able to keep up with my own thought processes...
 
11:56 AM
lol
anyway, I wasn't being particularly serious about T * 10 being an array of 10 T
@jalf I actually had to drop trailing return and go back to the old C-style way
 
sbi
@DeadMG Thanks.
 
just can't make my grammar work otherwise, unless I want to have the most hideous grammar that ever existed
by that I mean the actual grammar implementation
it's possible to make it work in a LALR(1) grammar but not in a particularly easy way
 
@sbi It would indeed be awesome if dereference was a postfix operator.
 
there's a part of me that wants to drop all the operators
 

« first day (300 days earlier)      last day (4650 days later) »