|
well, poo pooraminasi posted:did anyone else start saying "oh what no no no no" to themselves while reading that mostly I was thinking "why would anyone use templates this poo poo is nuts"
|
# ? Dec 1, 2016 01:49 |
|
|
# ? Jun 4, 2024 18:22 |
|
having to make a variant in C++ reminds me of cutthroat kitchen when someone has to make an omelette with only a hammer and a guitar or something
|
# ? Dec 1, 2016 01:54 |
|
hackbunny posted:ok, let's step back and rationalize. implementing variant, even a lovely buggy limited version of it, takes a huge amount of code, almost all of it metaprogramming. what does variant do?[list] You can use a union. You want to use something like this internally. code:
|
# ? Dec 1, 2016 02:11 |
|
Bloody posted:with the power of Icarus Verilog, your Verilog can indeed be computer instructions!!!
|
# ? Dec 1, 2016 02:26 |
|
I just assume that nothing supports sysv and write Verilog-2001. so far this has been a mostly valid assumption (note that I am trapped in the hellscape of actel/microsemi FPGAs)
|
# ? Dec 1, 2016 02:50 |
hackbunny posted:ok, let's step back and rationalize. implementing variant, even a lovely buggy limited version of it, takes a huge amount of code, almost all of it metaprogramming. I'm loving these posts.
|
|
# ? Dec 1, 2016 07:01 |
|
Sweeper posted:well, poo poo Well lemme ask this could you create a flexible compile time type safe discriminated union with C# generics?
|
# ? Dec 1, 2016 07:49 |
|
qntm posted:I was going to make a programming language with no I/O capability whatsoever, and adding such would be specifically forbidden in the licence There are plenty of languages with no I/O whatsoever (and not like Haskell's "whoops, there's actually a whole imperative sublanguage in here"). They usually compile to functions that you then have to call from some other language.
|
# ? Dec 1, 2016 07:57 |
C++ templates are basically eldritch magic. Very arcane but very powerful, and best suited for the hands of wizards.
|
|
# ? Dec 1, 2016 08:11 |
|
hackbunny i dont know anything about templates or c++ but I was able to follow (most) of what you were talking about there. my point is you're a good and clear writer and I enjoy your posts.
|
# ? Dec 1, 2016 14:27 |
|
Malcolm XML posted:a miserable little pile of secrets i'm going to make a password manager named "aman" and then use that line as the first answer in the faq
|
# ? Dec 1, 2016 14:45 |
|
MALE SHOEGAZE posted:hackbunny i dont know anything about templates or c++ but I was able to follow (most) of what you were talking about there. my point is you're a good and clear writer and I enjoy your posts.
|
# ? Dec 1, 2016 15:30 |
|
Fergus Mac Roich posted:Well lemme ask this could you create a flexible compile time type safe discriminated union with C# generics? something like this? https://github.com/mcintyre321/OneOf
|
# ? Dec 1, 2016 16:18 |
|
Bognar posted:something like this? https://github.com/mcintyre321/OneOf What if I want 10 types in a variant?
|
# ? Dec 1, 2016 16:50 |
|
Xarn posted:What if I want 10 types in a variant? bug the library author to add some more definitions also if it's good enough for tuple it's good enough for me!
|
# ? Dec 1, 2016 16:53 |
|
Xarn posted:What if I want 10 types in a variant? guess you have to use cpp then, sorry
|
# ? Dec 1, 2016 16:53 |
|
MALE SHOEGAZE posted:hackbunny i dont know anything about templates or c++ but I was able to follow (most) of what you were talking about there. my point is you're a good and clear writer and I enjoy your posts. thank you, I try current progress: just learned how to use enable_if and how to use it with copy and move constructors. slurps mad rips this is your cue to start laughing your rear end off
|
# ? Dec 1, 2016 18:12 |
|
gj using aligned_union instead of aligned_union_t hackbunny thank god the undefined behavior sanitizer caught one of its side effects. it's really annoying that you can't use the address sanitizer and the memory sanitizer at the same time (but I'm grateful to have them)
|
# ? Dec 1, 2016 18:39 |
|
hackbunny posted:thank you, I try speaking of which i keep waiting for the groundswell of people laughing their rear end off at you for missing the True Way To Use C++ that doesn't run into all these insane things and then i remember, oh yeah. c++
|
# ? Dec 1, 2016 19:15 |
|
Xarn posted:What if I want 10 types in a variant? the actual downside of it as compared to the c++ thing is that it requires boxing the values since it just stuffs everything in an object field BobHoward posted:speaking of which i keep waiting for the groundswell of people laughing their rear end off at you for missing the True Way To Use C++ that doesn't run into all these insane things some of the problems are self-inflicted to various degress. the way to make allocators not awful is just not use allocators because they only exist for the sake of segmented memory and are shockingly useless for anything else. a lot of the other complexity you could ignore and get a solution that's not worse than what's possible in other languages.
|
# ? Dec 1, 2016 19:22 |
|
hackbunny posted:current progress: just learned how to use enable_if and how to use it with copy and move constructors. slurps mad rips this is your cue to start laughing your rear end off yeah im not gonna laugh at that because when enable_if/SFINAE clicked it was several years ago after staring at it for weeks. i feel like with c++ template metaprogramming theres a mental state before and after understanding and using enable_if and i cannot get into that pre dark magick mental state and i legit wonder sometimes if i would be happier not knowing what i know but then i remember that i implemented interface restraints for concepts entirely in c++14 and i realize im in too deep for it to matter. hackbunny posted:gj using aligned_union instead of aligned_union_t hackbunny when i wrote my first optional type i used aligned_storage instead of aligned_storage_t so welcome to the club
|
# ? Dec 1, 2016 20:51 |
|
Slurps Mad Rips posted:yeah im not gonna laugh at that because when enable_if/SFINAE clicked it was several years ago after staring at it for weeks. i feel like with c++ template metaprogramming theres a mental state before and after understanding and using enable_if and i cannot get into that pre dark magick mental state and i legit wonder sometimes if i would be happier not knowing what i know but then i remember that i implemented interface restraints for concepts entirely in c++14 and i realize im in too deep for it to matter. well turns out I was wrong and I didn't actually get it. welp! effortpost soon
|
# ? Dec 1, 2016 21:11 |
|
is there such a thing as an enum with multiple properties? (c# btw)code:
even if i could, i cant have other properties like max value/min value i could use static classes code:
code:
30 TO 50 FERAL HOG fucked around with this message at 21:25 on Dec 1, 2016 |
# ? Dec 1, 2016 21:21 |
|
i think in java you need libraries like guava and autovalue to hide the tedious simplicity, and in c++ you need libraries like boost to hide the hellish complexity
|
# ? Dec 1, 2016 21:26 |
suffix posted:i think in java you need libraries like guava and autovalue to hide the tedious simplicity, and in c++ you need libraries like boost to hide the hellish complexity I like this
|
|
# ? Dec 1, 2016 21:53 |
|
do you mean like sum types? because those are the best. do the enums in rust look like what you want?
|
# ? Dec 1, 2016 22:04 |
|
yeah rust enums look handy i ended up doing this code:
|
# ? Dec 1, 2016 22:10 |
|
yeah sum types/tagged unions are very good. in languages that don't have them people try to emulate them by overloading the meaning of null or other values and it's just gross and causes so many bugs. like whenever you see poo poo like "returns the index of the first occurrence of a character, or -1 if the character doesn't occur" or "returns a File, or null if the file wasn't found" that could have been done properly with a tagged union.
|
# ? Dec 1, 2016 22:24 |
|
BiohazrD posted:is there such a thing as an enum with multiple properties? (c# btw) no. c# enums loving suck rear end. your solution is fine, but you'll miss out on things like iteration of possible values unless you do some gross hacks (either another static prop w/ list of options or reflection)
|
# ? Dec 1, 2016 22:25 |
|
suffix posted:i think in java you need libraries like guava and autovalue to hide the tedious simplicity, and in c++ you need libraries like boost to hide the hellish complexity you know you're a c++ programmer when you look at boost and think "yes, this is hiding the hellish complexity"
|
# ? Dec 1, 2016 22:40 |
|
BiohazrD posted:yeah rust enums look handy change the prop to: C# code:
|
# ? Dec 1, 2016 22:46 |
|
Slurps Mad Rips posted:yeah im not gonna laugh at that because when enable_if/SFINAE clicked it was several years ago after staring at it for weeks. i feel like with c++ template metaprogramming theres a mental state before and after understanding and using enable_if and i cannot get into that pre dark magick mental state and i legit wonder sometimes if i would be happier not knowing what i know but then i remember that i implemented interface restraints for concepts entirely in c++14 and i realize im in too deep for it to matter. i miss C++ so bad
|
# ? Dec 1, 2016 22:49 |
|
Soricidus posted:you know you're a c++ programmer when you look at boost and think "yes, this is hiding the hellish complexity" you're a real c++ programmer when you look at MPL and not only understand what it does but are able to simply code you wrote using it. (less true as of c++11 thankfully)
|
# ? Dec 2, 2016 00:18 |
|
let's talk about enable_if. enable_if is a metafunction with two arguments: a boolean, and a type. if the boolean is true, it returns the type, otherwise it returns nothing. it's used to conditionally cause a non-critical compilation error (called substitution failure), which is used to conditionally exclude functions from overload resolution. it's a sad excuse for pattern matching, but not as bad as the alternatives it replaced. let's see an example:C++ code:
an old way, widely used, was tag dispatch: instead of overloading the function, we make it fully generic; we pass the generic types to metafunctions that classify them according to patterns, and return a different type (the tag) for each pattern; we then use the tag to select the right overload of the internal implementation of the function. optimization of iterator algorithms is heavily based on tag dispatch, let's see what it looks like: C++ code:
C++ code:
C++ code:
bonus content: if we need to disable a single function, instead of choosing among several overloads, there's a much simpler way that's, again, a terrible hack C++ code:
|
# ? Dec 2, 2016 02:08 |
|
hackbunny posted:nowadays, the preferred way to pattern match is sfinae, an acronym meaning Substitution Failure Is Not An Error. as the name suggests, it's literally a hack: we cause recoverable compilation errors as a hint that the compiler should go look elsewhere. the main tool for using sfinae is the enable_if metafunction: at least since c++11 there's enable_if to hide the horrors that underlie this whole thing. i've had to use "naked" sfinae once to get around limitations in code generation tools in a c++03 codebase and i've not felt clean since then
|
# ? Dec 2, 2016 02:36 |
|
hackbunny posted:a p. drat fine write up i just wanted to point out that you can check if an iterator (that follows the iterator category system) has any of a number of tags with std::is_base_of. for example, C++ code:
one other thing too is that you can do the enable_if in the template parameter in conjunction with an "assignment hack" as well, and it ends up being a bit easier to swallow C++ code:
and now you've got a clean lil' function C++ code:
|
# ? Dec 2, 2016 02:39 |
hackbunny posted:
Maybe I'm missing something obvious (or maybe I missed this part of your post), but why do you switch over to a pointer to an iterator here? And doesn't this increment the pointer to the iterator, not the iterator itself? And in the default case of a null pointer, isn't that undefined behavior?
|
|
# ? Dec 2, 2016 03:38 |
|
VikingofRock posted:Maybe I'm missing something obvious (or maybe I missed this part of your post), but why do you switch over to a pointer to an iterator here? And doesn't this increment the pointer to the iterator, not the iterator itself? And in the default case of a null pointer, isn't that undefined behavior? where is the pointer to an iterator?
|
# ? Dec 2, 2016 03:40 |
raminasi posted:where is the pointer to an iterator? Oh yeah actually I misread it. I thought it was C++ code:
|
|
# ? Dec 2, 2016 03:47 |
|
|
# ? Jun 4, 2024 18:22 |
Actually wait why doesn't this work?C++ code:
|
|
# ? Dec 2, 2016 03:55 |