« first day (90 days earlier)      last day (4843 days later) » 

1:00 PM
I think it has it's place like anything else. If it is an unreadable pile of crap then perhaps if/else is better.
But for simple things, it's fine.
 
I find it funny when OO purists claim that if/else is evil and should be replaced by virtual dispatch :)
 
I also find that humourous
I mean, virtual dispatch is great, but seriously, there's a limit
if you don't have if/else, how are you going to create objects with a run-time type that's not it's static type?
unless you want to build a jump table by hand
 
@DeadMG I'm sure the OO purists have an answer to that. The factory pattern, I guess.
 
sure
but how am I going to choose what constructor to call?
oh, whoops
the only thing you could do is hand-build a jump table
 
Just because something can be achieved using idiom A, doesn't mean it should. Someone looking at code is going to understand if/else a lot faster than finding out what the factories are doing and why.
 
1:04 PM
@DeadMG Via XML configuration files that are 12 MiB in size on average
yes, we can
 
how are you going to parse the XML without if/else?
 
@DeadMG Dynamic dispatch. duh
 
right
 
by the way, there’s a library for that
 
so how are you going to dynamically dispatch when you can't create different types dynamically?
 
1:05 PM
interface Boolean
{
    void if_else(codeblock true_block, codeblock false_block);
}

class True extends Boolean
{
    void if_else(codeblock true_block, codeblock false_block)
    {
        true_block();
    }
}

class False extends Boolean
{
    void if_else(codeblock true_block, codeblock false_block)
    {
        false_block();
    }
}
 
but the point is partially right
 
@DeadMG There you go, if/else simulated by virtual dispatch.
 
wtf language is that in?
 
it’s usually a good solution to remove the if from the actual code and hide it in the factory
unless that makes the design orders of magnitude larger, of course
 
which is practically every situation
 
1:06 PM
@DeadMG Any OO language that supports closures.
 
I'm not against replacing huge switch/case with virtual dispatch
but if (a) x() else y()
that's just silly
the trouble with jump tables is that they become a LOT more complex when the values involved aren't like, 0-n integers
 
@DeadMG in all fairness if someone would ask you why "int n = 0 ? 1 : 2;" fails, and you would get an answer "it fails because both branches have different values", it doesn't sound wrong if you get a question back like "why does my compiler accept it?"
 
but he didn't ask that
he asked why someone else's compiler accepts it
that someone who is most definitely not me
 
i agree his question was stated badly imho
 
how on earth am I supposed to answer questions about a different compiler to the one specified?
 
1:08 PM
@DeadMG I think Smalltalk did exactly that, you pass two codeblocks to an IfElse method or something.
 
i too thought first the code is indeed illegal, but when he said gcc accepts it i became suspicious xD
 
as far as I know
the Standard latest draft basically gives the compiler complete freedom over lambda types
doesn't define any conversions or comparisons
except the function-pointer for capture-less ones
and the compiler is free to make every lambda a different type and doesn't have to provide any conversions
in any case
I know that MSVC is written to an earlier draft
 
@DeadMG well, except for the function-pointer conversion
 
they don't, for example, allow captureless lambdas to be converted to function pointers
yeah, I mentioned that :P
that's actually a good point
in his case, surely the legal result type would be void(*)()
I'd completely forgotten about that
but of course, since MSVC isn't written against that draft, then it won't go there
 
Hello, could someone explain why, with Visual Studio 2010, without UNICODE defined, the following constructor throws an exception:

_tregex r(_T("\\x80"));
 
1:16 PM
what exception?
 
and not when using \x00 to \x79
it is a bad_regex.
 
pretty sure that you've done that wrong
 
looks reasonable
 
\\ is the escape sequence for \
 
Yes, and I want \x to be in my regex literally
 
1:17 PM
ah right
ok
 
@Benoit In that case you need \\\\
 
yes
no wait
shouldn't it be \\\?
 
Why?
 
good thing that C++0x introduces some solutions to this problem
 
because \x is an escape sequence for some x. \\x means literal \x in a string, but regex also has \x as an escape sequence. So if you want to have literal \x in a regular expression, you need to escape \ twice – hence \\\\
 
1:19 PM
`\\\\` looks like a fast camera shot of dominoes falling.
 
Yes. \x is part of my regex because I want to match hexadecimal character 0x80.
 
ah, ok – then you’re doing everything right
 
So regex("\\x80") should build a regex that matches it, as regex("\\x20") matches a space.
 
except that 0x80 is outside the ASCII range and without UNICODE defined, _tregex will probably not be able to handle that
 
I thought that ASCII was 0-127?
 
1:20 PM
i.e. it will assume that the input is an ASCII string and thus cannot contain anything > 0x7F
@DeadMG Right. And 0x80 is 128
 
oh yeah, hex
 
Yes, but char has a length of 8 bits…
 
@Benoit irrelevant, unfortunately. At least in Microsoft-C++ land
 
And I have chars that are 0x80 (the Euro sign in ISO-8859-15 or codepage 1252)
 
@Benoit have you set that codepage in your application? Good. That indicates that the regex ignores code pages
(I’m assuming here, I have never worked with that type and it’s been years since I last touched a Microsoft C++ compiler)
 
1:23 PM
Actually _tregex is a macro that is a synonym for std::tr1::regex or std::tr1::wregex
in my case it is regex.
 
OMFG... I just had a call from a new client we're going to be working with... they want a quick amend to their old existing site before we migrate them, and his question was "We do not know the password to our current database, but anyway, can you amend the following..." .. O.O
 
@Benoit I assumed as much but that doesn’t change my answer ;)
 
@KonradRudolph Thanks. Fortunately we are switching to Unicode soon.
 
Grr. I wish GCC were a dude so I could kick him in the nuts. This is driving me crazy :(
 
@MooJuice just bruteforce it. There is (little) chance the password is hello or some stupid string like that :-)
 
1:26 PM
lol
or <companyname>1234
 
or the birthdate of the previous database admin or his girlfriend/wife/mother
 
1:38 PM
0
A: Horizontal Scrolling Ticker Option in Chat

Tomalak Geret'kalThis has wound me up no end over the two weeks that I've been using StackOverflow. In general the SO software is really tight, and the chat feature is fantastic. The feed itself is very useful too, but it is so invasive as to be a real distraction. A way to selectively disable the feed showing ...

 
sbi
yesterday, by sbi
That got me thinking: How about we add a feed to this room for c++-faq questions? That would be a low-volume one (and we would definitely want to know if it wasn't!). But since it would sport questions that might already be fed in here by the feed Roger set up, I thought I would add it so that it is posted as messages by that Feed guy. Anyone violently opposed to that?
Since nobody seemed to have objected, I went and added that.
(IOW, if anyone adds anything to the c++-faq tag, it will be posted here as a message.)
 
8
Q: Lifetime of temporaries

frunsiThe following code works fine, but why is this correct code? Why is the "c_str()" pointer of the temporary returned by foo() valid? I thought, that this temporary is already destroyed when bar() is entered - but it doesn't seem to be like this. So, now I assume that the temporary returned by foo(...

5
Q: FAQ: Why does dynamic_cast only work if a class has at least 1 virtual method?

FilipThis does not compile in C++: class A { }; class B : public A { }; ... A *a = new B(); B *b = dynamic_cast<B*>(a);

7
Q: Semantics of flags on basic_ios

Steve TownsendI find myself repeatedly baffled by the rdstate() flags - good(), bad(), eof(), fail() - and how they are expressed in basic_ios::operator!, operator bool and operator void*. Could somebody put me out of my misery and explain this so I never have to think twice again?

27
Q: Operator overloading

sbiWhat are the basic rules and idioms for operator overloading in C++? The General Syntax of operator overloading in C++ The Three Basic Rules of Operator Overloading in C++ The Decision between Member and Non-member Common operators to overload Assignment Operator Input and Output Operators Fun...

14
Q: Undefined Behavior and Sequence Points Reloaded

NawazConsider this topic a sequel of the following topic: Previous Installment Undefined Behavior and Sequence Points Let's revisit this funny and convoluted expression (the italicized phrases are taken from the above topic *smile* ): i += ++i; We say this invokes undefined-behavior. I pr...

 
ohh nice new feature?
 
sbi
Urgh. It seems it first adds some of the old ones. Sorry for that.
2 mins ago, by sbi
Since nobody seemed to have objected, I went and added that.
 
sbi
1:49 PM
Currently, both the c++-faq tag page and the question on meta that started the FAQ idea have inline feeds. If anyone adds anything to either of those, it will be posted as messages from that Feed guy. Since both should be low-volume, that should be Ok. If anyone still objects, just holler.
 
If anyone objects, just ignore the Feed guy.
 
sbi
@TomalakGeretkal That, too, would work. Still, if 90% of all participants here would want to ignore these, I'd question their existence.
. RT @jorendorff: "So this SEO expert walks into a bar, grill, pub, public house, Irish bar, bartender, drinks, beer, wine, liquor"
 
I just pasted that SEO joke to my colleagues
nobody got it :(
I work with failures.
 
Perhaps they’ve until now been sheltered from the harsh reality of the web
don’t shown them 4chan straight away ;)
 
or reddit/r/gone_wild
 
2:04 PM
@sbi sure
@MooJuice I got it; it's just not particularly funny.
 
sbi
2:26 PM
Victory is mine! I've beaten the feature and now I can go to bed ... as soon as the caffeine gets out of my system
@jaredpar But who would want to use a beaten-up feature? :)
 
groan
I must be the only programmer in the world with an actual sense of humour
 
Yeah? Prove it. :)
 
sbi
@TomalakGeretkal This is the C++ chat, you're in. Of course, we all have an anally perverted sense of humor. What did you expect?
Anyway, I need to go home to beat up the kids. See y'all later!
 
Remember @sbi
If you kids aren't in the fetal position when you get home, you have failed as a parent.
 
Question: How do you call programmers who constantly say "I don't like that" and "Na, I'm not gonna do that?"
Answer: object oriented programmers ;-)
 
2:30 PM
unemployed.
 
(to object means to disagree)
 
Oh dear :)
That's up there with, "I'm sorry, you have acute angina"
"Really? Thank-you!"
 
@sbi "Perverted" is not the same as "shit", though you did say "anally" :)
@MooJuice I proved it by not finding those tweets funny.
@FredOverflow lol
 
sneaky.
 
@MooJuice Always
 
2:33 PM
@FredOverflow, I am sure you could come up with a joke that involved a complex-inheritance tree, a depressed type that is mad at the world, and the word "downcast".
2
 
heh
btw C++<Lounge> doesn't make much sense
 
Object o = "heretic";
String s = (String) o;
@MooJuice What song is this? :)
 
should be "C++::Lounge or Lounge<C++>"
 
@FredOverflow It tells you in the title and the description and the comments
 
2:38 PM
@TomalakGeretkal C++ is not a valid C++ identifier
 
You didn't give me enough time, @FredOverflow :)
Cast Down the Heretic :)
 
@MooJuice I figured, nobody would get it, so I could just post the answer directly.
 
2:49 PM
these days everyone seems to have twitter account
 
@FredOverflow And neither C++ nor Lounge are declared!
(albeit, as you point out, one cannot be)
 
@TomalakGeretkal At least you could declare Lounge as opposed to C++...
 
though if you say #define C operator then you can say C++<Lounge> lol
 
:P
3
A: howto examine c++ .o file under linux?

Tomalak Geret'kalA .o file is the translated output from compilation. It is not C++, even if the source code that generated it was written in C++. You could get an .o file from the compilation of source of any programming language. Use objdump to look at .o files.

pfft how is this not the highest-voted!
 
3:01 PM
Have an upboat.
 
I feel that the other answer was more direct
I would have put "Use objdump to look at .o files" first, and then the rest later
you can have an upboat anyway
 
@TomalakGeretkal peoro answered 17minutes before you. maybe he collected 4 votes in that time. could explain the diff :)
 
Pity
implies that GCC does not have a macro to return the decorated name
if his question was unix
i mean, windows
 
@MooJuice lol thanks
 
with msvc, we could have pointed him at FUNCDNAME
 
3:07 PM
@JohannesSchaublitb ;)
This chat is handy
 
wtf happened to my underscores
'__FUNCDNAME__
 
@JohannesSchaublitb How do you know the exact time? They both say "2 hours ago" for me
@ChrisBecke SO formatting innit
 
@TomalakGeretkal tooltip :)
 
@JohannesSchaublitb ooh, genius
 
3:08 PM
haha
 
what tooltip?
 
litb you have a nasty habit of smacking people around the head with really complicated shit that they don't understand, scaring them off a thread
just happened to me
it's very clever
 
@TomalakGeretkal hmm what do you mean?
 
2
A: O my Lambda!!!!

Johannes Schaub - litbRules for conditional operator in the draft n3225 says at one point Otherwise, the result is a prvalue. If the second and third operands do not have the same type, and either has (possibly cv-qualified) class type, overload resolution is used to determine the conversions (if any) to be app...

what am I supposed to say to this!
 
Well
you did ask him to elaborate ;)
 
3:18 PM
lol
 
lol
 
The short conversation went like this:

Tomalak: "But you didn't include all that shit about Rocket Science"
Johannes: "K, here's all that shit about Rocket Science...."
Tomalak: "Shit, don't tell me all about Rocket Science"

:P
 
"it starts to even look like a TERNARY operator!"
 
@MooJuice That's not how I started it at all!
 
lol
 
3:24 PM
I said, "you included all this shit about rocket science but didn't describe the rocket." And I also wanted to imply that the OP only needed a firecracker.
 
he asked "What does this mean?"
 
@MooJuice explain != elaborate :)
 
@TomalakGeretkal, I wasn't implying my fictional account there was in anyway representative of reality :)
 
I've no idea what i've done wrong or overly complex. please elaborate & explain
 
"C++::Lounge or C++<Lounge>: For those who don't know (N)RVO" <- AWESOME haha
 
3:27 PM
@MooJuice :D
@jweyrich You just missed the conversation about how "C++::Lounge or Lounge<C++>" would be better
@JohannesSchaublitb lol
 
I prefer C++<Lounge>
 
@MooJuice It doesn't make much sense.
 
It's indicative of the content (language name, plus hints of a template). It sounds like a chat-room for C++. Encarta doesn't make much sense either, but it's a great name for an Encyclopedia.
 
@MooJuice lol
 
i think of Lounge<C++> as "instantiate me a lounge about C++"
 
3:30 PM
Yup, that works.
 
maybe i will think of C++<Lounge> as "The C++ dialect of C++::Lounge. Where (N)RVO is forbidden." haha
 
@JohannesSchaublitb yup
 
@TomalakGeretkal yup.
lol
 
Everytime I read NRVO I keep thinking of the army.
Fuck this company, seriously.
 
Ok, now I’m apparently too stupid to use an ostringstream … shouldn’t the following work in principle (it compiles)?
std::ostringstream sstr;
for (TIterator i = _begin; i != _end; ++i)
    sstr << *i;
do_something_with(sstr.str());
do I need to flush the stream or something?
 
3:46 PM
@KonradRudolph Can't see anything wrong immediately. I haven't checked the docs but I'm 93.2% certain that you don't have to flush (or sync()) before str().
Assuming that Tit-erator does something sensible.
 
@CharlesBailey Thanks. This is a very weird error indeed
In my real code, the loop (correctly braced, yes) contains another output statement that writes directly to cout – this works. Only the ostringstream ends up being empty.
 
@KonradRudolph It's not something "obvious" like a zero byte causing the string to look empty?
 
I’m investigating but theoretically begin and end are just char* s (valid positions, that’s verified) into a buffer that contains the lovely text "long text to be searched longlong text to be searched longlong text to be searched long"
 
so what type is TIterator?
 
I don't understand, I'm seeing Tomalak's messages in transcript.
 
3:52 PM
@AlfPSteinbach looks like a bug in ignore.
 
quick question
let's say that I have a bunch of objects to be rendered in a scene
 
@Johannes Tomalak's comment that my answer was false, was incorrect. In that question the return type was non-ref. Also, the code was not the OP's, no one was insulted. He's just making personal comments. I don't know why.
 
should I set visible/invisible on each of them
or set them into groups to be visible/invisible all at once
 
Damn. Problem solved. – Did I already mention that I hate macros?
 
@DeadMG each of them. You can optimize the performance by moving them to a (in)visible list though.
 
3:55 PM
you think?
 
@Alf ohh i see!
 
I was thinking that the whole Visible() thing would get quite repetitive
 
@Konrad, what was the issue?
 
i was so blind!
 
and I was going to group them into Scenes to be rendered separately
and then you can set which scene is active, etc
oh well
I might just leave that kind of organizational tool to the user
 
3:56 PM
@MooJuice the do_something_with is a debugging printing macro. Since that macro has to work in multithreaded code and cannot use a critical section, it streams its arguments into a string stream and outputs that all at once.
 
it's not like I wrote my library so that you can't instantiate on the stack, etc
 
Guess what this stringstream inside the macro is called …
 
lol?
 
@KonradRudolph Ouch.
 
rofl
 
3:57 PM
turns out, stream << stream.str() doesn’t work so well :D
 
lol
 

« first day (90 days earlier)      last day (4843 days later) »