|
Update: Someone on reddit helped me with this, and the solution is simple and elegant. I'm low key ashamed I didn't think of it.
I run into that with C++ sometimes.
all i wanted to do was extend
rgb_pixel<24> foo;
foo.channel<channel_name::R>(63);
so you could set multiple channels at once.
rgb_pixel<24> foo;
foo.channel<channel_name::R,channel_name::G,channel_name::B>(63,31,47);
You'd think you could do with a parameter pack (template<typename... ChannelNames> but no, because I'm already using a parameter pack and you can't take two to a template.
Anyway, I dug and dug and dug even through some esoteric techniques to stash parameter packs in tuples[^] which I still don't understand
Finally I gave in. You know what I did?
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 Name1, typename Name2>
constexpr inline void channel(typename channel_by_index<channel_index_by_name<Name1>::value>::int_type value1,
typename channel_by_index<channel_index_by_name<Name2>::value>::int_type value2) {
constexpr const int index1 = channel_index_by_name<Name1>::value;
channel<index1>(value1);
constexpr const int index2 = channel_index_by_name<Name2>::value;
channel<index2>(value2);
}
template<typename Name1, typename Name2, typename Name3>
constexpr inline void channel(typename channel_by_index<channel_index_by_name<Name1>::value>::int_type value1,
typename channel_by_index<channel_index_by_name<Name2>::value>::int_type value2,
typename channel_by_index<channel_index_by_name<Name3>::value>::int_type value3) {
constexpr const int index1 = channel_index_by_name<Name1>::value;
channel<index1>(value1);
constexpr const int index2 = channel_index_by_name<Name2>::value;
channel<index2>(value2);
constexpr const int index3 = channel_index_by_name<Name3>::value;
channel<index3>(value3);
}
5 times (last two omitted)
C++ is better than this. I'm not. This is after posting in r/cpp_questions and posting a question here and getting nowhere.
I feel bad about this code. It's terrible. And I'm stuck with it until I get better at C++
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
modified 8hrs 5mins ago.
|
|
|
|
|
|
Yes, this is part & parcel of programming. Back when I was slinging code, I used to read books from Scott Meyer ("Effective C++") et al to bring my level of coding practice to that of a fine craftsman.
Did that craftsmanship keep me employable? NO
Do employers give a rat's a33 about such craftsmanship? H3LL NO
Indeed, the reason that Java has become the default application development is because all its belts & suspenders make it so that the product that poor coders put out will not (usually) cause crashes and other failures, since the compiler ensures that everything is neatly belted up. I'd like to say something similar about JavaScript, but that monster makes Java look professorial.
|
|
|
|
|
It looks like you created a template tuple. That proves you do understand tuples!
(I am mostly lost)😊
|
|
|
|
|
My first impression was "tuple? I don't think you read my code right"
And then I realized, you're just looking at my pixel<> template as if it were a tuple, and that makes sense because you can access the channels off of it as though they were tuple fields.
I never looked at it that way, but you're absolutely right.
Maybe you understand more of it than you think?
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
I was referring to this clause.
template<typename Name1, typename Name2, typename Name3>
I have only ever used tuples in Python:
(anyValue1, anyValue2,…)
slap some items together so you can track them with a single reference. Great for returning multiple pieces of information from a function.
|
|
|
|
|
Ah, those are simply template arguments in C++.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
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.
|
|
|
|
|
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!"
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
But they have the best lager louts.
|
|
|
|
|
|
Looks like it's expensive to be lazy.
A home without books is a body without soul. Marcus Tullius Cicero
PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com
Latest Article: EventAggregator
|
|
|
|
|
I see no reason to reward laziness.
|
|
|
|
|
Especially doing front end applications that interface with large databases ?
Dealing with large SQL requests ?
Anything related to UI/UX ?
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
Hopefully the back-end API's support pagination and sophisticated searching. (That's a UI/UX clue as well.)
|
|
|
|
|
Have you seen (or read) this book: Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems[^]
I read about half of it and it was so deeply technical I couldn't even believe it.
People all over the Internet _say_ they're reading it or have read it, but I couldn't complete it.
i'm not that smart though. I gave up because it explained Databases etc. in such a deep way it went flying over my head. But, that is probably easy.
Check it out, because I think it may be what you're looking for.
|
|
|
|
|