|
VikingofRock posted:Actually wait why doesn't this work? This form doesnt allow compiler to deduce Iter from callsite
|
# ? Dec 2, 2016 09:02 |
|
|
# ? May 22, 2024 16:34 |
Xarn posted:This form doesnt allow compiler to deduce Iter from callsite Oohhhhh gotcha. Thanks.
|
|
# ? Dec 2, 2016 10:38 |
|
Slurps Mad Rips posted:
oooh so that's what it's for Slurps Mad Rips posted:you can then turn that enable_if into a macro: in my experience, macros and templates don't mix
|
# ? Dec 2, 2016 10:42 |
|
god c++ is so freaking ugly
|
# ? Dec 2, 2016 10:59 |
|
c++'s foundation is No New Syntax a clearer syntax could break compatibility with c and old code but, way more serious, it could break some clever trick someone came up with it's sunk cost fallacy applied to language design
|
# ? Dec 2, 2016 11:04 |
|
Slurps Mad Rips posted:you can then turn that enable_if into a macro: #define REQUIRE(...) std::enable_if_t<__VA_ARGS__, int> = __LINE__ The macro approach is nice in my opinion, even though we're supposed to hate macros. It has a limitation, though, in that the condition passed to the macro must be related to a template parametre, otherwise it doesn't count as a substitution failure. This is relevant when you want to e.g. disable a member function in a class template depending on template parametre, but can be solved like this: C++ code:
However, I've noticed that 99% of the time I use something like this, it is for checking type traits, so I made an alternative like this: C++ code:
C++ code:
Also, ##__VA_ARGS__ is not standard, but seems to be available in all common compilers (at least Clang, GCC, MSVC). My brain must be a bit broken because I think template meta-programming is actually fun. Nehacoo fucked around with this message at 11:46 on Dec 2, 2016 |
# ? Dec 2, 2016 11:23 |
|
Nehacoo posted:It has a limitation, though, in that the condition passed to the macro must be related to a template parametre, otherwise it doesn't count as a substitution failure. you fuckre that was my next post
|
# ? Dec 2, 2016 11:33 |
|
if nothing else, I was successful in bringing out all the c++ victims out of the woodwork. I never knew you were so many!
|
# ? Dec 2, 2016 11:37 |
|
hackbunny posted:you fuckre that was my next post hackbunny posted:if nothing else, I was successful in bringing out all the c++ victims out of the woodwork. I never knew you were so many! Victim? I chose this for myself!
|
# ? Dec 2, 2016 11:38 |
|
c++ is a terrible practical joke gone wrong
|
# ? Dec 2, 2016 12:25 |
|
redleader posted:c++ is a terrible practical joke gone wrong It's good
|
# ? Dec 2, 2016 12:38 |
|
I wouldn't call it "good", but there isn't anything in the world like it
|
# ? Dec 2, 2016 13:07 |
|
holy lol c++ is even more dogshit than I thought i didn't even think that was possible
|
# ? Dec 2, 2016 14:15 |
|
BiohazrD posted:holy lol c++ is even more dogshit than I thought cool wrongpinion you have there C++ is art
|
# ? Dec 2, 2016 14:17 |
|
leper khan posted:C++ is fart
|
# ? Dec 2, 2016 14:21 |
|
I deeply agree with this post from the other thread:Sapozhnik posted:C++ is a tool for turning imaginary problems into real ones. with that said, I love hackbunny's posts
|
# ? Dec 2, 2016 14:37 |
|
too weird to live, and too rare to die
|
# ? Dec 2, 2016 14:57 |
|
To be a bit more serious, all this crazy meta programming stuff we've been doing over the last few pages is not what 'normal' C++ code looks like (this is more like low-level generic library code). No one seriously thinks the current methods for doing this stuff are desirable. There has for a long time been a proposal for a more sane and readable compile-time pattern matching system called concepts. It's supposed to make all template code clean, readable, give short and precise error messages, make sure template code is valid for all types it can be instantiated with, cure cancer, end all wars, etc. However the committee cannot agree on how it should work so it will never make it into the standard, probably, but here's hoping for C++20 In the meantime, this is what we can do, unless we drop the whole compile-time meta-programming thing and do everything with runtime polymorphism like in other OOP languages. But that sucks because it requires dynamic allocation of objects (which is slow), vtable lookups (which easily causes branch misprediction), and indirection everywhere (which takes a steaming dump on data locality and thus performance). And that approach is closer what C++ was originally designed for, I believe. The template meta-programming stuff was accidental and discovered afterwards, concepts is supposed to replace it with an intentionally designed system.
|
# ? Dec 2, 2016 15:52 |
|
Nehacoo posted:To be a bit more serious, all this crazy meta programming stuff we've been doing over the last few pages is not what 'normal' C++ code looks like (this is more like low-level generic library code). yeah this is getting deeply into 'don't do that it's gross'' mode but one of the problems with c++ is that it's so easy to just do a little tmp and next thing you know
|
# ? Dec 2, 2016 16:26 |
|
Nehacoo posted:In the meantime, this is what we can do, unless we drop the whole compile-time meta-programming thing and do everything with runtime polymorphism like in other OOP languages. But that sucks because it requires dynamic allocation of objects (which is slow), vtable lookups (which easily causes branch misprediction), and indirection everywhere (which takes a steaming dump on data locality and thus performance). And that approach is closer what C++ was originally designed for, I believe. The template meta-programming stuff was accidental and discovered afterwards, concepts is supposed to replace it with an intentionally designed system. Please don't take this as a personal attack but this is a perfect microcosm of the raging stupidity that begat ~*modern c++*~ If you're writing a numerical kernel or whatever that cares so deeply about performance that the behaviour of your branch predictor is a consideration (real time trading, codecs, the very innermost loops of a game engine), then the last thing you are going to want to do is poo poo out a bunch of insane template voodoo that is about five layers of impossible-to-mentally-model semantics removed from the metal. You're going to write raw C with raw memory accesses, vector intrinsics, and lots of compiler-specific pragmas and annotations. You are going to tailor it for one precise compiler, operating system, CPU target because your algorithm is business-critical and your particular choice of Xeon silicon is a real physical object that can execute the code and the phonebook sized printed C++ standard is not. And of course this is going to be a tiny part of your code. There is no situation ever where micro-optimizing, say, your configuration file parser is a good idea.
|
# ? Dec 2, 2016 16:32 |
|
Nehacoo posted:No one seriously thinks the current methods for doing this stuff are desirable. There has for a long time been a proposal for a more sane and readable compile-time pattern matching system called concepts. you mean, two (three?) competing and completely different proposals. and the worst one is gaining the most ground because it's the easiest to implement using the current metaprogramming hell and a sprinkling of compiler magic meanwhile, on planet stroustrup: wouldn't it be cool if we could overload operator.??? no bjarne, it wouldn't
|
# ? Dec 2, 2016 16:41 |
|
Sapozhnik posted:There is no situation ever where micro-optimizing, say, your configuration file parser is a good idea. Actually,
|
# ? Dec 2, 2016 17:00 |
|
hackbunny posted:you mean, two (three?) competing and completely different proposals. and the worst one is gaining the most ground because it's the easiest to implement using the current metaprogramming hell and a sprinkling of compiler magic There are three now? Goddamit. Which one is winning?
|
# ? Dec 2, 2016 17:08 |
|
Sapozhnik posted:Please don't take this as a personal attack but this is a perfect microcosm of the raging stupidity that begat ~*modern c++*~ Honestly, I am not experienced enough to know whether it's stupid or not. I'm just a student and hobbyist, and I've read the arguments for the modern C++ style and found them quite convincing. Perhaps I'll change my mind in the future. But there is a level in between targeting specific CPUs, compilers, etc. and throwing runtime polymorphism all over the place. For example, being able to use std::vector for arbitrary types and get a contiguous storage while preserving non-POD semantics for contained objects is only possible thanks to templates. I would say the modern C++ style is about making it convenient and safe to use (nominally) zero-cost abstractions, even though the library implementations supporting it will look pretty nasty under the hood (see any STL implementation). It's things like this talk which make me believe that modern C++ style can be brutally well optimised: https://www.youtube.com/watch?v=zBkNBP00wJE quote:the very innermost loops of a game engine
|
# ? Dec 2, 2016 17:20 |
|
Xarn posted:There are three now? Goddamit. Which one is winning? well, I assume there are three, or at least there have been three, because I remember a syntax where concepts looked like classes, that contained both pattern matching statements and extension methods (the intention being of allowing you to give a uniform api to all types that match a concept), and yet I can't find any mention of it anywhere anymore. I may have dreamed of it. it did look too good to be true
|
# ? Dec 2, 2016 17:55 |
|
hackbunny posted:you mean, two (three?) competing and completely different proposals. and the worst one is gaining the most ground because it's the easiest to implement using the current metaprogramming hell and a sprinkling of compiler magic heres a cool factoid, soustrup taught my engr111 class at texas a&m "Foundations of Engineering" it was bad
|
# ? Dec 2, 2016 17:56 |
|
hackbunny posted:and this is how enable_if is used! it can be used as an additional argument type (as we've done here), as a return type (can't be done here because the return type doesn't participate in overload resolution and we'd get a redefinition error), fwiw, this isn't true. functions may not be overloaded by return type, but function templates can: the dependent components of the return type and template parameter list are part of the signature and do differentiate templates
|
# ? Dec 2, 2016 19:00 |
|
I cant be too hard on Stroustrup, he gave us my favourite language Also he wrote an interesting article about his experience teaching programming, that made me think harder about the course I teach.
|
# ? Dec 2, 2016 19:37 |
|
Xarn posted:I cant be too hard on Stroustrup, he gave us my favourite language link to this article please, I have no idea what to expect from Stroustrup on teaching
|
# ? Dec 2, 2016 19:43 |
|
certainly all this c++ talk has made me happy with my choice of rust as my next lang to learn. distinguished unions, pattern matching, iterators, all with no runtime overhead like c++, but also a distinct lack of this incredible amount of bullshit (so far) lifetimes annoyed me a lot at first, but then i started to realise that every compiler error would have been UB in C++ anyway except for a few cases anyway, lexical lifetimes can't come soon enough
|
# ? Dec 2, 2016 19:48 |
|
hackbunny posted:well, I assume there are three, or at least there have been three, because I remember a syntax where concepts looked like classes, that contained both pattern matching statements and extension methods (the intention being of allowing you to give a uniform api to all types that match a concept), and yet I can't find any mention of it anywhere anymore. I may have dreamed of it. it did look too good to be true Concepts are now a technical specification there is a proposal for 'virtual concepts' which is basically rust traits for use across shared libraries and a separate proposal for pattern matching based on type that you might be thinking of i doubt those latter two would get past the committee if bjarne throws a tantrum again like he did with "if constexpr"
|
# ? Dec 2, 2016 19:48 |
|
my work is mostly scala these days and reading posts about c++ makes me say bizarre poo poo like "wow i'm glad i get to use such a simple and easy language"
|
# ? Dec 2, 2016 20:29 |
|
honestly it makes me see the appeal of go because even though it's a language for retards at least you're not at risk of drowning in bikeshedding garbage and can focus on making stuff
|
# ? Dec 2, 2016 20:55 |
|
Mr. Showtime posted:my work is mostly scala these days and reading posts about c++ makes me say bizarre poo poo like "wow i'm glad i get to use such a simple and easy language" im slowly trying to learn scala, and it's a flaw in my signed character that im drawn to complex rude languages like it, and before that c++ and before that perl
|
# ? Dec 2, 2016 20:59 |
|
fleshweasel posted:honestly it makes me see the appeal of go because even though it's a language for retards at least you're not at risk of drowning in bikeshedding garbage and can focus on making stuff also true of python although go is at least somewhat strongly typed hmm
|
# ? Dec 2, 2016 21:01 |
|
fritz posted:flaw in my signed character mods please
|
# ? Dec 2, 2016 21:01 |
|
fleshweasel posted:honestly it makes me see the appeal of go because even though it's a language for retards at least you're not at risk of drowning in bikeshedding garbage and can focus on making stuff I still see discussions on whether you should bring in testing libraries that are not in the stdlib to have things like assertions in tests or just keep doing if err != nil everywhere and the language has existed for 7 years
|
# ? Dec 2, 2016 21:23 |
|
fritz posted:im slowly trying to learn scala, and it's a flaw in my signed character that im drawn to complex rude languages like it, and before that c++ and before that perl scala is loving rad given a p. strict code review process so that nobody can sneak their own pet DSL in (unless it's really slick) or write some undocumented method named @++%! without providing a named alternative, though in all fairness "it's not bad if you don't let people do bad things" applies to most languages
|
# ? Dec 2, 2016 21:27 |
|
rjmccall posted:fwiw, this isn't true. functions may not be overloaded by return type, but function templates can: the dependent components of the return type and template parameter list are part of the signature and do differentiate templates alright, thanks. though I wonder for how long I will actually retain this information
|
# ? Dec 2, 2016 22:12 |
|
|
# ? May 22, 2024 16:34 |
|
no major numerical library relies on C++ for performance nor will they, seeing as they don't even rely on the C preprocessor numerical library hackers are your ultimate "we live the hard life and we like it" crowd
|
# ? Dec 2, 2016 22:33 |