Timeline for Templates for generic code and code flexibility
Current License: CC BY-SA 4.0
26 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 31, 2023 at 16:53 | vote | accept | Enlico | ||
Dec 20, 2020 at 9:30 | answer | added | Jerry Coffin | timeline score: 1 | |
Dec 17, 2020 at 21:57 | comment | added | jxh |
The decltype suggestion was to remove your last two objections in your question.
|
|
Dec 17, 2020 at 13:27 | comment | added | Enlico |
Because end() just needs to return a kind of guard, not a true iterator, right? As regards vtables, inheritance, and whatever is dynamic/run-time when it could be static/compile-time, I feel that experienced C++ programmers (at least those I know) tend to be at least not happy about using it, unless where it is stricly necessary.
|
|
Dec 17, 2020 at 13:09 | comment | added | rwong |
If a C++ type is a kind of a container such that it has a begin() method that returns an iterator that can be dereferenced into something, you can take it as a way to decipher the "element type" of that container. It may be necessary to sprinkle some std::remove_cvref . Note: in C++, for some containers, begin() and end() can have different return types.
|
|
Dec 17, 2020 at 13:06 | comment | added | rwong | C++ iterators is both right and wrong; right because it is indeed a mechanism that can work over wide range of data structures; wrong because each data structure has its own iterator types; it's not possible to have polymorphism over them. The solution is simple - just wrap around them, OOP style. | |
Dec 17, 2020 at 13:03 | comment | added | rwong |
@Enlico My personal experience is that (since I'm a C++ and C# dual user), eventually, sane C++ code design should take lessons from C#, and learn to use vtable (C++ flavor of OOP) more. To begin with, create an abstract interface that mimics ICollection and IList and Tuple , and create adapters for specific implementations of C++ containers.
|
|
Dec 17, 2020 at 12:38 | comment | added | Enlico |
However, @rwong, I'm pretty sure that my problem with what I'm trying to understand with this question is not about SFINAE or decltype , which would "just" be tools to accomplish some useful/good/flexible/whatever design; it's about the fact that I lack some theoretical education/training about code design, probably. And probably these networks are not the right place to learn that :(
|
|
Dec 17, 2020 at 12:35 | comment | added | Enlico |
@rwong, I know what decltype does and I know what SFINAE is, and as regards how to use SFINAE, I'm still at the beginning, but I could at least understand and put in practice a colleague's suggestion of you can SFINAE that out when I was having a clash between two friend functions. This is just to say, I'm eager to go deep in SFINAE, templates, enable_if /void_t , and all that stuff. As regards medical conditions, I'm proud to say that I'm on my way already, if that puts me in a better position to learn SFINAE.
|
|
Dec 17, 2020 at 12:28 | comment | added | rwong | Learning SFINAE can also trigger medical (psychological) conditions. Make sure medical and counseling coverage that last longer than employment termination. | |
Dec 17, 2020 at 12:27 | comment | added | rwong | Large corporations (over 10000 headcount) that use C++ significantly have SFINAE working groups that create SFINAE-based C++ library features for internal use. They typically also participate in C++ language specification committees. Each new version of C++11, C++14, C++17 introduces significant and sometimes breaking changes to SFINAE, which are meant to make SFINAE less insane (but which also breaks archaic insane SFINAE usage). Also, SFINAE users can encounter compiler differences and bugs (vendor and version specific) that ordinary users won't see. | |
Dec 17, 2020 at 12:21 | comment | added | rwong |
@Enlico The two C++ topics that you might want to learn are: decltype and "SFINAE". Note: learning SFINAE will disqualify a C++ programmer from employment because programming productivity will drop to zero during the first few years of learning SFINAE. Most people eventually abandon C++ altogether after they started learning SFINAE seriously.
|
|
Dec 17, 2020 at 11:01 | comment | added | jxh | Yes, that should do it. | |
Dec 17, 2020 at 9:55 | comment | added | Enlico |
As far as I can tell = I've used those left /right on a std::array and they operate like [0] and [1] . So you mean decltype(left(one of those arrays)) ?
|
|
Dec 17, 2020 at 9:52 | comment | added | jxh |
std::array does not offer such an interface. If you can assume any group of 2 inside the collection will be interpreted properly by your left and right functors, then you can use decltype to detect the type returned by them.
|
|
Dec 17, 2020 at 9:31 | comment | added | Enlico |
The codebase has a left and right function objects that work pretty reliably, as far as I can tell.
|
|
Dec 17, 2020 at 9:19 | comment | added | jxh | For the groups of 2, what can you offer to generically obtain the first and second thing? | |
Dec 17, 2020 at 9:18 | comment | added | Enlico | @jxh, for now I'd answer yes. | |
Dec 17, 2020 at 9:18 | comment | added | jxh |
Will fun always operate on a collection of things that are collected in groups of 2?
|
|
Dec 17, 2020 at 9:18 | comment | added | Enlico | I'm don't exclude that probably I need more a discussion than an answer to this question here. I'm just stuck in my understanding of what is wrong in my attempt to use templates. Probably a book would also be good, but I'd like to have a bare understanding before spending money on a book which might end up not being what I need. | |
Dec 17, 2020 at 9:11 | comment | added | Enlico | Another thing which I hope helps giving some perspective to my question: I'm an extremely young programmer. I'm enjoying C++, but I tend to answer "let's make it a template" whenever I'm asked to make something work with more than 2 classes. And everytime I'm told that I'm killing flexibility (not because I try to use templates, I feel, but because of the way I try to use them) hence I'm asking this question. | |
Dec 17, 2020 at 9:07 | comment | added | Enlico |
@NicolBolas, I've added some comment in fun . Does that help? Regarding the clear and concrete idea (of what fun does, but also in general), don't take me wrong, but if I had one I wouldn't be asking. As regards who will be using it, that's probably the most nasty aspect, because that who is me. So given I still don't have a clear picture of the whole machinery, I risk to make a "working" mess which I end up being not able to handle/maintain.
|
|
Dec 17, 2020 at 9:02 | history | edited | Enlico | CC BY-SA 4.0 |
added 38 characters in body
|
Dec 16, 2020 at 22:35 | comment | added | Nicol Bolas |
You first need a clear and concrete idea of what fun does and who will be using it for what. Once you know what fun is all about, only then can you go into asking how to generalize it. You can't generalize things without knowing what you're trying to generalize.
|
|
Dec 16, 2020 at 18:50 | review | First posts | |||
Dec 16, 2020 at 18:53 | |||||
Dec 16, 2020 at 18:48 | history | asked | Enlico | CC BY-SA 4.0 |