« first day (479 days earlier)      last day (4467 days later) » 

1:00 PM
here it is ideone.com/7BPrM
 
Where's your indentation?
 
Xeo
a = new int;
a = *copy.a; // a == int*, *copy.a == int DOESN'T MATCH
a = new int(*copy.a). There, fixed.
 
@DzekTrek inline means 'ODR dispensation', __forceinline probably has to do with code generation.
 
Xeo
or *a = *copy.a
 
1:02 PM
I want to copy the value of a not the pointer
 
AFAIK, __forceinline is "Can you inline this? Please? Pretty please? Please pretty please with sugar on top?".
 
@LucDanton ODR?
 
Xeo
@RMartinho: Anyways, if you want to "partially specialize" on a template for giggles, I think you need to do something like this: ideone.com/tVLeU
With extra 0 to force the specialization to be preferred, since it would otherwise be ambiguous
I'm not too sure how to get rid of that.
 
type is id, son.
 
Xeo
(The linker error is intended, btw)
@RMartinhoFernandes Oh, yeah. Whatever.
 
1:04 PM
@DzekTrek ODR stands for the 'one-definition rule'. It's a pretty involved bit of standardese (in both the C Standard and the C++ Standard), the gist of it being that any one C++ entity that is not a template can only ever have one definition per TU (for types) or program (for functions). Hence the 'one definition rule'. In some cases one entity can have more than one definition, and inline is used to 'get excused' into those cases.
And the standardese doesn't use the word 'entity' to refer to those things that the ODR apply to. I forgot what the actual term is, perhaps 'names'? Since those have linkage right?
 
Doesn't ring a bell.
 
Xeo
sleeps
For me.
 
I gotta stop using "stuff" as a countable word.
 
I see, so basically if I wanted to define one TU as a float and something else, I would need inline for it?
Is it processed in the assembler level, then?
 
1:10 PM
@DzekTrek Just to be clear, TU means translation unit. I'm not sure I understand what you mean.
 
you can't define an entire TU as a float, lol
 
Like, my program is consisted of many functions that each of them deals with specific type, for instance computeFloat(float a,float b) ... computeDouble(double a, double b) and so on?
It is already written somewhere in the headers to deal with it, right?
 
What is written?
 
@DeadMG in C float; is a valid TU
 
1:15 PM
that still doesn't make the TU semantically equivalent to a float
and how on earth could it possibly be a valid TU?
 
I bet you could get the bits of the file to be a valid float
 
$ g++ --float foo.cpp vs $ g++ --sink foo.cpp
 
code consisted of inlines that deals with building my program corectlY? @LucDanton
 
> cat test.c
float;
> gcc -ansi -Wall -Wextra test.c
test.c:1:1: warning: useless type name in empty declaration
C lets a bunch of crazy stuff like that through that C++ doesn't
 
Uh, what's an inline. I followed you when you mentioned functions. In any case, if that's what you're wondering, (freestanding) functions that you define won't implicitly be declared inline. Member functions get that under certain conditions though.
 
1:17 PM
@awoodland Just for kicks.
 
@RMartinhoFernandes just for grammar simplicity
(I assume)
 
I see, thanks @LucDanton
 
Please note that even using inline isn't a full, 'hands-off' dispensation. There are still restrictions on the (now possibly several) definitions you write for one function.
 
Can you point me where to look for those restrictions? :)
 
The standard?
 
1:21 PM
Standard is a little awkward to me, I can't understand anything from there. ( that was the first place I looked for )
 
It's awkward to everyone except litb
 
Well, instead of remembering an actual SO question/answer, I remembered that Johannes has an answer in his favourites regarding ODR. Far too long for me to see how exhaustive and relevant it is or isn't.
 
Xeo
@Pubby Hey!
 
@Xeo ?
 
@Xeo, thought you were going to bed?
 
Xeo
1:23 PM
I don't find the standard awkward. :(
@TonyTheLion Yeah, I thought so too.
 
excellent, @LucDanton . Many thanks.
 
7 hours ago, by R. Martinho Fernandes
@Xeo We both know you'll still be here in an hour.
 
@DzekTrek You did well to ask me for a more detailed version as what I explained to you glossed over a lot, and I do mean a lot of details. (The kind of details that can lead to UB unfortunately.)
 
Notice the timestamp.
 
@Xeo It must be getting to you then. I suggest reading some well-written prose for a while.
 
1:24 PM
Notably it isn't so much that you can turn off the ODR but you can instead switch to a different version of it... ("You can have several definitions as long as they're all the same, for some meaning of 'same'.")
 
sbi
@Pubby What do you need well-written prose for, when you have this chat?!
 
@LucDanton It was more clear to me than the standard explained. Also,many thanks for this link.
 
@sbi Turns out this chat is one big poem
 
@RMartinhoFernandes lol
 
Xeo
@RMartinhoFernandes Blame @MrAnubis for that, he caused @Pubby to plink me because of my C9 comment. :P
 
1:27 PM
lol
Some people never sleep
 
Sleep is for the weak
 
lol
I'm downloading Andrei's talk
hopefully I can watch it without feeling utterly confused at the end
 
Xeo
@TonyTheLion Andrei went easy.
 
sbi
@Pubby If this chat is a poem, it must be by Charles Bukowski then, judging from the amount of sex that features in it.
 
Xeo
With both variadic templates and static if
 
1:29 PM
static if was fairly easy to understand
 
@Xeo The timestamp says "7 hours ago". I can't blame @MrAnubis for that.
 
Xeo
The poem that this chat is is based on the infinite-monkey-theorem. We're just infinite monkey hacking away, day after day.
@RMartinhoFernandes He initiated a cascade!
 
has anyone read "Modern C++ Design" by Andrei?
 
@TonyTheLion Yes, because "it's an if!"
@TonyTheLion Yes.
 
damn, coding RPGs has made me dizzy.
 
1:30 PM
I'm guessing @Xeo must have read it
@RMartinhoFernandes would you think I'd understand any of it?
I actually have the book, never opened it
 
@TonyTheLion I did.
 
sbi
@TonyTheLion Of course, someone has. I heard it sells well.
 
Xeo
@TonyTheLion I already said I only read 3 programming books till now. :P 2 introductory/reference thingies for C and C++ and then Effective C++
 
Dunno, it starts off easy, but I still have to re-read the multimethods emulation.
 
@Xeo oh I'm sorry I wasn't here when you said it before
I'll wait a bit more
 
sbi
1:31 PM
@TonyTheLion Probably, but I'd suggest you start out with the Josuttis/Vandervoorde one.
 
I should actually get Effective C++ first
 
sbi
@TonyTheLion Definitely. It's the 2nd C++ book one should read.
 
@RMartinhoFernandes Uh, I don't remember that.
 
sbi
I always found multi-methods boring.
 
the "Modern C++ Design" is a bit obsolete in C++11 era
 
1:33 PM
I wonder why I created an astronaut in a field surrounded by walls... I've lost my senses
 
sbi
@Abyx Well, but it does explain the underlying principles, doesn't it? I suppose it aged much better than many other books.
 
let me check it....
 
@LucDanton You don't remember the multimethods emulation? I don't remember it because I know I skipped most of it.
 
Xeo
@RMartinho: I think you're thinking of the wrong iterator. Not istream_iterator but istreambuf_iterator
It'd be very strange if that thing used formatted input
 
@sbi meh I keep putting off buying it
 
1:35 PM
Oh, I didn't notice that. Sorry, will delete my comment as soon I find the question in my history.
 
who changed the tagline?
 
some horny guy.
 
@sbi +1
 
1:36 PM
@RMartinhoFernandes Doesn't ring a bell at all. Welp, I'll use assume he stuffed some std::type_info const* (or some TypeInfo I guess) in a container.
 
Xeo
@TonyTheLion I couldn't resist.
 
can I take a pointer out of my ptr_vector and delete it?
@Xeo oh
 
Xeo
@TonyTheLion No
 
well... functors, smart-pointers, scary TYPE_LIST_42 macro - now we have boost or std replacements for them. IMO the only useful reading there - is the Visitor pattern implementation
 
@RMartinhoFernandes I do :) I never used it because it was too convoluted in practice. I might use it with C++11 implementation though
 
sbi
1:37 PM
12 hours ago, by Xeo
room topic changed to Lounge<C++>: Sorry, I couldn't resist. [c++] [c++11] [c++-faq]
 
@Xeo then I'm screwed aren't I
 
@RMartinhoFernandes one area where I suppose VVTTs will come in handy
 
@sehe That's exactly why I plan to re-read it :)
 
Xeo
@TonyTheLion No wait, you can. If you specify to release it
 
how do I specify to release it?
 
Xeo
1:37 PM
auto* p = pvec.release(index); and set the internel pointer to null
 
@LucDanton Not at all? He used cartesian product of two static typelists
 
Xeo
Provide a method. :P
 
@Abyx Actually there's no std replacements for typelists.
 
@Xeo ah on the vector?
 
@RMartinhoFernandes there is boost.mpl
 
Xeo
1:38 PM
@TonyTheLion Yes
 
What's a VVTT?
 
@RMartinhoFernandes mpl::vector<>
 
template <typename...> struct typelist {}; is simpler.
 
@Pubby shees :) someone ought to make that a sticky star
 
1:38 PM
@sehe Is this about multimethods but somehow not multiple dispatch?
 
Xeo
Jan 3 at 19:10, by Xeo
template<template<class...> class... VVTT> basically
 
wouldn't it be cool if you could write a templated container that can take multiple types? (or is that already possible?)
 
@LucDanton No, mutliple dispatch. If you google it it with 'Modern C++' you'll get google books page previews
 
@RMartinhoFernandes std::tuple perfectly cromulent!
 
@TonyTheLion You mean std::vector<boost::variant<A, B>>?
 
1:39 PM
@RMartinhoFernandes yea
sorta
 
@LucDanton I hate myself for repeatedly forgetting that.
 
Oh, variadic variadic template template?
 
Xeo
Yes
 
but more like you don't have to specify T at instantiation, but just at calling insert
or something
my fantasy is running wild here
 
Xeo
@TonyTheLion You can do that with some void*s, but you won't like it.
 
1:40 PM
@TonyTheLion std::vector<boost::any>?
 
ugh void*
 
Xeo
Since you'll be throwing away all type safety there is.
 
@RMartinhoFernandes I guess that's about as close as it gets
to be type safe or not to be type safe
the ultimate question.
 
Xeo
No, not really.
 
Is boost::ptr_vector<void*> specialized?
 
1:42 PM
I remember when I joined SO boost::any was getting mentioned anytime something even a bit dynamic came up ("what if I don't want to set my function parameters in stone" etc.). Not so much the case these days, is it?
 
Xeo
Hm, I suddenly got an idea how range-based for could work for tuples
 
@Xeo Not very pretty, I assume.
 
Xeo
The compound statement would get transformed into a polymorphic lambda
 
50% off on polymorphic functors.
 
Xeo
1:43 PM
@RMartinhoFernandes Not library based. :P
 
how do you do polymorphic functors?
 
@Xeo I still called it because I need time to transform my sarcasm into ads, okay?
 
Ah, you mean messing with the language?
 
Xeo
@TonyTheLion templated function call operator
@RMartinhoFernandes Yea
 
Xeo
1:44 PM
like
 
Anyway, back there I was trying to say that boost::any wins over void* because it blows up if you miscast, while void* just happily UBs all over your code.
 
that's a valid argument
 
But, but, but, performance!!
 
I enjoyed verbing UB.
 
we prefer to have a blow up over a UB up
 
Xeo
1:47 PM
@RMartinhoFernandes "UBs all over your code" sounds dirty
 
sbi
@LucDanton I never understood why some consider it important that an application crashes fast.
 
@Xeo That was the point.
 
barfing all over your code
sounds about the same
 
@sbi Maybe they can't wait to start up the debugger.
 
DEBUG ALL THE CODE
 
sbi
1:49 PM
@LucDanton The debugger is one of the slowest applications I have used in the last decade.
 
Hence why every nanosecond is important!
 
Is there some way to at runtime find out what type of Derived you have in a class hierarchy?
 
Xeo
dynamic_cast-try all derived classes. :P
 
Or typeid.
 
hmm typeid
 
Xeo
1:52 PM
That's only as a string, though
 
0
Q: Object type detection in hierarchy

dimayakI've got a hierarchy of game objects: class GameObject { public: virtual void update(float dt) = 0; virtual void draw() = 0; }; class Building : public GameObject {} class Sawmill : public Building {} class Human : public GameObject {} and so on. All objects are managed by the game (wh...

 
But both of those are fugly and signs of bad design.
 
for this question about OO masturbation
well, his enum solution for his OO wanking isn't any better
 
Oh, there's some managing going on.
 
lol
it's just rediculous, why do people see a need for these huge inheritance chains
for two virtual functions
you could template the functions to pass in any object
 
1:54 PM
What I find worse is that then he uses RTTI instead of taking advantage of the virtuals.
@TonyTheLion But you can't store more than one type on a vector.
 
Xeo
GCC 4.5.1 doesn't like it, but this is what I had in mind w.r.t. range-based for on tuples: ideone.com/xg61Z
 
@RMartinhoFernandes boost::any
like you said earlier
lol
 
@TonyTheLion But that's not as convenient. You need to do lots of ifs later.
With inheritance you can just call the functions. Less ifs, more power.
 
Xeo
Of course that needs extra support for break and continue.
 
Last time I needed that I went with template <typename... T> some_iterator<boost::variant<T...>> iterable_tuple(std::tuple<T...> t); + static visitor.
 
2:03 PM
@RMartinhoFernandes my code then violates that
I have so many ìf's it's not even real
I suck at design :(
 
Only ifs that test for types are bad.
 
oh, mine don't test for types
mine test other things
 
Xeo
Do your types test for if?
 
Got another messed up notation problem. Anyone know what È is supposed to be? pastebin.com/p3WN3bsv
 
@RMartinhoFernandes you're bad design! O_o
 
2:06 PM
@Xeo wut?
puppy woof
 
@Pubby Can't make head or tails of that one.
Maybe it's one of set union (∪)/set intersection (∩)?
 
@TonyTheLion woof woof
 
Xeo
> EDIT I forgot to mention that I cannot use STL containers (like std::vector or std::list)
 
I have 18 if statements in one function
in one of my classes
meh
 
Xeo
@TonyTheLion That surely is bad?
 
2:08 PM
Ok, at least the function is doing too much.
 
yea, well quite a few check whether std::find returned something
@RMartinhoFernandes I know that, I have to refactor, but I want to get the code fully working before I start splitting it up
I iterate a few containers in that function, where I have to check certain conditions for each element
perhaps I should have used std::for_each
 
@RMartinhoFernandes If it helps I think it's equivilent to this: pastebin.com/njJaKDZJ
 
Hmm, don't know of any symbol that could make that.
 
Actually, it probably is union. Strange as it was rendered correctly earlier on the page.
 
2:13 PM
lol
 
0
Q: Cannot build LLVM and Clang

MetallicPriestI have tried to compile clang and llvm using the clang getting started manaul. However, at step 5, when I do make, I get the following error. Any idea what is going on here, and how to fix it? cp: cannot stat `/home/MetallicPriest/Desktop/build/tools/clang/runtime/compiler-rt/clang_linux/full-x8...

oh noes
this guy again
 
I'm not sure if "failure to build Clang" counts as on-topic here.
Also, doesn't Ubuntu have some package management system for sources?
 
@RMartinhoFernandes yes, apt-get source packagename
but possibly trying to build a newer version?
 
Ah, that doesn't fetch from trunk?
 
@RMartinhoFernandes in this room you mean?
or on SO in general?
 
2:23 PM
@TonyTheLion SO.
 
ah
I need 7 more rep for 12k
 
Well, on-topic or not, it's not a question.
 
Ok, I'm trying to write a release function for my ptr_vector. I'm wondering whether I should first delete the object gotten with at(..) or first erase it from the ptr_vectorusing erase-remove??
template<typename T>
void ptr_vector<T>::release(size_type index)
{
	T* t = vec_.at(index);  //Delete first or erase from vec_ first?

}
 
It think it's irrelevant.
As long as you don't do delete vec.at(index).
No, even then, it's ok.
 
no wasn't planning
I was gonna do delete t; in the above
 
2:30 PM
Erase from your vector first, require that delete t be no-throw. That's a requirement so innocuous you don't have to even document it.
 
if you're comparing pointers to objects, do you need to overload operator== on the object to use it with std::find ?
 
I have so much work, all being held up by other people ¬_¬
 
@TonyTheLion std::find(begin, end, &the_object);
 
@LucDanton my function should be no-throw then?
@LucDanton yes but I'm looking a vector of pointers
 
Unless you want to compare values. Then you'd need a function object to dereference the elements.
 
2:32 PM
Stupid time zones
 
oh, sorry, got confused
 
@TonyTheLion Well, no. But as a consequence from that requirement it ends up like that.
 
huh?
but how else would you require delete t to be no throw?
 
It doesn't have to appear in code.
 
oh, so it's just no throw anyways
 
2:34 PM
The overload of std::sort that accepts an arbitrary functor requires that this functor follows some strict requirements.
But that's not documented in the code.
 
Similarly for your container of T, you put some requirements on T so that the container makes sense. This can be one of them.
 
I always assume destructors don't throw. I don't care if your code breaks when used in my code because of that.
 
And really I don't even know what happens if a destructor throws in delete t; lol.
 
You don't?
 
2:37 PM
Nope.
 
Usually, it just throws. Sometimes it std::terminates.
 
That's just inconvenient. Who's gonna take responsibility for that memory.
 
does this look correct?
 
sbi
@thecoshman It could be worse. The others could have so much work to do, all held up by you. <insert lousy shirt saying here.>
 
@TonyTheLion No.
 
2:44 PM
but why?
 
@sbi :O
maybe they are held up by me and not willing to make a fuss
 
I knew something was wrong, my gut feeling told me
 
Can you check that after a call to this member, the internal vector is empty?
 
sbi
@TonyTheLion If you delete first, and this fails (which it shouldn't, but indulge me), then you end up with a potentially stray pointer in your container. If you erase from the container first, and this fails, then at worst you have leaked and object. Seems a straight-forward decision to me.
 
2:46 PM
so delete first?
 
@sbi Which is: do as you please and let those that throw from destructors pay the price.
 
@TonyTheLion remove pointer first then delete is what sbi is saying
 
right, that's what I did, see here: ideone.com/vsWb1
I was asking if anything was wrong with it?
 
IIRC you really should try to avoid having destructors that can throw errors. I know some times shit happens, but you should aim to avoid it
 
What did you try to express with the calls to the Standard algorithms?
 
2:48 PM
remove from container
if it's a certain element, matching to T
 
Right. remove seems more appropriate than remove_if in this case.
 
oh, so my template remove_elements is also no longer applicable
 
You could however miss some elements in cases of multiple inheritance... (Or could you?)
 
vec_.erase(std::remove(vec_.begin(), vec_.end(), T), vec_.end());
like so
 
This will remove all elements with the same value as t.
 
2:51 PM
oh it should be t
 
sbi
@TonyTheLion I am struggling to understand this algorithm. So you pass in an index, the algorithm takes the pointer at that index, and the goes to remove all occurrences of said pointer? Either I'm missing something or this is odd behavior for a release() member function.
 
I'm trying to remove an element at given index
since it's a ptr_vector, the element will be a pointer
 
Just that one element?
 
An element is not the same as a value.
 
sbi
2:52 PM
@TonyTheLion But that's not what the algorithm does. Or is this one of those days where I should have a coffee?
 
I don't know
I'm confused :(
 
Let's forget about pointers altogether and let's take std::vector<int> a { 3, 3, 3 }; for an instant.
Removing element 0 means you end up with { 3, 3 }.
 
Removing the value of element 0 means you end up with {}.
 
2:53 PM
ok
no, I want to do the first thing you said
 
There's an overload of erase for that I think, isn't there?
vec_.erase(vec_.begin() + index);
 
@TonyTheLion so you have a vector or pointers, and want to have the remove(int index) to delete to object and then remove the pointer?
 
Doesn't do the same bounds checking as using at though.
 
@thecoshman yes
 
Wait, if you have duplicate pointers in the vector, and the vector owns them, that sounds like a recipe for disaster.
 
sbi
2:54 PM
@TonyTheLion What's wrong with this:
template<typename T>
void ptr_vector<T>::release(size_type index)
{
    T* t = vec_[index]; // why at()?
    delete t;
    vec_.erase(vec_.begin() + index);
}
 
@LucDanton feel safer using at
 
but you want to use existing STL as much as possible
 
@sbi because it can't go out of bounds
 
@TonyTheLion Add your own bounds checking and there you go.
 
@RMartinhoFernandes unlikely
what's wrong with at() ?
 
2:55 PM
Stuffs.
 
lol
ok, afk for a bit. gotto do something entirely different
 
If the user doesn't want to pay the cost of bounds checking (e.g. because it can statically prove the index is correct, or because the checking was already done) then your interface can't help.
If on the other hand you provide an interface that doesn't do bounds checking for release, the caller/user can still manually check if that is needed.
 
sbi
@TonyTheLion If I call std::vector<T>.erase() with a stray iterator, it blows up into my face, but it does so fast. If I want to trade fault tolerance for speed, I can always insert a check myself, before calling erase(). In your implementation, employing at() takes the ability away from to decide for myself whether I want to have speed of fault tolerance. I'd resent that.
 
@sbi Wait, what about this?
1 hour ago, by sbi
@LucDanton I never understood why some consider it important that an application crashes fast.
 
sbi
@LucDanton Darn. I write a whole paragraph explaining the issue, only to discover someone else had already done so after I post it. :(
@RMartinhoFernandes It's no accident that I used the same phrase, I remembered that well. Give me a sec, I'm a slow typer.
 

« first day (479 days earlier)      last day (4467 days later) »