« first day (200 days earlier)      last day (4740 days later) » 

7:00 PM
I wished I had a better answer.... like I was converting legacy COBOL code into C++ routines....
 
Spot the mistake:

template<class T>
void InvokeMethod(T * inObject, void (T::*inMethod)(int))
{
inObject->inMethod(1);
}
I always forget how to write a pointer to member function..
 
sbi
@MartinhoFernandes Sorry, that's another one of those things I got used to in Usenet. It comes from the time AOL suddenly provided Usenet access to its millions of customer, who broke over the groups like a tsunami. (Look up "eternal September" for more on that.) One of the things they brought with them were the many "me, too!" postings (which SO took precautions to prevent), which became so proverbial that nowadays "AOL" stands for "me, too!".
@StackedCrooked Wouldn't that have to be inObject->*inMethod(1)?
 
@StackedCrooked, inObject->*inMethod(1);
 
sbi
@AProgrammer I was faster! :)
 
@sbi : I keep forgetting this meme.... it's so hard to remember.
 
7:05 PM
@sbi @AProgrammer:

#include <iostream>

template<class T>
void InvokeMethod(T * inObject, void (T::*inMethod)(int))
{
inObject->*inMethod(1);
}
struct Test
{
void PrintInt(int inValue) { std::cout << inValue << std::endl; }
};

int main()
{
Test test;
InvokeMethod(test, &Test::PrintInt);
return 0;
}
I get the compiler error: main.cpp|16| error: no matching function for call to ‘InvokeMethod(Test&, void (Test::*)(int))’
 
sbi
@StackedCrooked &test
 
@sbi How silly of me :)
 
I don't understand the concept (T::*inMethod)(int).... is this a function pointer?
 
sbi
@Xaade Member function pointer.
@Xaade: You need a C++ book.
 
It still doesn't work:

template<class T>
void InvokeMethod(T * inObject, void (T::*inMethod)(int))
{
inObject->(*inMethod)(1);
}
|| main.cpp: In function ‘void InvokeMethod(T*, void (T::*)(int))’:
main.cpp|6| error: expected unqualified-id before ‘(’ token
 
sbi
7:07 PM
@StackedCrooked inObject->*inMethod(1)
 
it's a function pointer to the member method in class T defined as:
class T { void inMethod(int); };
 
@sbi That results in:
main.cpp|7| error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘inMethod (...)’
 
@sbi : I have one..... for the life of me, I can't wrap my head around templates.... and I haven't had much use for function pointers.
 
@StackedCrooked You can't include the left parenthesis -- "->*" is a single token.
 
sbi
@Xaade Yeah, only that T is a formal template parameter, and not an actual class, and the same goes for the method name. So both the type name and the method name can be anything.
 
7:09 PM
#include <iostream>

template<class T>
void InvokeMethod(T * inObject, void (T::*inMethod)(int))
{
inObject->*inMethod(1);
}

struct Test
{
void PrintInt(int inValue) { std::cout << inValue << std::endl; }
};

int main()
{
Test test;
InvokeMethod(&test, &Test::PrintInt);
return 0;
}

|| g++ -o test main.cpp
|| main.cpp: In function ‘void InvokeMethod(T*, void (T::*)(int)) [with T = Test]’:
main.cpp|18| instantiated from here
main.cpp|7| error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘inMethod (...)’
 
@StackedCrooked (inObject->*inMethod)(1) AFAIR.
 
@CatPlusPlus YES!
 
sbi
@StackedCrooked ideone.com/UrLj3
@CatPlusPlus Ah, this time you were faster. :)
@Xaade Well, function pointers are rarely used (except when you use the STL to do FP), but templates you should get used to.
 
What would be a practical scenario for templates?
Can you create templates that support polymorphism?
 
sbi
@Xaade A practical scenario for templates? Are you kidding? Don't you use the std lib? It's 90% templates.
 
7:13 PM
Template being a kind of polymorphism, I'm wondering what you mean...
 
@sbi : Fine, I get it, containers are a good use for templates....
 
c++ was always a meta programming language - c++ classes were templates that generated c functions that worked on structs.
c++ templates take this code generation a step further
 
sbi
@Xaade And algorithms.
 
But what if I want a CArray, of objects created from templates. But I want one loop to operate on the array. They'd have to be polymorphic.
 
My goal was to test if overloading by function pointer function argument works. Apparently it does:

template<class T> void TestMethod(T * inObject, void (T::*inMethod)(int)) {
(inObject->*inMethod)(1000); // test random value
}

template<class T> void TestMethod(T * inObject, void (T::*inMethod)(const std::string &)) {
(inObject->*inMethod)("1.2.3.4"); // test random values
}

struct Server {
void setPort(int) {}
void setIP(const std::string &) {}
};

int main() {
Server server;
TestMethod(&server, &Server::setPort);
 
7:16 PM
@Xaade hmm? Templates, pretty much by definition, are polymorphic
 
sbi
@StackedCrooked Please indent this mess.
 
just not in the narrow run-time OOP sense
 
@sbi it was indented, when I edit the message the indent is there
 
sbi
@StackedCrooked Read the newbie hints for how post code here.
 
@sbi I did.
 
7:18 PM
one cute use for templates that oop programmers discover first - is the inside out class - or curiously recurring template pattern.
 
@Xaade could use an array of boost::variant's. Personally, though, I'd just accept that not every language feature can be used to solve every problem equally well. Which is why most languages have more than one feature
 
@jalf : Ok, got that.... but can you have a template.... create two "classes" from it, then pass both classes through the same argument in a method?
 
@sbi Don't ask me to memorize every line of it.
 
ie.e use templates to implement virtual methods, without using virtual
 
@StackedCrooked I think the entire message must be indented, and your first line is most likely not. :P
 
sbi
7:18 PM
<sigh/> Use the "fixed font" button.
 
@ChrisBecke If you want virtual, use virtual. That's what it was designed for. Templates are not virtual.
 
@Xaade yes. But you can't store them both into a single array, without trickery such as boost::variant
 
Those stars burn out so fast.
 
@sbi Thanks.
 
sbi
@Xaade Two ways: Either make the method a template, too, or make the class template derive from a common base.
 
7:20 PM
@FredOverflow virtual has a runtime cost that the template method neatly avoids
 
@sbi and in the latter case, watch out for slicing, of course
 
@ChrisBecke But templates are not a substitute for virtual.
 
@sbi : Gotcha... the latter is what I was looking for.
 
sbi
@jalf Yeah, but that's not template-specific.
 
I saw that.
 
7:21 PM
@sbi fair point
 
@FredOverflow they are far more than that sure.
 
@FredOverflow : That's what I was worried about. How can I do true polymorphism with classes without virtual.
 
@FredOverflow It's not a substitute, but CRTP can be handy in a lot of cases that initially look like you need virtual functions, but you can get away without them.
 
@Xaade depends on what "true" polymorphism is
 
@Xaade You cannot simulate virtual with templates and expect to get runtime polymorphism. It just does not work.
 
7:22 PM
@Xaade You shouldn't, but if you really need to you can use pointers to functions. But don't.
 
How do I drop a hydrogen bomb without polluting the environment?
 
@jalf : Call an identical method on multiple different types without knowing the exact type.
 
sbi
@Xaade It's often used for a technique called "type erasure".
 
You simply cannot have your cake and eat it, too.
 
sbi
@Xaade That's what all STL algorithms do all the time. What's your problem with this?
 
7:22 PM
@Xaade templates allow you to do that perfectly well. But the types are resolved at compile-time. So you'll probably need to refine your requirements a bit :)
 
@FredOverflow The cake is a lie! (Sorry, this is stronger than me).
 
@sbi They know the type at compile time.
 
@FredOverflow Templates offer compile time polymorphism. Overloading does too.
 
@FredOverflow but he didn't specify that compile-time binding was a problem
 
@StackedCrooked Yes, but they do not offer runtime polymorphism.
 
7:23 PM
Actually, I find that overloading by type is really one of the most useful C++ features.
 
@CatPlusPlus 2007 called, they want their... cake... back
 
@FredOverflow Indeed.
 
@jalf Space cake!
 
@jalf I hope you rememberd to tell them about the earthquake in japan then?
 
Why am I here?
 
7:25 PM
You don't always need runtime polymorphism. But when you do, you must use virtual (or simulate some equivalent manually).
 
I could be sleeping!
 
Eh, I overuse exclamation point today.
 
@jalf What happened, an InterruptedException?
 
I'm confused.
Let's say I had a std::vector.
Let's say I want to put two different types in the vector, but call the same method on them (the two types have different reflexes for the methods).
If I use a template to describe those two types, I can't put them into the vector without the vector being able to handle multiple types, or the types share a base class (at which point I use the base class pointer).

So without virtual being available and having to use templates to describe my classes, the vector would have to support multiple types in its positions.
 
@Xaade You're conflating two different issues though
can the same function be called on both objects? Yes. Can the vector store objects of both types? Not directly
 
7:27 PM
Ok, so I wrap both types in an object?
 
that's one option, yeah
 
@Xaade You can either use std::vector<Base*> or std::vector<boost::variant<Type1, Type2> >.
 
I don't quite get how the templates, which created two DIFFERENT types, are polymorphic.
 
or you store pointers, converted to some suitable common base type
@Xaade probably because you're thinking polymorphic in the "boring" OOP sense, with virtual.
But templates allow me to write a function foo, which works on any type T. How is that not polymorphic?
 
@jalf Actually, templates allow you to write a function template that works on any type T ;-)
 
7:29 PM
Because, as far as I'm concerned, polymorphic means you can refer to two different types with a single reference, and call a method that resolves to different methods based on the type.
 
That's usually what "polymorphic" means in functional languages. And it is a perfectly valid form of polymorphism
@Xaade then you're talking specifically about runtime (or dynamic) polymorphism
 
@Xaade That is "subtype polymorphism", one of four possible kinds of polymorphism.
The other three are genericity, overloading and coercion.
 
I read 'subtle polymorphism' and was confused for a second.
Guess I need some sleep, too.
 
hello all
 
I see.... so one kind of polymorphism, allows me to write a template, have some code call template methods on the object, then at some point in the future, change it's underlying type without having to change my method calls.
 
7:33 PM
If you really want to get into templates, I suggest you buy a book about the STL.
 
Like so....

animal<dog> theAnimal;
theAnimal.makeSound();

Output bark.

animal<cat> ....

Output meow.
 
I have never seen templates used that way.
 
Sorry....
 
It still seems you see templates as a subsitute for OO. They are not. Templates and OO are orthogonal.
 
looks valid enough to me though
you can do that, and it is polymorphic. But all the types are bound at compile-time, so you can't store an animal<dog> into a reference-to-animal<cat>
 
7:36 PM
@FredOverflow : That.... therein.... lies my problem. The main reason I don't understand templates. I can't come up with any design that could use a template, that I couldn't do the same thing with OOP....
 
it's polymorphism, it's just resolved earlier
try writing a simple max function then
with OOP, you'd end up with something like max(1, 4) returning an object instead of an int
with templates, it'd return an int
and it'd be faster
and more typesafe
 
@Xaade Sure, you can do anything with objects, just as you can do anything with just C or even plain assembly language.
 
it would generate a compile-time error if you call it with max(1, "hi"), whereas the OOP version would have a signature like object max(object, object) in order to be as generic, and then it would accept invalid inputs like (int, string)
 
@FredOverflow : I didn't say OOP was "superior", I'm just saying my mind is closed to templates, but I can't find a point where a template design would pop into my head.
It's MY FAULT....
 
How would you write a sort algorithm that should work with any kind of collection? You could either go the OO route and have a Collection supertype that every collection class has to derive from. Or you could ditch inheritance, go the STL route and invent the "iterator" concept. Again, read a book on the STL and you will understand.
 
7:39 PM
Java arrays allow you to store a banana into an array of dogs, because they just store Objects. Templates allow you to define an array of dogs, where it'd be a compile error to store anything else into it
 
@jalf Only if you cast to Object[] first. Also, Java does not "allow" that, it just happens to be a runtime error instead of a compile-time error.
 
@FredOverflow : I've only seen the callback scenario... but that involves making a different method for each combinations of types you would use.
 
sbi
Come on, guys, this could have a few more upvotes. :)
 
Overloading is really powerful. I'm experimenting with automated unit testing using a mechanism like this: code.google.com/p/stacked-crooked/source/browse/trunk/…
 
@Xaade Yes, but the compiler stances those functions out for you. You only write the template once.
 
7:41 PM
@FredOverflow yeah, but that's my point, it's usually considered an advantage to catch the error as early as possible. At compile-time is preferable to at runtime
 
@jalf I totally agree.
 
@sbi Done.
 
sbi
Whoa, look at this guy's code:
0
Q: C++ template meta sql

Industrial-antidepressantI wrote a wrapper around boost-mpl and transformed it to an sql engine. It is a compile time sql thing, not related to normal databases. I have not finished it completely. I have some problem with the interface. A template meta program run in compile time. So input data always present in compile...

@StackedCrooked :)
 
@FredOverflow : Ok, I think I understand now. Partially. I get template methods. Still don't get template objects.... Applying that method concept to an object. You want to design a template object that would work on any type and accomplish the same goal.
 
you can't have a template object. You can have a class template
 
7:43 PM
@Xaade Do you understand List<String>? How is that not useful?
 
@sbi The Poco libraries achieve the same elegantly (templates instead of macros) by returning a Tuple object.
 
I keep thinking of objects as conceptual objects. Functional objects, haven't wrapped my head around yet.
 
@sbi ok that's plain crazy, does it make any sense?
 
think of containers/collection classes again
 
@jalf : Yeah, I'm getting the connection now.
 
7:43 PM
@Xaade What is a functional object?
 
you want to be able to say "this is a list of apples", and "this is an array of cars"
class templates do exactly what it says on the box. They're templates for constructing classes. So you write a bit of code, which is the template used to generate "array of T"'s
using this template we can generate one array<dog> class, and another, entirely unrelated (as far as the type system is concerned) array<cat>
 
: Inventing words again I guess. To me, a "functional" object, is a "class/object" that accomplishes a goal, rather than an object that represents a concept.

For example.
Concept object programming would be a person that contains a mouth that can chew.

Functional object programming would be a chew object that uses the person's mouth.
 
@Xaade in C++, that'd probably be a functor
 
> Functional object programming would be a chew object that uses the person's mouth.
That's gross!
 
sbi
@Xaade That's just plain wrong. Chewing is something you do not you are, so you need an algorithm, not an object.
 
7:46 PM
but you were asking about objects/classes in general, I thought? As in, objects (in the OOP sense) which represents, well, objects, as well as those that represent functions or actions?
or did I misunderstand?
 
: I understand that my example isn't perfect. But the purpose of an array is to store items. An array is more functional than it is a concept.

When I see a line of cars, I don't see the "line" as an object. So any class that represents the line, is a functional class.... not a conceptual object class.
 
@Xaade that's an unusual point of view. Every object has a purpose, but they're often still things, not functions. A physical plate is a thing, even though its purpose is to store food, isn't it?
 
In the same manner, if I think of class templates as accomplishing a function... then I might be able to come up with designs that include templates.
 
I see. I would probably call those "domain objects" and "plumbing objects" ;-)
 
sbi
@Xaade If I see a line of cars, I see that they're on a street. And that's an actual object. (And besides that, a "line of cars" is as conceptual as it gets.)
 
7:49 PM
@sbi : Poor choice of words on my part.
Point being... if you have an array of cars.... what is an array. Have you ever seen an array lying around??? I've never SEEN an array.
The array doesn't exist....
 
sbi
@Xaade I doubt it very much. I suppose there's an underlying problem unde rthat poor choice.
 
It accomplishes a goal. To contain the cars.
It doesn't exist in the real world.
That's my problem, I see objects as existing in the real world.
Which is why templates escape me.
 
No single C++ object really exists, they are just extremely simplified models of objects in the real world.
 
sbi
@Xaade And what's this got to do with anything? My mother has never seen a HD lying around, and she's still using it.
 
7:51 PM
@Xaade I see. Well, that maps very well to templates, I'd say. A class template doesn't exist by itself either. But you can specialize it by providing another type for it, and the result is a class (say, you have a line template which is specialized to create a "line of cars")
 
@jalf : Finally... someone's understanding what I'm saying.
 
sbi
@Xaade And array is an abstraction of a container where elements are sorted and lying right next to each other. I have certainly seen such objects in the real world, and so have you.
 
A template is just such an "unbound" concept. It doesn't become "real" in the program until you tell it which types (or constant values) to wrap itself around
 
@Xaade Lucky you :)
 
@jalf Well, according to the standard, a class template is an "entity". Sounds pretty "existential" to me ;-)
 
7:53 PM
Of course, in the OOP world an array by itself can exist, because it is implicitly "an array of objects"
@FredOverflow well, according to my compiler, defining templates which are never used doesn't make any difference to the resulting executable. Sounds pretty "nonexistential" to me ;-)
 
I guess this conversation isn't for me
just saying
 
Sorry... my understanding of math and logic is very much tied to the visual world.
 
@FredOverflow anyway, we both know what I mean. I'm too tired for the usual pedantry, and I suspect it would only muddle the discussion ;)
 
sbi
Happy Star Wars day, everyone! May the fourth be with you.
 
@Xaade Then you will love Visual C++ ;-)
 
sbi
7:55 PM
OH: If today is star wars day, is tonigh the dark side of the 4th?
 
@FredOverflow : I do.
That's why they have me working on GUI.
 
@Xaade How do you understand Morgan's Law (negation of AND/OR) in terms of real objects?
 
@Xaade What kinds of GUI objects do you consider "real"? Are events "real"? Have you ever seen an event?
 
@StackedCrooked isn't that DeMorgan? Or something? Been a few years, I'll admit ;)
 
@StackedCrooked : It's really hard for me.... I usually draw inclusion circles.
 
7:57 PM
virtual implemented manually with templates: ideone.com/xruoW :-)
 
@Xaade Are circles real?
 
@FredOverflow : Events are messages.... like letters.... passed around by a carrier.... the Win32
 
@jalf Apparently it's "De Morgan". It's a tie.
 
@FredOverflow : real != visual
 
I don't think anyone has ever seen (or will ever see) a circle.
 
7:58 PM
@FredOverflow Ceci n'est pas une pipe.
 
Hi René.
 
@FredOverflow : Drawing of a circle.... don't be so literal.
 
@Xaade Not even a drawing of a circle is possible. It would involve drawing an infinite amount of inifintely small points. Plus, paper does not offer inifinite precision.
 
anyway, a big hint is really in the name, "template". it's useful whenever you go "sheesh, I wish I didn't have to keep making copies of this code, with only a tiny change each time". Make it a template, and have the compiler specialize it for the different use cases for you. Then you can define the concept of an array once, and then apply it to apples, dogs, bees, waffles or bottles "for free".
Or the define a max function which can be applied to any object that defines the "less-than" operator, instead of having to write a separate max for each type
 
@FredOverflow : Are you trying to help, or prove me a liar. Either way, you're not helping.
 
8:01 PM
does that help?
 
@Xaade I was just wandering if circles are objects or not.
 
HTML sucks
 
anyway, I'm gonna go pass out now. See ya!
 
this I have decided
 
more so than php or stomach troubles?
 
8:02 PM
@FredOverflow A circle is something that can be understood as a real-life object. It can be imagined a bicycle wheel for example. This doesn't require the wheel to be a perfect circle.
 
@FredOverflow : Wandering around aimlessly.... or wandering around in a circle. Because you can't wander in a circle. That would require infinite small turns, which I don't think your feet are capable of.
 
hmm
PHP definitely sucks more than HTML, because it inherits all their suckage and then sucks more
 
@sbi lol
 
but stomach troubles suck the most, definitely
 
@Xaade Good point :)
 
8:02 PM
@DeadMG what's the most suckage of all, does anything beat PHP?
 
hmm
 
Let's just ditch all that complicated template stuff and concentrate on solving the mysteries of circles!
 
@TonyTheTiger : I once had to write an assembly program that modified its own execution code while in memory.
 
@FredOverflow The Magic Circle in England is the most elite club of magicians. That tells!
 
in HTML, the whole styling and layout things is completely fucked
 
8:04 PM
@Xaade that sounds cool, self modifying code, that doesn't suck imo
 
It went rampant.... and it's been misunderstood as the E. Bowl-eye virus ever since.
 
@DeadMG oh, DIV tags have to be the worst invention ever
 
E.Boli doesn't exist
you likely mean E.Bola, or E.Coli
 
@DeadMG XHTML helps.
 
@TonyTheTiger Until you try to port it to a system where code is in write protected sections. Then you have to copy the code before modifying it.
 
8:04 PM
what even is XHTML?
 
@StackedCrooked anything with those HTML letters in it, suck
 
@DeadMG : HTML is like defining your methods inside your main... then having to copy that code around every where you call the method.
 
@DeadMG HTML variant that requires the doc to be well-formed XML.
 
@DeadMG html where you have to close your tags, and do so in the same order as you opened them
 
@AProgrammer argh, that's to prevent virus writers from abusing the ability to write self modifying code for destructive purposes
 
8:05 PM
all I know is that I tried both the Visual Studio webpages designer, and Dreamweaver CS5, and neither of them are capable of moving elements vertically, you can only stack them horizontally
 
Another fun with ASM is interpreting part of it as data and then as code.
 
@DeadMG I've never seen a visual designer for HTML that worked
much easier to just use notepad++ or something
 
@AProgrammer I've played around with Buffer Overflows in ASM, for fun :)
 
@TonyTheTiger Be a little more open minded. :)
 
overwriting EIP on the stack is fun
 
8:06 PM
that doesn't help, because the systems involved with it are insanity, regardless of what program you try to use to generate them
 
@StackedCrooked I tried and it only got more frustrating from that point on
 
@jalf : Because copy and pasting becomes a tag moving nightmare. What if I forget to analyze one tag and don't wrap it before copying.... then when I paste, should I remove identical tags that surround the pasted content.
 
@TonyTheTiger :/
 
it's hardly got a clean, hierarchical, object-orientated structure
 
<b> yes <i> no </i></b>
Copy text "no".
Paste somewhere.
Did your designer remember to include <b> in the copy.
Which is why a lot of designers I know won't even do that.... they'll do this after formatting.
<b> yes </b> <b> <i> no </i> </b>
BEAUTIFUL!!!
 
8:10 PM
it would be easier for me to finish implementing my own rendering engine and finish writing all the UI classes rather than use HTML
 
@Xaade yeah, but I'm not interested in excuses. ;)
I've just observed that they suck, and they're more trouble than they're worth .)
 
What's even more awesome.... cutting and pasting "no" in the same exact location. Result was:
<b> yes </b> <b> <i> </i> </b> <b> <i> no </i> </b> <b> <i> </i> </b>
 
@StackedCrooked :(
 
What I would do??
Write an interface that uses objects that render the same way as HTML.... then build the HTML whenever you export to HTML.
 
What I would do -> rip out the whole thing and start again?
 
8:13 PM
I would ban HTML and PHP off the face off the earth and the world would be a better place.
@DeadMG yep
 
pages shall now be written in a vaguely C#-resembling language, that is fully stateful and object-orientated
 
You can use RAII to represent an XML element. In the constructor you put the opening tag and in the destructor you put the closing tag.
 
but can you genuinely use RAII to represent the semantics of an HTML element?
cause last time I checked, HTML tags change behaviour depending on what they're nested in
 
The you can write code like this: El theDoc("html"); El theBody("body"); El theLabel("label");
 
and I'm not just talking about forbidding some nestings
 
8:15 PM
@DeadMG Not HTML perhaps, but XHTML yes.
 
XHTML is pretty much dead.
 
@CatPlusPlus It lives on in HTML5.
 
@DeadMG contextual tags = bad idea. Need to make new tags.
Could you imagine a windows program doing this.

if (GetParent()->GetType() == eScreen)
{ DrawSideways(); }
else
{ DrawVertical(); }
 
uh
without any sort of meaningful explanation, then yes, I could
 
if (m_pParentContainer == typeof(std::vector<someclass>)
{ someclass::method() }
else if (m_pParentContainer == typeof(std::vector<someotherclass>)
{ someotherclass::method() }
 
8:25 PM
uh, yes
it's called dynamic_cast
happens all the time, it's a language feature
 
Or overloading.
 
the test occurs at runtime, I'm imagining
 
@TonyTheTiger I'm writing stuff in MIPS assembly now.
 
I'm talking about classes that require information about their parent's type to reflex.
@DeadMG : This sounded awful. Any rendering in C++ would be questionable design practice.
 
And wondering why add $t0, $zero, 1 doesn't increase $t0. Of course the answer is "because /me is stupid".
 
8:27 PM
@CatPlusPlus hmmm interesting :P
 
@TonyTheTiger It has a nice environment to work with (well, MARS is, anyway; haven't used SPIM). I like execution speed control a lot.
 
sbi
I think we can take down my little poll from today now. @Tony and the other few, um, misguided conservatives are utterly defeated, and the way to go seems clear.
 
@sbi ok I admit, I was too conservative
 
@sbi : Moar deficit spending?
 
8:42 PM
@sbi watching the Scott Meyers video, great stuff :)
 
Xeo
and with that, I'm off. :)
 
45 mins ago, by Tony The Tiger
@StackedCrooked anything with those HTML letters in it, suck
@TonyTheTiger With the Exception of HoTMeaLs, of course ;-)
@TonyTheTiger What Scott Meyers video are you watching?
 
8:59 PM
The video quality is horrible :(
 
yes
but the audio is good enough to follow along
and he explains it very thoroughly
 
Fortunately, Scott's hair (and competence) makes up for it.
 
true :P
 
Xeo
@TonyTheTiger lol, "predict when and how often I'll trip"
 
@Xeo :P
 
9:21 PM
@TonyTheTiger The guy is also funny :)
 
sbi
@FredOverflow "My hair style calls into immediate question all my judgements." Scott Meyers
 
A 4,5 hour talk about rvalue references? I would really like to see that!
 
sbi
@FredOverflow It's not a talk, it's a seminar. It's too slow-paced for you and for me, but he makes up for it.
It's fun to be there.
 
Wow, Scott has two really good introductory examples for motivating move semantics.
Oh, he even has a third example :)
 
sbi
@23:28: "We never move from lvalues." <pause/> "We never move from lvalues." <long_pause/> "It's a lie, but it's really close to true." <laughter/> "This is C++. Everything is a lie. But is still really close to being true." :)
 
9:30 PM
Hi there
 
How do you move from lvalues? Does he mean T(std::move(some_lvalue))? Because then it's not an lvalue anymore, it's has become an xvalue :)
std::move does not move, it's just a cast to an xvalue :)
 
sbi
@FredOverflow I think hist philosophy is that, since he's earning his money with teaching, he'd better be a very good teacher. So he works hard.
 
(I have a quick little question about C, not really worth the post on the stack, may I?)
 
@Sword22 Sure, why not.
 
sbi
@FredOverflow Yeah, but the effect is still that val = std::move(lval) moves from an lvalue, right?
@Sword22 Now you already did ask a question about C. :)
 
9:33 PM
@sbi Depends... is val of a type with a move assignment operator?
 
sbi
@FredOverflow Yeah, that depends. But if it is, there's your example.
 
@sbi But we still don't move from an lvalue, because std::move(lval) 1) does not move and 2) is not an lvalue anymore.
 
In a given structure I have let's say a int tab[N] variable. Why can't I call the constructor of this structure like this blahblahconstructor(int k[N]) {tab = k;} ?
 
You can only move from rvalues (prvalues or xvalues) because rvalue references only bind to rvalues. And your type has to have move methods.
 
That should some obscure C reason that I don't know yet
be*
 
sbi
9:36 PM
@FredOverflow Are you trying to annoy me? We are trying to find an example where we move from an lvalue. Of course we have to have moving ctors and assignment ops.
@Sword22 C doesn't have constructors and no this pointer.
 
> Lvalues are things that you can generally take that address of. Generally.
Wrong: that's precisely what lvalues are :)
 
@sbi Yeah well, when I said constructor I meant the instantiation function of the structure.
 
@Sword22 You can't assign to arrays.
 
@Sword22 Array parameters are silently rewritten by the compiler as pointers. Warning: This does not happen anywhere else. Arrays are not pointers!
 
@CatPlusPlus And what would be the method to go around that? (geez, going from java and python to C is harsh)
 
9:40 PM
@Sword22 Copy all elements from one to another.
 
(So you are trying to assign a pointer to an array.)
 
I see...
 
You can't assign array to an array, either.
 
so int* tab won't work either that's right?
 
Where is tab defined? Is it a struct member?
 
9:42 PM
Well, you can assign to a pointer, but ask yourself if that's what you really want to do. And why the hell are you writing C, go learn C++.
 
memcpy(tab, k, N * sizeof(int));
Or just memcpy(tab, k, sizeof tab); if tab is an array. Can we see the declaration?
 
@CatPlusPlus classes purpose, if I had the choice I'd go with something else. I have this algorithmic class where all the assignments have to be made in C and we were never taught C ever.
@FredOverflow seems good, thanks
 
Can we see the declaration of tab?
 
(Thanks you all btw)
Oh that was an example
 
@Sword22 Ugh.
 
9:46 PM
oh hello all
I guess that video was an interesting find :)
 
Yes, thanks.
 
Basically I'm trying to do a BF palindromes sequence research in a vector, I already did it using dynamic programming and that was way easier.
@FredOverflow Woaw memcpy works really great. Thank you very much!
 
> The reason you identified [the object] as a candidate for moving is you want to rip its guts out, which is a non-const operation!
 
I think I'll add memcpy to the list of function that if I had know before I wouldn't have watsed 3 hours of my life.
 
Right, every C programmers should know memcpy :)
 
9:55 PM
And memmove.
 
Just be sure you understand how sizeof works with respect to arrays and pointers. sizeof is a compile-time operator, and it will always yield the size of a pointer if you give it a pointer. It will never try to guess at runtime how many elements you have in memory starting at the pointer or something.
If you give sizeof an array, it will give you the size of the array in bytes, not the number of elements. Many programmers have stumbled over this one.
And just to be sure: Arrays are not pointers.
(Do we need a FAQ on sizeof? Do we already have one?)
 
@FredOverflow The idea of moving memory always strikes me as odd. One of the first things I learned about computers is that moving from memory location A to B actually means copying from A to B. Optionally followed by erasing the contents of location A.
 
@StackedCrooked memmove is just a slower variant of memcpy that works for overlapping arrays.
 

« first day (200 days earlier)      last day (4740 days later) »