« first day (733 days earlier)      last day (4218 days later) » 

12:00 AM
Haskell, that is
 
@Rapptz I have only written one game. It was in Java using OpenGL and voxels.
@Pubby A few months, but I can already do most things. Haven’t had any problems lately. The documentation is wonderful.
I have experience with the type system, monads, arrows, ØMQ, I/O, data structures, byte-strings and FFI (I’ve used Haskell in a Cocoa application).
 
Well, good luck
Post the results if you get anything working
 
Thanks and okay. :P
 
12:23 AM
@DeadMG Haha, I knew you'd come around :P But yeah, if you can write code transforms you can make it as a library.
@TonyTheLion I don't like it. As is, it stands as a curio. It doesn't show anything useful you can do with it. In fact, it goes on to say it's not useful in the end.
I think I can turn part II of the description of my optimal tuple into an example of useful TMP, though.
That's actually a neat idea.
 
I’m going to sleep. It’s 2 AM and I have to wake up at 9.
Später.
 
@DeadMG What are you tutorials encoded in?
Firefox is detecting them as UTF-8, but they're not.
It's kind of... funny when your pages about Unicode don't render properly :P
Hmm, it's not latin-1 nor cp1252. Maybe it's actually just mojibake.
 
1:16 AM
@R.MartinhoFernandes I have a feeling they're puppy-1337
 
So many things to ready and study for my web exam on friday (Scala, HTML5, CSS, JS)
 
1:39 AM
Woot, 200 bronze badges.
 
1:52 AM
Damn, 121 Nice Answer badges...
 
Thats 120 more than me :P
 
Hello, I have a bunch of template classes that I will need to instantiate from other class. Ideally I would like to store references to their constructors (all parameter-less) as a vector of std::function. Is that doable?
how to handle their memory allocation without having to have their type info?
 
No, you can't refer directly to constructors.
You need to wrap their construction in lambdas/functions/function objects/whatever floats your boat.
And you may want to use placement new.
But are you sure you need references to the constructors?
 
so the only alternative (that comes to my mind) is to have these template classes have private static methods that create instances of themselves and return a pointer to *this and reference those methods instead as std::function-s?
I don't nessesarly need the constructor itself, what I need to do is to create instances of these classes without storing them in long tuples.
(my compiles doesn't support variadic templates yet and the variadic limit is 10 :( )
 
No just create a lambda that calls the constructor and returns the object
 
2:04 AM
@KarimAgha If I needed that, I'd use something like this: template <typename T> T* construct(void* storage) { return ::new(storage) T(); };
 
@R.MartinhoFernandes yeah, this is what I was thinking about. I just thought that there might be a less intrusive way of doing it.
 
But that requires extra care.
 
@R.MartinhoFernandes, could you please elaborate?
 
But this is really weird.
@KarimAgha You need to destroy them manually too.
 
I would store tuples in a vector of their constructors and destructors.
 
2:06 AM
And since those construction functions all have different signatures, you can't store them in a vector with type erasure somewhere.
Unless they all inherit from the same base.
 
> Java: Implementing a Stack using Queues
???
 
Sounds like an interview question.
 
It's homework apparently
 
I'll just throw that out there, make your lambda return a unique/shared ptr to the new object. if you pass that around instead of the actual pointer, destruction will be taken care of automatically.
 
Hmm, use the queues as cons cells would probably work
Except that's just silly
 
2:09 AM
I don't know the rest of the requirements, but I'd just write a stack of queues of one element.
 
@R.MartinhoFernandes they do. They have a common template class parent.
all of them inherit from template <typename Derived> class Base;
 
Ah, that's not a common base.
That's a separate base for each.
 
true, but that separate base could expose a static method that looks somehow like: void* construct() { new Base<Derived>(); }
right?
and it will preserve type info during compile time for that invocation.
correct me please if I'm wrong.
 
And how do you destroy them afterwards now that you deleted the type?
 
void destruct(void* ptr) { delete static_cast<Base<Derived>>(ptr); }
and pass that constructor.
but this is less of a concern, because the whole idea of this system is that classes need to be instanciated only once and they take care of their own lifetime and destroy themselves when they feel like their time has come.
 
2:14 AM
Erm, they are in a vector of void*. How do you know that the first element is a Base<foo> and the second is a Base<bar> ?
 
so all I really need to to construct them once and forget.
 
Isnt it a bad idea to destroy an object through it's Base destructor?
 
Still, how do you know the first element is a foo and the second is a bar?
 
but to answer your question first, assuming that I want to be able to destruct them, I would store a tuple of (constructor, destructor, actual pointer)
 
@Borgleader If it's not virtual, yes.
I mean, there's nothing you can do with a vector<void*> without the type information.
You can't erase it and lose it.
 
2:15 AM
no no no, it would be vector<tuple<constructor, destructor, void*>>
 
I have a feeling there's a simpler solution
 
and then I would do std::get<1>(v[0])(std::get<2>(v[0]));
 
but I have a different problem.
 
You don't need to store the constructor anyway.
 
2:17 AM
true, true, but here is the crux of my real problem:
the class that is responsible for instanciating those templates is a class that handles operators (say you have SpecialTypeOfClass >> SpecialTypeOfclass) that denote communication paths, and the class that handles that operator (and will be responsible for spawning both types involved in the parameters
will need to know somehow that a certain class was already used before in an earlier operator operation, so that it won't instantiate it twice.
 
I still fail to see how you can make use of that void* for anything.
 
and here, the only thing that I can think of is keeping track of "visited" types in a long tuple and checking for existance before adding again.
but my compiler does not support that yet.
 
If you only keep the destructor, all you can do with it is destroy it.
 
well.. in my scenario I do not need to store void* because I do not need to destruct them, but to answer your question, let me show you a piece of code that I wrote a while ago that did that.
sec.
 
Not sure if that makes sense but I would have each template have a different name (just generate one) they could all register to a class. each of them would have a destruction function and you could call that with a pointer to that object.
 
2:23 AM
(please excuse the comment I forgot on line 6 :))
and this works.
I've verified that and I have tests that verify that too.
 
and this destrctr_ is called from within other type's destructor.
as a form of automatic resources cleanup.
but, that's not what I'm strugling with...
 
Ok, so what is it you want to store?
 
if there would be something like a hashcode for a type, available during compile-time that would be great.
 
I really doubt you want to store constructors.
 
2:25 AM
no, I don't :)
 
Then what is actually the problem?
 
welll.. I do, but only statuc functions that would create these objects - which means that I want to have pointers to a static function of the base template that does { new Base<Derived>; }
but, how can I identify duplicate types?
same Base<> with different template arguments and make sure that each is instanciated only once.
?
 
Ah, that's what I was saying earlier: void* doesn't work because you have no idea what the type of it is.
You need a common base, or something like Boost.Any.
 
exactly. That is why I'm struggling.
I thought about this, but this is not deterministic or reliable:
 
Anyone know what stuff like this is in g++ preprocessor output?
# 5 "path" 2 9 5
 
2:28 AM
to write a small metafunction, that would run at compile time and calculate a hash for a type, i.e say sizeof(derived::trait1) + sizeof(derived::trait2) + ...
but there is high potential for collisions in here.
 
@Pubby Source location data for error messages?
 
and then first check of I have this hashcode in a collection before adding a reference to the static constructing method.
 
@R.MartinhoFernandes That's a possiblity
 
but are you aware of something more reliable?
 
A common base or Boost.Any.
 
2:30 AM
Argh, I hate dealing with Boost.PP :(
 
untemplated base you mean?
 
Yes.
Then you can use typeid or something (make the base's destructor virtual so that RTTI works).
 
I've considered that, but I'm still trying to avoid that for now. I have one hack in mind but I would like to ask you first if it is not conceptually wrong:

to have the templated base have a static method that does nothing with noinline modifier. This static method would be part of a traits class, so it could be easily found, then every template instance will get it's own version of that static class, compiled under different address.
and use that address as type's identity?
give me a second - I'll show you code.
 
@R.MartinhoFernandes: Sorry for asking but... what is the R for in R.MartinhoFernandes?
 
@KarimAgha Do you realize you're reinventing RTTI (what you're doing there is not much different from a vptr)?
 
2:33 AM
RTTI carries runtime overhead, I want to avoid it.
 
What you're doing carries runtime overhead as well!
 
yes, but with this runtime overhead, I'm exactly aware of type's layout and the overhead is only compile-time.
 
R. Daneel Olivaw is a fictional robot created by Isaac Asimov. The "R" initial in his name stands for "robot," a naming convention in Asimov's future society. Olivaw appears in Asimov's Robot and Foundation series, most notably in the novels The Caves of Steel, The Naked Sun, The Robots of Dawn, Robots and Empire, Prelude to Foundation, Forward the Foundation, Foundation and Earth. Since he also appears in all of the books of the Second Foundation Trilogy, Daneel is the most commonly appearing Asimov character. He was constructed immediately prior to the age of the Settlers, and lived at ...
@KarimAgha If the overhead is only compile-time, it won't work.
 
Ohhhh I see.
 
Read your problem description again: you want to identify the types at runtime.
 
2:34 AM
But this is all I need: compile-time type uniqueness.
 
You can't possibly do this with no runtime overhead.
@KarimAgha That makes no sense. Types at compile-time are always unique.
 
no no no! It must be a problem with my english skills. Let me illustrate my idea with a language that I'm more proficient in, C++. Give me a sec ;)
 
Hm, I got on front page of /r/programming, wasn't expecting that!
 
@Pubby Oh cool.
 
It isn't that hard to get on the front page of /r/programming anymore actually.
 
2:38 AM
@Pubby What article?
 
Considering there's one with a score of 0 there right now :|
 
51 is pretty good for a blog. nice!
 
@Rapptz lol
@Mysticial Hmm, it's at 46 here.
 
@R.MartinhoFernandes They randomize it to prevent gaming.
 
2:40 AM
46 here.
 
@Mysticial Only votes, not the actual scores.
 
I see 51 but my link karma is only 45
 
SO and Hacker News has 100% accurate vote counts.
 
No the entire thing is fuzzed. It's pretty retarded.
 
@Rapptz That's not what they say in the docs.
 
2:41 AM
Karma on reddit is even more meaningless than rep on SO
 
I wonder if r/programming blocked SO links. It's been a while since I've seen any SO submissions.
 
You can't block domains as a moderator.
 
But it seems the front page has a different count than the comments page.
 
@Rapptz That's good to know.
 
Not sure if trolling, but someone just tried to tell me that AnythingManager is a reasonable name for a container of game entities, because game entities are "anythings".
 
2:42 AM
@R.MartinhoFernandes ideone.com/8v8wS
 
@Rapptz Are hellbans done on per-account? Or per-subreddit?
 
Per account. Only admins can shadowban.
 
here, the static method's address (unique to every template instance) will be used as type's identity
 
@Mysticial Aren't hellbans silly on a site that is publicly viewable?
 
what do you think?
 
2:43 AM
@R.MartinhoFernandes Yes it is.
 
(Handle should be static.)
 
@R.MartinhoFernandes A shadowban makes your page 404 for others except yourself. You'd be talking to yourself the entire time.
 
good evening :)
 
@R.MartinhoFernandes Also the docs haven't been updated in a long time. Everything is fuzzed
 
is it always the case that each template instntiation will have Construct at a unique address (constant to it's template type)?
 
2:45 AM
ooh, wrong link.
 
@Rapptz Erm, that only shows that votes are fuzzed.
@Rapptz Still sounds silly for reddit, where accounts are more disposable than toilet paper.
 
I probably won't find a comment in a while but every 3 hours the score drops down around the 3k mark.
For example, the Barack Obama AMA had about 25k+ total score but after 3 hours it went down to 12k then 8k to 3k
 
Here is a version without typos: ideone.com/g5C97
 
@KarimAgha So what identifies the type of an object in that?
 
the addtess of Construct() static method
it should not be a set, but rather a map
 
2:47 AM
What would the code that does that identification look like?
 
map of &Construct <---> std::function that calls that construct
it would make sure that even if a type is involved in a certain operator more than once, it will have only one instance constructd.
*constructed.
 
The whole thing still seems awfully convoluted and wrong.
@KarimAgha I still feel I don't understand the problem. The way to do that is to make constructors private and provide a lazy instantiation factory (what is commonly known as a singleton).
 
ok, here is a scenario:

Base<T1>::Handle() >> Base<T2>::Handle();
then
Base<T2>::Handle() >> Base<T3>::handle;

YetAnotherClassThatHandlesCreation::RunTheShow();
I want each of Base<T 1..3> to be isntanciated exactly once, and avoid Base<T2>'s double instantiation.
so here, for each of these classes, the compiler will generate a different Construct() implamentation, under different address. Correct?
if that is the case, then my problem is solved - I can just use that address to have compile-time type identity.
 
You don't need "compile-time identity" for anything.
At compile-time, a type's name is its own identifier.
 
and how I would store a reference to this instance?
what if I have Base<T6> that wasn't used in any operator and I don't want it to be instanciated?
 
2:53 AM
@KarimAgha How are you currently storing it? The code you've shown is not storing it.
 
it is. It is storing references to individual Construct static methods in form of std::function<void(void)>
 
(line 30: (*it)(); nothing gets stored)
@KarimAgha You don't need to store references to the constructors for anything.
 
see line 22 and 23
 
The get() function in my code sample will create a new instance if none exists, or return the existing one if it exists.
Isn't that what you want?
 
but in your example everything that derives from template <typename Derived> class Base; will have automatically an instance created, right?
 
2:55 AM
@KarimAgha No.
The instance is created when the get() function is first called.
 
hmm, let me take a look at your code one more time ;-)
yeah! Sorry. I missed one thing in what I was describing - let me correct it:
I do not want any of these classes to be instantiated untill all >> operators are invoked. Think of these operators as a way to define a communication network between types.
now, I want these types to be instantiated only when the whole network topology is already known, rather than when it is still being formed.
 
Ok, now that explains a lot.
 
yup - so going back to the initial question: is there any guarantee in the standard that says that each of the static Construct() methods will have: 1) a different address for each template instance and 2) have the same address across all template instances of the same type? Which would qualify it for being a type identity?
 
Reading your code in light of this information, it makes sense now. I'm not sure if function addresses are guaranteed unique (I believe compilers can fold them into one if they end up with the same generated code), but even if that were not the case, you could use a static member instead.
 
hmm.. so if there is a slight possibility that the compiler might optimize these methods and merge some of them, then is there any other thing that would give me these two properties?
like a static member variable for that type or something like that?
 
3:07 AM
Yes.
 
what is that?
 
I mean, yes, a static member variable works.
 
so if I have:
typedef int typeA;
typedef int TypeB;

(&Base<typeA>::member != &Base<typeB>::member) <-- does this property always hold true in all instances?
 
Well, in that particular example, no, because typedefs don't produce different types.
But &Base<int>::member != &Base<double>::member would hold.
 
3:09 AM
So I can't use tag structs..
yeah, it makes sense.
 
How so?
If the tags are all distinct, like struct a; struct b; struct c; it works.
If you use typedefs, no.
 
struct tagA {};
struct tagB {};

the compiler might notice that they both have the exact layout and might optimize and compress them into one static method shared across all instances of that template?
 
No. That's what I said above: a type's name is its own compile-time identity.
 
well.. then this solved my problem.
 
Those two are different types, and the compiler must make two different objects for those static member variables.
 
3:11 AM
awesome, I'll let you know in 30 minutes how it works.
The more I dig deep into C++ the more beauty i find in it. I think that it is THE ultimate programming language.
And the cool thing about it is that you never reach that level, where you know everything about it, there is always something that could surprise you.
 
It's just sad that it is such a big mess.
 
Other languages are messy too.
What would you remove from C++ to contain it's mess?
 
Large chunks of C.
Especially the syntax.
 
Sometimes they're useful when you need to hack something.
 
Pointers also need to go. They are a hybrid abomination of "buffer" and "reference" and "iterator".
 
3:23 AM
and sometimes hacking is inevidable.
I disagree. Pointers are great.
if used correctly.
 
@KarimAgha Just a few that occur to me immediately: 1) implicit, narrowing conversions. 2) declaration syntax (make it more like Pascal). 3) array->pointer decay. 4) any implicit mixture of signed/unsigned in expressions.
 
@KarimAgha They'd be even greater if you didn't need to add the caveat "if used correctly".
@JerryCoffin Yep, all of those inherited from C.
 
array->pointer decay ?
why?
 
@R.MartinhoFernandes Yup. There are a few things unique to C++ that I'd change too though. Just for one obvious one, this should be a reference, not a pointer.
 
I'd guess because it happens implicitly.
 
3:26 AM
if you need to keep track of array's metadata you can always pack it in a structure that would hold its size, dimensions, etc.. - and give the the overhead that other languages impose on arrays without giving you real choice
 
Array decay is not really necessary (&a[0]) and it causes trouble because it's implicit, so it should go.
 
@JerryCoffin if this was a pointer, then it would be really hard to write any memory allocator for C++
 
What?
this already is a pointer.
 
sorry, if it was a reference*
 
I fail to see why.
 
3:27 AM
@KarimAgha Being able to do it is fine. Having to take strange steps (e.g., embed an array in a struct) to prevent is is a whole different story. The point of C++ (and C) is that it should do exactly what it's told, not try to second-guess you.
 
because references cannot be uninitialized - when you allocate memory for a type, you begin with an uninitialized value that you assign to a chunk of memory that is reserved for its use.
 
If you want second guessing, that's what PHP and Perl are for.
 
@KarimAgha Simply untrue. Yes, in (extremely) early C++, you could (and did) get the equivalent of placement new by modifying this in the ctor. That's been obsolete for a couple of decades though.
 
@KarimAgha You don't do anything with this in an allocator (well, you do, to access the allocator's own members). this is never uninitialized.
It never changes value, it is never null.
 
@JerryCoffin & @R.MartinhoFernandes: but isn't any memory allocation function based only on address&size?
why would it need to know anything more than that?
 
3:30 AM
@KarimAgha And this is irrelevant for that.
buffer allocate(int size);
 
@KarimAgha this already acts like a reference in all but syntax. I.e., it's a T *const, meaning it has to be initialized just like a reference. The sole reason it's not a reference is that it was added to the language before references were (i.e., historical accident, not necessity). Stroustrup says this fairly directly in The Design and Evolution of C++.
 
It is relevant. after "delete this;" a reference wouldn't tell if it is still existing.
this is a bad example, I know
 
A pointer doesn't either.
 
hmm..
 
Do you think this changes value after that?
It doesn't. this stops making sense after that. Using it has undefined behaviour.
 
3:32 AM
(this is why its taking me a bit longer to respond - I'm checking the standard :) )
 
@KarimAgha Neither does a pointer. The only thing you can do to pointer after deleteing it is assign a new value to it -- but in the case of this, you can't do that either (because it's const). Attempting to read a pointer after delete gives UB.
 
ya!
swapping two instances
 
nope - bad example again: this is const.
 
std::swap uses references and works fine.
 
3:34 AM
I think I should just focus on getting my code to compile now, I'm starting to talk nonsense.
 
@KarimAgha Probably good advice for all of us, come to that.
 
4:02 AM
http://www.rohitab.com/discuss/topic/39298-wipe-file-impossubru-to-recover/
If you don't mind my asking, anyone have bulletproof argument to counter what he just said? I have a few in mind but I'm not entirely sure the argumentation will be bulletproof.
 
4:17 AM
@Borgleader Because you don't need to dynamically allocate something that 1) you know the size of at compile time and 2) is small enough to lie on the stack. Plus, going with dynamic allocation and raw pointers messes up exception safety.
If he's going for dynamic allocation, at least, use vector, not malloc.
 
Ahh yes thank you :) That's what I suggested but those are really good reasons
 
While it's true that it's a C question, the user seems to be using MSVC, which is not a C compiler, so might as well use C++ facilities.
But that's another problem altogether.
 
Well the question is tagged C++
which was the basis of my argumentation, why use malloc/free/memset when working c++
 
Then, his answer is wrong simply for using malloc.
I would have downovoted this shit on SO.
If he whines, send him here, we'll deal with it.
 
Hehe will do
 
4:19 AM
lol, he says you don't know how to handle it.
 
@R.MartinhoFernandes That's an interesting point. My view on the subject is that someone who knows how to handle dynamic memory allocation actually stops using it directly.
 
i.e. those who use malloc, free, new and delete are those who don't get it.
 
I have no appreciation for people that can't fucking build abstractions.
 
Yeah, it's good to know how to use it, but really, don't use it.
 
4:22 AM
If you don't want to use vector for whatever meaningless excuse you can come up with, that still don't justify doing it manually.
 
@Borgleader Hey, it's that Day9 speed drawing thing.
@R.MartinhoFernandes The guy really does look like a C programmer, though.
 
Yes :) The caricature from Joey Judkins
 
So many people claim they know C++ simply because they put .cpp extensions to their C files.
 
It's a choice between using vector or writing vector yourself. Not between using vector or handling memory by hand.
 
I got a Day9 shirt thinking I could get chicks with it, but I only seem to attract male engineers.
And I dislike engineers.
@R.MartinhoFernandes We all agree on the same thing.
Come to think of it, @Borgleader, simply link a message here and tell him to start reading.
(I could make a discussion, but fuck it)
 
4:25 AM
I'll do if he whines after my answer. I think I made a convincing point. Thanks for the suggestions :)
 
@Borgleader He's right on one point though: dynamic allocation is not the root of all evil. Manual memory management is.
 
Linking people here to discussions about why they suck always seems rude
If you want to argue with someone then reply on the website they use
 
It is rude.
Still acceptable.
 
Now I'm off to bed. Gotta wake up early tomorrow to study for my test on friday.
cya
 
Well if your intention is to get him to understand why manual memory is bad then you're better off not being rude
 
4:28 AM
He already sounds like an arrogant twat.
But I'm always quick to judge when I'm tired.
I should go to sleep.
 
@Borgleader Oh, your name is "Borg Leader". I was thinking it was French and reading it as "Borg-lee-doir" or something along those lines.
(that's probably a butchery of french pronunciation)
 
Borgue li dé.
 
3
Q: How to avoid a "template template template" template in c++

soxxI have tried to implement a "template template template" - template class to fullfill my needs ( I am quite new in using template metaprogramming). Unfortunately, I have found the following topic too late: Template Template Parameters Nevertheless, I need to implement something like listed belo...

:)
 
5:15 AM
@EtiennedeMartel Yes -- all the other arguments may be open to at least some counter-arguments. Exception safety is a whole different story though. If you use dynamic allocation, your only choices are to wrap it in a try block, or use an RAII class. Without one of those, an exception will leak memory.
Dijkstra covered the rest quite well: "The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague." To summarize how that applies to this case: RAII FTW!
 
5:37 AM
posted on October 18, 2012

If the program is broken, how can one ever be confident in any assessment of what it did?

 
0
Q: Can anyone plz help me out writing the code

Shaistha FarheenHello can any one help me in writing the code....i have created a table in sql and the table name is invoice..here is the table . create table invoice(Invoice_Id int identity primary key,quantity int,unitprice int); and i have two dropdownlist and one textbox in my webdesign....all i want to do i...

^^ lolz
 
@Mysticial On meta no less. Maybe if he asked here he'd get more help! [sure we'd help him -- just not with the code!]
 

« first day (733 days earlier)      last day (4218 days later) »