« first day (573 days earlier)      last day (4372 days later) » 

12:00 AM
@CatPlusPlus you mean catnip don't you? kittens are so cute when they're high
 
@CheersandhthAlf I'd like that people with 24k rep won't advise to use such macro, ever
 
@stdOrgnlDave We (that is, the programmers that I identify with) like centralized solutions. Not solving each function ad-hoc. But solving all of them in one simple, fell swoop. Or swell foop. Whatever. Do you understand this principle?
 
it's like goto cleanup to me
 
@stdOrgnlDave Well, alcohol is a drug, too. I think.
 
@Abyx what do you think is problematic about the macro? and don't say multiple evaluation of argument, that's not a practical problem. or, it's never been a problem.
 
12:01 AM
@CheersandhthAlf I fail to understand why a header file containing two specialized templates and 20 or so overloads isn't "one fell swoop"
 
@stdOrgnlDave do you understand that the set of functions is unbounded?
 
geeze
 
@CheersandhthAlf the set of std:: functions?
 
@stdOrgnlDave the set of functions taking a pair of iterators rather than a range object?
 
what's more relevantly problematic is that they are not function objects, but regular functions
 
12:03 AM
oh, so you're saying you want to be able to replace EVERYONE's code EVERYWHERE that wrote it for iterators
I just thought your ambition was STL
or rather, the standard library
 
You know what's the worst part.
We still have vodka.
 
template<typename F, typename T, typename Args...>
void range_algorithm(F&& f, T&& t, Args...&& args) {
    f(std::begin(t), std::end(t), std::forward<Args>(args)...);
}
 
@stdOrgnlDave i've already noted that i'm angry with certain morons. but i forgive you for trying to misrepresent me. it's just too dumb, more like laughable (if i wasn't so angry)
 
@DeadMG that is the trivial C++11 type of stuff we were dismissing as impossible
 
@CheersandhthAlf the problem is that you think it's OK to use text replacing, just to "reduce code size"
 
12:04 AM
@stdOrgnlDave Because it is.
 
@DeadMG that's C++11?
 
it only works if std::sort is a function object with overloaded operator()
 
@Abyx did you know, the standard library does just that. like, assert. or errno
 
but since it isn't, you can't
 
@SerenityStackHolder yes, variadic templates
@SerenityStackHolder and perfect forwarding
 
12:05 AM
the only way to use such a thing would be to explicitly pass &std::sort<T,Pred>
 
Thanks, @johnathon
 
@SerenityStackHolder and rvalue references
 
Any C++03 reference on that?
 
@DeadMG you can take std::function as an argument and it will take things like std::sort
 
@CheersandhthAlf assert uses __FILE__ and other stuff
 
12:06 AM
@SerenityStackHolder what do you mean?
 
@stdOrgnlDave You can't pass std::sort directly- it has to be an explicit instantiation.
 
Are FILO stacks typically indexed with 0 being the most recently-pushed value?
 
@SerenityStackHolder C++03 reference on what- all the stuff that's new in C++11?
 
is it applicable to c++03 standard? @johnathon
 
@DeadMG ...except for the fact that you can with std::function...unless when I did almost exactly that I was hallucinating
 
12:07 AM
@SerenityStackHolder Uh, because it's new C++11 stuff, then no.
 
@SerenityStackHolder no. All that stuff is new to c++11
 
I see, I had to ask.
 
@SerenityStackHolder minus the fact it's a template
 
What does F&& means?
 
@SerenityStackHolder thats an RValue reference
 
12:07 AM
F&& f is the same as F f?
 
rvalue reference
 
@SerenityStackHolder
75
A: Advantages of using forward

GManNickGYou have to understand the forwarding problem. You can read the entire problem in detail, but I'll summarize. Basically, given the expression E(a, b, ... , c), we want the expression f(a, b, ... , c) to be equivalent. In C++03, this is impossible. There are many attempts, but they all fail in so...

 
In computer science, a value is an expression which cannot be evaluated any further (a normal form). The members of a type are the values of that type. For example, the expression "1 + 2" is not a value as it can be reduced to the expression "3". This expression cannot be reduced any further (and is a member of the type Nat) and therefore is a value. The "value of a variable" is given by the corresponding mapping in the environment. In languages with assignable variables it becomes necessary to distinguish between the R-value (or contents) and the L-value (or location) of a variable. In ...
 
@Abyx no, it doesn't necessarily use those things. and no, it's not a relevant argument. and yes, it's plain moronic to not use a macro when it's a good tool for the job, just because it's a macro.
 
12:08 AM
haha
GCC produces an ICE
 
@CheersandhthAlf I think you'll find macro hate on SO is a bit higher than is reasonable.
 
@GManNickG macros == evil. TRUE. Nuff said?
 
@CheersandhthAlf why do you think "it's good tool" ? because you write less code with it?
 
12:09 AM
I use macro's to generate repetitive code all the time, though I try to limit such use to specific translation units, but sometimes it's not possible (templates).
 
nice explained, @GManNickG :)
 
@GManNickG Macros are terrible and hideous. The only excuse for using them is that templates aren't as powerful as they should be... which may well be applicable in this case.
 
@johnathon It's a fine guideline, but at some point people do have to reach that "know what you're doing" stage, and at that point you'll find macro's can be used to solve problems of code repetition.
@DeadMG Sure. You've merely said "never use them except when you need to use them", but that surely applies to everything.
 
@Abyx yes, and because it abstracts up the intended concept. instead of translating your intention to a sequence of details, you write what you mean. that's much of the whole point of higher level languages, from the time rear admiral Grace Hopper developed the first one, a precursor to Cobol.
 
@CheersandhthAlf why don't you use #define begin .begin(), or #define call ();?
 
12:12 AM
@GManNickG Belive me when i say i know. I do a lot of win32.. and WTL .. macro's everywhere. But the issues with macros are far deeper than the fact that they save you code repetition. They lack a proper type system, and that alone is a fundemental flaw with their design than anything else that i can say about them
 
@GManNickG I would say that more relevantly, I established a specific priority, being that they are worse than virtually any other language feature, and defined "when you need to use them" as the smallest amount possible. Unlike, say, RAII, where I would say "Use in preference to other features".
 
@CheersandhthAlf btw, how do you find sort(all_of(new foo)); ?
 
@Abyx regarding the first, it's better with a template function. i used to advocate such function. until C++11 delivered std::begin.
Your idea of using a macro for that is dumb.
 
@Abyx What's the new doing here?
 
Macro is not necessary and it's lowercase so easily problematic, it is a moron's macro.
 
12:13 AM
@DeadMG operator new, you know it
 
@GManNickG , you have got some really nice biography here. :)
 
Win32 and macros... oh man... so many macros.
 
@Abyx I'm vaguely familiar with it. Why on earth is it in the middle of an algorithm invocation?
 
@dreamlax tell me about it
 
@CheersandhthAlf it's not about casing.
 
12:14 AM
@Abyx you don't because it'll make multiple new foo's and error out on you
 
@Abyx it would be ok, if there was a standard overload of sort for that. it's what i generally do. but it's a hassle for every new funciton
 
@johnathon: And then of course, there's COM
 
or perhaps NOT error...
 
@dreamlax COM ain't that bad. As long as you're only calling the COM interface and not providing it.
 
@johnathon I'm well aware of their deficiencies, but we live in a world where deficient solutions can be better than no solutions.
 
12:15 AM
@dreamlax COM is no where near the horrible abomination as some people point out, As long as your a consumer of com that is
 
@SerenityStackHolder Thanks.
 
@Abyx it is also about casing. saying it is not betrays a lack of insight and experience, or plain trolling. lowercase macros can easily collide with other names, while uppercase ones shout (so must be weighted against advantages).
 
ok, let it be sort(FOOLIB_ALL_OF(x.get_arr_by_value()));
 
@GManNickG Such a point is true, however in general, macro's are evil.
 
anyway this flamewar is one of the stupidest ones I've ever participated in and I used to be a console fanboy in another life. neither side even cares that a solution literally stares them in the face. oh well, I'm rage quitting for the next hour or so, I hope you kiddies have it sorted out by then
 
12:16 AM
@Abyx that's the macro you downvoted, except it had a better name
 
@johnathon Which goes back to what I said: fine guideline, but we have to learn to recognize when a deficient solution is the best solution.
 
@DeadMG @johnathon I like what COM can do but honestly, some things that you'd expect to be trivial in COM are terrible. I wanted to add a context menu item to a printer's context menu and there was about 500 lines of generated source code, a lot of which was macros that I had absolutely no idea what they did
 
@CheersandhthAlf do you see anything wrong with that code?
 
@dreamlax wich goes back to what was said earlier, if your a consumer of com, not an implementer, then it's not that bad
 
@Abyx yes, the function get_arr_by_value is badly named. the name should instead involve the word copy.
 
12:18 AM
@johnathon: Oh sorry I see what you're saying now
brb, going to get my lunch, a delicious chicken char kuey teow
 
@CheersandhthAlf so it's OK that get_arr_by_value() will be called twice?
ah... sort(FOOLIB_ALL_OF(x.get_arr(++i))); - that's even better
 
@Abyx it's your code so you have to ask yourself. how the fuck should i know whether your imaginary function is safe to be called twice here?
 
You should write Haskell
 
Are you constructing example of imaginary goof-ups to sort of associate something negative with the macro approach?
 
@CheersandhthAlf but wait, why do you think it will be called twice?
 
12:20 AM
Lemme tell you, it has never been a problem except for novices.
@Abyx I didn't, you did. Please turn on the other neuron also.
 
what the, facebook is in Spanish now? Last time I let my fiance touch my computer
 
Everything is nice.
 
@CheersandhthAlf "except for novices"? who will read your answer?!
 
@CheersandhthAlf me, abyx, or all of us?
 
 
12:23 AM
@Abyx they need to deal with other dangerous stuff too. like string literals. pointers. booleans that aren't. down-conversions.
 
@CheersandhthAlf it's not "dangerous", it's unreliable crap, by design. Your ALL_OF looks like a function, but it's not a function. And no one knows when it's safe to use it, unless they look at its implementation.
 
I think I shouldn't answer questions now.
 
@Abyx it does not look like a function: it has an UPPERCASE macro name, it looks like a macro. it's not something anyone competent uses without knowing what it does. looking at the implementation is how you know what it does. it truly, truly dumb to think it's better with a verbal description.
 
brawlers
 
12:29 AM
Sorry for saying you are dumb. The evidence does not support that. In that respect you won, I exploded. Sorry. Your statements are dumb, but I do not know that about you. Again, sorry.
 
@CheersandhthAlf, just imagine that you see a code written by your colleague foo(BAR(x[i])); ++i;. Is it OK to refactor it to foo(BAR(x[i++])); ?
 
@Abyx that's obfuscated code. it is probably not a good idea to touch it at all.
is your point that macros can be used to obfuscate?
so can operators, pointers, nearly anything.
it is not an intelligent argument.
 
@CheersandhthAlf why it's obfuscated ? because of foo and bar?
 
@Abyx re "why": i think you obfuscated it just to be able to make it seem like it supported some argument.
 
12:34 AM
Can you reliably refactor code where you don't know what each function/macro involved does?
 
@CheersandhthAlf, ah... forgot it. I just believe I'll never maintain your code, and I hope you won't teach noobs such things again.
 
You can't refactor code you don't know, refactoring is changing code without changing visible beahviour.
 
or we just will downvote your answers with such scary practices
 
So knowing whether foo(BAR(x[i])); ++i; can be refactored into foo(BAR(x[i++])) isn't a question about macro "safety" really
 
@dreamlax what about foo(bar(x[i])); ++i; ? do you need to know its implementations?
 
12:38 AM
@Abyx To be honest (and impartial), if I saw that, I wouldn't blindly change it to foo(bar(x[i++]));. If it was separated, it was probably so for a reason.
 
@Abyx: I still wouldn't know, if the author of the code followed the traditional convention of having uppercase macro names then you could to some degree assume that both foo and bar are functions
 
@Abyx yes. the original code has a sequence point before i is incremented, while the proposed refactoring does not. if i is referenced it can incur UB.
 
@CheersandhthAlf referenced where? inside foo or bar?
 
I see... int i; int main() { ...; foo(bar(x[i])); ++i; .. } another good practice
 
12:42 AM
probably more likely such referencing occurs via arguments, not via globals or pointers.
 
there are no other arguments.
 
@Abyx i was talking about the general case, as were you with your example that i responded to. it is a bit difficult to follow all the context switching.
Anyway, @Abyx, have you ever used the Boost library or, say, a unit test framework?
 
@DeadMG I have seen your post about CRTP and I am interested in one thing, when I create some virtual function in base class and I don't override that function in my derived class, in what way the process of inheritance is going there?
 
Coincidentally, I'm using a macro right now in some code I'm writing. Living on the edge.
 
12:47 AM
btw, it would be good question for P.SE, "if it's OK to #define f(x) a(x), b(x)"
@CheersandhthAlf yep, I did
 
I think I was writing a module in C for PostgreSQL, there were a lot of macros involved to ensure functions were declared properly, macros to declare pg types etc... I can't say I enjoyed it, but I'm not sure I would have enjoyed the macro-less version either
 
@Abyx OK. Did you notice the abundance of macros in those libraries?
 
@CheersandhthAlf macros for __FILE__, #, ##, and other stuff?
 
hij
hijk
 
12:48 AM
or BOOST_PP_*? I saw that.
 
Guys. Macros are here.
For a reason.
Get over it
 
and you know what? there is no #define f(x) a(x), b(x) .
 
there is no spoon?
2
 
@Abyx I meant other than for picking up text. Convenience macros. There is a whole sub-library in Boost to support them, the Boost Preprocess Library.
 
@Abyx Of course there is: it's right there in the chat
 
12:50 AM
And for example, nearly all usage of the Boost Parameters Library is through convenience macros.
Have you encountered any of that?
 
@sehe in boost...
 
@Abyx I wouldn't be surprised if there is. It is a so called syntax macro. And it's nearly the main example of that category.
 
@CheersandhthAlf it's OK to use good safe macro when you can't avoid'em. But it's not OK to use ALL_OF(x) begin(x), end(x). It's different things.
 
Is it possible for a compiler to detect expressions with side-effects being used in macros? I know that the preprocessor does the macro expansion and the compiler itself won't be able to tell without some sort of communication between the two...
 
I would use ALL_OF if the following conditions hold: I'm going to be typing a lot of begin(x), end(x) in a scope, the macro is defined and undefined within that scope, and if after trying it out it reads better (doesn't require me to adjust the code to use the macro in a straightforward manner).
 
12:55 AM
uhm... I'm going to sleep. @CheersandhthAlf you won. I agree with anything you say, just please when you'll make an answer like that, post link here.
 
user406009
@dreamlax I could almost swear there was a gcc extension to deal with this.
 
Maybe if macros had to be invoked with different syntax (to make it obvious that it is a macro and not a variable/function)...
too late for that though
 
@Abyx Here's another example of a syntax macro:
#define BOOST_RANGE_ARRAY_REF() (&boost_range_array)
And
#define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef )                         \
    template< typename C >                                                     \
    struct extract_ ## a_typedef                                               \
    {                                                                          \
        typedef BOOST_DEDUCED_TYPENAME C::a_typedef type;                      \
    };
 
 
What's wrong with them, or why do they not suffer from what you think is wrong with ALL_OF?
 
1:03 AM
^ it's about me
 
Hi! @CatPlusPlus
 
@CheersandhthAlf nothing wrong with'em. it's just a different case
9 mins ago, by Abyx
uhm... I'm going to sleep. @CheersandhthAlf you won. I agree with anything you say, just please when you'll make an answer like that, post link here.
 
Good night, @CheersandhthAlf .
Good night, guys.
 
1:24 AM
Gnight
 
Anyone know an assembly language?
 
I know some x86.
 
Bleuch... too much MSG in my lunch...
@Maxpm: I know a little x86, and a little PPC
 
When a value is popped from the stack, is it stored anywhere? I ask because dup is often described as popping once and pushing twice, which seems contradictory because pop is described as simply discarding the topmost value.
 
What's MSG?
 
1:29 AM
MSG = monosodium glutemate, a.k.a. Chinese gourmet powder
 
@Maxpm There's a dup in x86?
In x86 a pop takes a register argument.
 
@RMartinhoFernandes I don't know. I'm specifically looking at the Java bytecode opcode list.
 
@Maxpm some x86, PDP-11, 6502, MC68000, and some
 
@RMartinhoFernandes Ah, I see.
 
There's a dup in .NET IL, and it basically push the top stack value
@Maxpm Oh, yeah, that's similar to .NET's. There are no registers in the JVM, and that's why you have dup, and why pop just discards the value.
 
1:32 AM
Java bytecode gives you a handful of "local variables," which I suppose correspond to registers in native code.
@RMartinhoFernandes I see. Thanks.
@RMartinhoFernandes The total number of registers depends on the specific processor model, right?
 
Now I see where some of the asm platform-dependency comes from. That's interesting.
I find low-level programming fascinating, but I know very little about it.
 
hey there. has that flamewar died down yet?
 
Hi all. I have a little question about float precision.
fs << x;
if x = 2,23 for example, than I get 2.2300000190734863e+00. Can't fix this.
fs is a openCV FileStorage instance (stream to file)
 
Right. There's nothing you can do about that.
 
1:43 AM
use sprintf to format it better
 
I've tried:
fs << boost::lexical_cast<std::string>( x );

It helped, but not very much: "2.23000002"
 
use sprintf to format it better
 
I imagine not.
 
@stdOrgnlDave format a string and output a string?, Ok. I'll try this
 
You could use some kind of bignum library.
 
1:44 AM
@Innuendo: Floating point numbers are not exact
 
Or store the decimal number as two ints.
 
Lemme add a bit of pedantry: floating point numbers are exact.
 
Well, one int and one unsigned int.
@RMartinhoFernandes ...But they can't represent every decimal number, right?
 
Obviously.
 
So I need to format a string and cut it. I don't need the exact precise number. I log a matrix to file (30x30), and if numbers are written short - it takes a screen, and I can see the whole matrix ;)
 
1:46 AM
Well yes, they are exact once the number is already converted to a floating point type
 
There's infinite number of decimal numbers.
So no
 
are you familiar with sprintf? I can demonstrate usage
 
@Innuendo Yeah, truncation is probably the best option in your case.
 
@Innuendo Will std::setprecision fulfill your needs?
 
@stdOrgnlDave Why so C?
 
1:47 AM
@stdOrgnlDave I've used sprintf before. I've just tried, but Segmentation Fault occurs ;((
 
@Innuendo: If you get a segmentation fault using sprintf then you are using it wrong.
 
@dreamlax I understand this))
 
> foldl pancakes
lol
 
char buf[10];
int n = sprintf(buf, sizeof buf, "%.2f", x);
Although, in C++ you should "probably" use the stream manipulators instead
 
fs << std::fixed << std::setprecision(2) << x; I believe.
Um, should probably be something like std::setflags(std::fixed) come to think of it.
 
1:51 AM
Don't forget to #include <iomanip> or whatever the header is
(or is that not necessary?)
 
I think those manipulators come for free. They're a shorthand for using the member functions after all.
 
Hard drives are strangely beautiful.
Like a positronic brain.
 
char* str = new char[30];
float flt = x;
sprintf (str, "%.3g", flt);
fs << str;
this worked! ;) Thanks to all
 
Great, someone suggested sprintf and now we all feel queasy.
 
@LucDanton It must be a macro, else it's not low-level enough.
 
user406009
1:54 AM
snprintf > sprintf at least.
 
@Innuendo just use a std::string to hold that char buffer
 
@CheersandhthAlf Heh, I've never heard that line of thought before.
 
Hard drives are annoying. It's part of my job to diagnose and repair/replace them in people's laptops
 
Is there any way to pass std::sort or similar template around?
Apparently not as template parameter
And not as actual argument
 
@CheersandhthAlf I've tried.

error: cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘char*’ for argument ‘1’ to ‘int sprintf(char*, const char*, ...)’
 
1:56 AM
And most laptop owners I encounter have absolutely no idea why backups are important
 
@CheersandhthAlf Writing a full polymorphic functor :/ Mighty inconvenient.
 
@CheersandhthAlf thank you! =)
 
1:57 AM
&s[0] is only guaranteed to work on C++11 isn't it?
 
@LucDanton And it can't be genericized...
 
std::string buffer( 30, ' ' );
sprintf( &s[0], "%d", 42 );
@dreamlax it's only guaranteed to work if string has at least one element, size > 0
contiguous buffers for basic_string was introduced at meeting at Lillehammer in 2004 I think it was
but then only because it was already an in-practice guarantee
 
@dreamlax I don't really have anything worth backing up. The vast majority of my games are on Steam; the vast majority of my coding projects are either hosted somewhere or are not worth backing up.
Music, maybe.
 
@CheersandhthAlf: I was told earlier when I tried to do this exact thing that in C++ versions prior to C++11 there was no guarantee of contiguous storage but they added it in C++11 because all mature implementations already supported it
 
@Maxpm Can't you just rip or download it again?
 

« first day (573 days earlier)      last day (4372 days later) »