« first day (254 days earlier)      last day (4699 days later) » 

12:02 AM
@Potatoswatter No idea. It doesn't like one of my lambdas.
I'll fix it someday.
 
@CatPlusPlus Paste it here and I'll take a look, lol
 
It's ugly, I know.
#define LOG_INTERNAL(Stream, Msg, Fn) \
	Stream << Logger::Prefix(__FILE__, __LINE__, Fn) << Msg << Logger::Suffix()

#define LOG_FUNC(Msg, Fn) \
	Logger::WithLog([&](std::ostream& GC_log_, const std::string& GC_fn_){ LOG_INTERNAL(GC_log_, Msg, GC_fn_); }, Fn)

#define LOG(x) \
	LOG_FUNC(x, __FUNCTION__)
For completeness.
Also it doesn't seem to inherit typedefs. Are typedefs inherited, or is it just MSVC being polite to me?
 
Everything that is in scope at the site is available in the lambda (including class scope where applicable)
 
@CatPlusPlus Typedefs inside a base class are accessible through a derived class… this is used for example by std::iterator so not likely to break.
 
Config.cpp:124:23: error: expected ')' before 'defaultValue'
Config.cpp:143:2: error: 'ValueT' does not name a type
Config.cpp:143:2: note: (perhaps 'typename Variable<Tag>::ValueT' was intended)
 
12:11 AM
The standard name for __FUNCTION__ is __func__
 
__FUNCTION__ works, too. :P
Meh, maybe I made another stupid mistake I don't see.
 
Where is 'defaultValue'?
 
Ctor argument.
BoundVariable(ValueT defaultValue, ValueT lowerBound, ValueT upperBound, const Config::VariableMetadata& meta)
 
Oh. Yeah, types in a declaration outside the class scope need to be qualified with the class name.
BoundVariable::ValueT
Oops, now I finally see the source, it is in the class scope. I dunno.
 
Yeah, it'll be faster to copy-paste the typedef, methinks. :P
 
12:16 AM
Ah, you need using typename Variable<Tag>::ValueT;
MSVC probably missed that because it's lazier with templates.
 
Mkay, the build will start in 5 minutes, we'll see. Thanks for the help.
 
 
7 hours later…
@MartinhoFernandes "The only winning move is not to play."
 
8:13 AM
Mornin
 
Morning
 
sbi
8:30 AM
Hi. I'm grumpy. Mornin my ass!
 
How are you this glorious monday @sbi
 
sbi
@ÓlafurWaage Are you sitting on your brain?
 
Yes sir.
 
sbi
Ah. Thought so. :)
 
9:24 AM
It's 11:24 and I've gone over the cap. Cute.
 
sbi
@CatPlusPlus Cap hope?
 
9:47 AM
And personal record too, 234 rep.
 
So, your day is over now?
What's wrong with the people? They don't fucking vote?
 
@MartinhoFernandes Pretty much, yeah.
 
Gnite Cat!
Maybe their queries were just malformed.
 
10:03 AM
Maybe their <insert SQL joke here>.
 
You mean SQL injection joke.
 
* inject SQL joke
 
Oh, and btw, MySQL is a piece of garbage, which explains why it's so commonly used with PHP.
 
@MartinhoFernandes: Any further comments on my concurrent iteration scheme? :)
(no, there's no update yet.)
Oh wait, you already commented, didn't you?
must.wake.up.
 
@Fred you really need to wake up.
I haven't commented anything after we last discussed it here in the chat.
 
10:14 AM
So you see no problems with the current version?
 
Other than the ignorance of exceptions, and its sheer craziness, no, I don't see any.
 
Hm, I don't know whether that's good or bad... if there's another bug in my code, I'm sure you're the only one who would notice, and I like fixing stuff...
Why is this question so famous? 23 favorites??
23
Q: C++ Singleton design pattern.

Artem BargerRecently I've bumped into realization/implementation of Singleton design pattern for C++. It has looked in the following way (I have adopted it from real life example): // a lot of methods is omitted here class Singleton { public: static Singleton* getInstance( ); ~Singleton( );...

 
Ugh, singletons.
3
 
It's been a while since we've discussed them here, hasn't it? :)
 
sbi
I just broke through the 50k barrier.
 
10:20 AM
Did it make a sound?
 
sbi
@FredOverflow Yep, a sweet one. :)
 
Of course not. Everyone knows that sound runs at 340.
 
@sbi You mean you made a sweet sound ;)
@MartinhoFernandes 340 m/s, not 340 rep :)
 
sbi
@FredOverflow "Did it make a sound?" "Yes."
@FredOverflow "340m/s, the speed of sound in vacuum"
 
So... what kind of a sound was it?
 
10:26 AM
@sbi You're kidding, right?
 
sbi
@FredOverflow A sweet one. I already said so.
@MartinhoFernandes "Kidding" - is that where you get kids? Because I'm not planning on repeating this.
 
@Fred you know what's funny? You're abusing threads to emulate yield return. A while back I saw an article where someone abused yield return to emulate some forms of asynchronous programming.
When I get home I'll dig around and see if I can find the link.
 
Singletons, uck
3
 
@MartinhoFernandes And since that wasn't good enough, async was introduced into C# :)
 
10:35 AM
@MartinhoFernandes Thanks, I'll read it when I wake up :)
 
11:24 AM
Ugh, looking at 85 lines of C# code which could literally be written as 3 lines if the language had templates.
 
Can I see it?
 
It's basically just a bunch of function definitions, for very similar functions where just the type being instantiated and returned varies
could replace it with a single function templated on that type
 
If the type is instantiated with the default ctor, you can use generics.
Otherwise, it sucks.
 
yeah, it's not :)
that's why we have those wrapper functions, to set up the object with a handful of parameters
 
Hmm, I can't write a template in 3 lines.
 
11:27 AM
true, I'd probably normally do it in 4
 
I write template <...> in one line, then class or a function header, then one line of code, then close brace :P
 
yeah, same. I forgot to count the template<> line. 4 then!
But that's still a 20x reduction in lines of code ;)
 
@jalf a case for T4 templates? slightly more manual approach to code generation than C++ or D templates, but hopefully more maintainable nevertheless
 
Ugh, adding a whole new layer of abstraction, a separate project, a different language, and very likely more code than the 80 lines I have now. ;)
anyway, it doesn't have to be particularly maintaniable. These functions are so simple they're not going to change. Just annoying having to scroll past them in VS
 
fair enough :)
 
11:33 AM
Is there a standard preprocessor symbol that is defined when the compiler supports rvalue references?
 
sbi
@jalf Just collapse them in outlining. :)
 
yeah, not a bad idea, actually
at least if I create a region around them so I can collapse the whole thing
@FredOverflow I doubt it.
 
Well, at least there is __GXX_EXPERIMENTAL_CXX0X__ on g++...
 
@FredOverflow yeah, but that says nothing about rvalue refs specifically, does it?
 
0
Q: stealing inside the move constructor

FredOverflowDuring the implementation of the move constructor of a toy class, I noticed a pattern: array2D(array2D&& that) { data_ = that.data_; that.data_ = 0; height_ = that.height_; that.height_ = 0; width_ = that.width_; that.width_ = 0; size_ = that.size_; tha...

@jalf Right, and it also does not work with any other compilers :(
 
11:50 AM
how generic do you need it to be? It should be fairly straightforward to hack one together which works for specific compilers
with MSVC just check if _MSC_VER >= 1400 (I think that's VC10's version id), with GCC, check for the macro you mentioned, and version >= 4.3
I think clang has some fancy scheme for querying specific features in the preprocessor too
 
0
Q: Assigning string literals to char*

FredOverflowIs the following code legal, deprecated or illegal in C++0x? char* p = "foobar"; I originally asked this question here as a comment.

 
ah, __has_feature(cxx_rvalue_references) and __has_extension(cxx_rvalue_references) should both work for clang
 
@jalf: MSC_VER is 1600, I think, for MSVC10
 
ah yeah, that sounds about right
 
@jalf What would be the difference between the two?
 
11:58 AM
the clang ones?
or msvc versions?
 
@jalf The clang ones :)
 
as far as I can figure out from clang.llvm.org/docs/LanguageExtensions.html, the first one checks for support for a standardized feature, and the second one checks if it's supported as either a standardized feature or a language extension
sounds like both should work in this case then
> "Use __has_feature(cxx_rvalue_references) or __has_extension(cxx_rvalue_references) to determine if support for rvalue references is enabled."
 
@jalf: I think I'll ask a proper SO question, then you can gain some rep ;)
 
aw but then I have to write a SO answer and everything
also, I just googled 'clang rvalue references', and that page was one of the first hits :p
 
@jalf too late ;)
0
Q: Conditional compilation for move operations

FredOverflowHow can I check whether my compiler supports rvalue references or not? Is there a standard preprocessor macro, or do different compilers have different macros? Ideally, I would want to write this: #ifdef RVALUE_REFERENCES_SUPPORTED foobar(foobar&& that) { // ... } #endif

Oh oh, someone just said the following about arrays and pointers:
> ...which in C & C++ are essentially the same thing.
Burn the witch! :)
3
-1
A: Assigning string literals to char*

Waheed KhanThis is legal and it does works ..you can also use char[] p = "foobar" ..

 
12:08 PM
FAIL
 
Finally! A freaking upvote!
I thought I was going to end the day with less rep than when it started.
 
ooh, tempting to downvote you now :D
2
 
> Naming a macro _MOVE is not a good idea, because identifiers starting with an underscore followed by an upper-case letter are reserved for the implementation. – FredOverflow 15 mins ago
> Naming a macro MOVE__ is not a good idea, because identifiers containing two consecutive underscores are reserved for the implementation. (SCNR) – sbi 5 mins ago
@sbi: LOL
 
12:29 PM
@jalf Oh, I can compare values in the preprocessing stage like _MSC_VER >= 1600? Didn't know that :)
 
yeah
 
But I can't compare strings, right? Stupid :(
LOL, we have a codegolf stackexchange? :)
61
Q: Challenge: Programmatically detect whether code is compiled with C++03 or C++0x

It is possible to write a function, which, when compiled with a C compiler will return 0, and when compiled with a C++ compiler, will return 1 (the trivial sulution with #ifdef __cplusplus is not interesting). For example: int isCPP() { return sizeof(char) == sizeof 'c'; } Of course, th...

> Code golf is a special type of programming puzzle where the shortest correct code submission wins.
The question doesn't really seem to fit on codegolf, does it?
 
sbi
12:46 PM
@FredOverflow Shall we all login to codegolf.SE and bounce it back to SO? :)
Ah, I don't have enough rep there to do that.
Well, I flagged it at both sites as "should not have been moved to codegolf". Let's see if this helps.
Criticizing Jeff (again) probably will hurt my flag weight. <sigh/>
 
sbi
1:20 PM
@Xeo: Thanks for fixing my broken code!
 
1:31 PM
@sbi I don't even have an account there...
I stopped at 3 or 4 I believe...
 
@Fred @sbi The site's title reads "Programming Puzzles & Code Golf"
 
Aha!
 
sbi
@FredOverflow I created one just to flag the question. :)
 
Maybe my concurrent iterator fits better on codegolf then? :)
@sbi lol
 
sbi
@MartinhoFernandes But is this a puzzle? I think it's unfortunately worded, but otherwise it could well be a very common C++ question on SO.
 
1:33 PM
I'd also rather have it at SO.
I think the "Challenge" in the title misled people to migrate.
 
Every C++ question is a challenge in itself, isn't it? :)
4
 
Is that sixlettervariables guy is a TINWCD sock puppet?
 
1:48 PM
gtz
hmm, stupid chat system, stops scrolling
 
sbi
@MartinhoFernandes I don't think so.
 
Well, he sure seems impossible to reason with.
 
sbi
2:03 PM
@MartinhoFernandes Unfortunately, there's more than one such person on this planet. :(
 
2:23 PM
Especially in the regex tag, I'm starting to downvote answers that are nothing but code.
Man, those are not helpful at all.
 
hey, anyone know of a "C++ for C programmers" type of material? I've been using C++ for a year now (with Qt) but I always fall back to C stuff. I've never even used the STL (Qt has similar stuff, so I use from it)
 
Well, avoid doing things in C :)
Everytime you feel the urge to do things in C, don't. Go look around the STL reference.
And check this one out:
531
Q: The Definitive C++ Book Guide and List

grepsedawk This question has historical significance, but is not a good example of an appropriate question. Read and learn from this post, but please do not use it as evidence that you can ask similar questions. See the FAQ for more info. Provide QUALITY books and an approximate skill level. Add ...

 
From having learnt C++ after having learnt C (also doing projects with C) I don't think there's a particular modus operandi. There's nothing much to remember from C tbh, might as well start from scratch.
 
The sole thing I leveraged from learning C before C++ was my skill with pointers.
2
 
Ah; good point here
 
2:28 PM
And, to some extent, the preprocessor.
 
I do a lot of microcontroller programming and more often then not i have to hack the linux kernel, so I can't simply abandon C :P
 
You don't have to abandon C. It's not like C is going to kill you.
 
By 'start from scratch' I meant 'consider C++ a completely different language' (which it is)
 
When you're coding C++, you can't think like your coding in some fancy C.
 
I can't remember a single C idiom that is used in C++
 
2:29 PM
Both have a main function!
 
Arrays[] maybe?
 
Nope
 
You don't want to use arrays in C++. You want to use std::vector.
 
And those aren't idioms :)
 
and for statically allocated arrays, there's std::array
 
2:30 PM
What idioms does C have?
 
goto for cleanup
 
Your-gonna-seg-fault idiom
 
int return for error handling + in parameters
void* for callback arguments
 
Both of which are damn fugly.
 
format string + varargs
 
2:32 PM
It seems every C idiom is ugly :)
 
@LucDanton TBH printf-style strings are probably the best.
 
@MartinhoFernandes Boost.format
 
Perhaps not so much an idiom than a convention in some of the works I have done: pointers to non-const for owned pointers, pointers to const for non-owned pointers in some contexts
 
Oh, I meant, the best of C idioms.
And boost.format is not in the stdlib :P
 
@MartinhoFernandes I'm listing some C idioms I remember. They make total sense in the C world and in fact I remember them from having used them. So no judgement on my part here :)
 
2:35 PM
@MartinhoFernandes So what? It's still C++.
 
Also opaque types that contain a pointer to a table of function pointers (dun dun dun)
 
@LucDanton You mean, handwritten vtables?
 
@LucDanton I think it's fair to say then that I do know C++ better than C.
 
Also discriminated unions
static inline
It's all coming back to me!
 
Take care that it doesn't overtake you.
I hate it when I post an answer and then later figure out I made a mistake in it, yet no one noticed it and several people upvoted.
 
2:41 PM
phew close
wrong window :)
 
amazon.com/dp/0321334876/?tag=stackoverfl08-20 Is this really that good? Should I invest? I live in Brazil, so S&H is probably gonna cost more than the book :P
 
IMO it's a bit dated, but in a good sense
By 'in the good sense' I mean that the advice in it is still relevant, but it has disseminated around so it's somewhat common sense by now
 
3:09 PM
@hexa Effective C++ is the best second C++ book there is.
 
whats the 1st?
 
You mean best second, as in, best book to read after reading one?
Or second best, as in, there is only one that is better?
 
Yes, exactly. You should not read Effective C++ as your first C++ book. It assumes you already know C++.
@hexa Depends on whether you already know how to program.
 
I know a bit of C++. I don't know much of the STL tho'
 
What is the best assuming you do not know how to program?
 
3:11 PM
If you're completely new to programming, I suggest:
 
I'm not completely new at all
 
@FredOverflow Accelerated C++ helped me to get started with C++.
 
@StackedCrooked what language you programmed in, before C++?
 
@hexa As a student I had used C# and Java for some projects.
 
4:04 PM
0
Q: Mixing operator new[] and placement new with ordinary delete[]

FredOverflowJust out of curiosity, is the following legal? X* p = static_cast<X*>(operator new[](3 * sizeof(X))); new(p + 0) X(); new(p + 1) X(); new(p + 2) X(); delete[] p; Is new[] just syntactic sugar for operator new[] followed by placement-new, or is there more to it? Similarly: X* q = new X...

 
That's horrible :(
 
I'm tempted to upvote because it's an interesting question.
 
@LucDanton What exactly is horrible about it?
 
But I'm tempted to downvote because it burns my eyes.
 
@MartinhoFernandes Why else would you upvote a question, if not because it was interesting? :)
 
4:12 PM
@FredOverflow Not matching operator new[] with operator delete[] and the new[] operator with the delete[] operator
 
I don't mind upvoting "bland" questions that are well-asked and show research effort.
2
 
I see. That happens very rarely here. I mostly upvote what I find interesting.
 
OTOH, I will quickly downvote questions that show a clear lack of googling.
Ok, I guess it doesn't deserve a downvote just because the answer is "If you wanna live, don't do that in code I have the slightest chance of ending up maintaining."
 
@Fred That's some ungodly piece of code, but it's still an interesting question.
 
@FredOverflow Strike one :)
Oddly enough I'm not so confident the second case is forbidden!
 
4:27 PM
Anyone feels prepared to formulate on the Move assignment operator for this beautiful FAQ Q&A?
Would be worth a mention. Possibly incrementing The Big Three (really?). Although I believe it deserves its own Q&A, if there's not one already - didn't check.
sigh I should've read the answer to the bottom :) Move Op is already there.
 
4:50 PM
@sbi: Hola!
 
so my dev team getting an experienced C++ guy on team... we're exclusively C#. Has anyone else made that sort of transition?
 
expect him to be annoyed with how much C# sucks :D
 

« first day (254 days earlier)      last day (4699 days later) »