|
Hi, you wrote that you are already using a parameter pack in the function rgbpixel::channel. Where would that be? Please post the signature(s) of rgbpixel::channel. Is your code somewhere so I could have a look?
Josef Schroettle
|
|
|
|
|
Sure
gfx/include/gfx_pixel.hpp at master · codewitch-honey-crisis/gfx · GitHub[^]
Pixel is at line 504
template<typename... ChannelTraits>
struct pixel {
...
This parameter pack is effectively passed through to each of the metadata query templates, as well as any function that access pixel data, like the implementation of channel<>()
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
DRY is soooooo overrated.
|
|
|
|
|
It is not often, but there are times in C++ when there is no alternative but to duplicate code. That is when macros come to the rescue. Due to the need for exactly the same code in several related methods, I will sometimes group those together, add a macro #define _someName with the code, expand the macro in each method, and add #undef _someName at the end of the group of methods. Sometimes there just aren't any alternatives.
In one case, I had an abstract base class that was essentially inherited in a diamond pattern to get the clean user interface that I wanted. But, even though there was no data in the abstract base class, a subclass either had to have two instances thus pointlessly increasing the size of the overall objects, or it had to be virtual, increasing both size and decreasing performance. There was no need for any of that because it was only providing an interface, with a default implementation of methods that only relied on other methods that were virtual. I wound up with two parallel lines of inheritance, with many methods duplicated between the lines. Invisible to client code (not the library code though), but there were no restrictions on size or performance. Yes, the virtual methods do require data -- but in the vtable, not in the code. And it is possible for the vtable to be optimized with global optimization (which is already being done at link time) so that multiple vtables are not required.
Recently, I created an experimental class, which required macros of templates because a template cannot contain a name used in code. A bit strange, but it worked and the user interface was reasonable. That, fortunately, never made it into my library since I had better options.
Even in C++ macros are very useful. They really, really need to be made more general with looping, variables, etc. There are places that I could use all of those features. Just like in older assembly languages. And why do macros have "elif", but neither C nor C++ do? Guess what? I use a global macro #define "elif else if". I also define "block", "loop", "when", "unless", "until", etc. I could do more with better macro features.
There seems to be a belief that if a language is good enough, that macros are simply obsolete and should be eliminated. That is false. There is no such thing as a language that is good enough. And never will be. C++ certainly isn't. I will always want more in a language (which is why I use C++, even though it is very limited) and I don't have an extra decade or two to design and build a better one. They keep adding things to C++, but the vast majority of them are never needed or should be better designed. Why are two iterators needed in loops? Mine don't require that. Do not design by committee! I have written code to support lambdas, but never actually needed them in practice. Perhaps one day. They are at least potentially useful. I have written many multithreaded programs, including the synchronization primitives themselves. But, I have never needed coroutines. I use templates, and some meta-template programming, but I have never needed templates as a Turing complete language. That is just nasty. In particular, the use of template meta programming to check std::print at compile time is an abomination. Get a single character wrong and you have several pages of useless error messages. That is a job for the compiler not template meta programming. And there is a lot of that in the standard library.
|
|
|
|
|
See, like Rust is great and all and cpp is a little dangerous, but you don't get that smart^^ working only with hand holding-y languages.
No pain no gain?
C# doesn't really have macros the same, but it's the same kinda deal. There's a bunch of information in your post that represents learning like branches on a tree (which has weird branches that grow into one another).
Starting with this stuff a long time ago when it was harder, you simply had to learn a bunch of things you just don't anymore. Many of those things have tendrils. Sum > whole of the parts...
|
|
|
|
|
Yes
|
|
|
|
|
Are you going to post the reddit solution?
|
|
|
|
|
template<typename Name>
constexpr inline void channel(typename channel_by_index<channel_index_by_name<Name>::value>::int_type value) {
constexpr const int index = channel_index_by_name<Name>::value;
channel<index>(value);
}
template<typename Name, typename... Names>
constexpr inline void channel(typename channel_by_index<type::channel_index_by_name<Name>::value>::int_type value,
typename type::channel_by_index<channel_index_by_name<Names>::value>::int_type... values) {
constexpr const int index = type::channel_index_by_name<Name>::value;
channel<index1>(value);
channel<Names...>(values...);
}
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
Similarly, when I was still working, every once in a while I'd leave a comment like:
//Seems like there should be a better way to do this, but I couldn't think of it.
//< explanation of what the code is trying to do >
|
|
|
|
|
Yeah, I use // TODO: for those so i can search them.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
Yes, absolutely. Some days I am just not inspired. On those days, I just crank out something and hope I can come back later to fix it. I often find that the next time around, I have a much better solution. The problem is, this only works if your employer is understanding enough to let you run your own show. Such employers are rare, of course.
|
|
|
|
|
Sort of.
The first several years I was in software development, I learned more and more, which helped me to improve code I had already written. It wasn't that my code was "stupid", but that I just learned newer and better ways.
Second, as the language I use improves, it provides better ways to do things, but it is up to me to discern whether the "better way" is really better.
Third, there are those team leads who are less knowledgeable and experienced, and make me rewrite code to how they think it should be done, even though I can make the clear case their way is not better. In those cases, I do what the lead says do, then inform him or her of the shortcomings it causes. In a lot of cases, they then agree (after a lot of wasted time) that I should do it the way I had it. Sometimes, though, pride gets in their way, and they make me put out the stupid code into production - problems and all.
|
|
|
|
|
I asked him if he could explain the gaps in his resume.
He said "yeah, they are spaces and you type them using the space bar."
I hired him on the spot!
|
|
|
|
|
Sander Rossel wrote: they are spaces
Ah! That's an instant red flag! Real programmers use tabs!
"Go forth into the source" - Neal Morse
"Hope is contagious"
|
|
|
|
|
To paraphrase Al Bundy, "you're hired!"
|
|
|
|
|
As a Charles Bukowski character once said when an interviewer asked about
the gaps in his resume, "Anybody can work all the time!"
|
|
|
|
|
I like to imagine I would have merely replied "Yes."
|
|
|
|
|
I thought you hired him based upon content
To err is human to really elephant it up you need a computer
|
|
|
|
|
...and fired him the next day for committing spaces instead of tabs.
|
|
|
|
|
I don't like the game anyway but It's official England are crap at football
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
|
|
|
|
|
pkfox wrote: official England are crap at football
At football tournament's England should be represented by it's media, it would be an all star team.
|
|
|
|
|
I sometimes think the media should form the next government; they clearly have all the answers....
|
|
|
|
|
That's true wherever you are in the world, too.
|
|
|
|
|
But they have the best lager louts.
|
|
|
|
|
swampwiz wrote: But they have the best lager louts.
Even that's open to debate these days, sadly. There are some fearsome reputations from groups other than the English followers.
|
|
|
|
|