I can't stand them, but I need them - nested template instantiations
-
The STL does this too but it's annoying. You wind up declaring C++ templates that package a bunch of template parameters together as a unit, and then pass that as an argument to another template, and so on.
rgb_pwm<
rgb_pwm_group< // declares one rgb pulse width modulation group
pwm_traits<32,0>, // Red: GPIO pin # 32, PWM channel 0
pwm_traits<25,1>, // Green: GPIO pin # 25, PWM channel 1
pwm_traits<26,2> // Blue: GPIO pin # 26, PWM channel 2p;
If that isn't the ugliest elephanting thing outside of preprocessor macros, I'm not sure what is. Sure you can use typedef/using, but then you just end up adding even more lines of code. I don't know what I want though. I guess JSON wouldn't be much more brief. I do kinda wish C++ allowed you to explicitly pass your arguments by name like you can do in C#. That way this would be at least a little more legible, if verbose.
To err is human. Fortune favors the monsters.
-
The STL does this too but it's annoying. You wind up declaring C++ templates that package a bunch of template parameters together as a unit, and then pass that as an argument to another template, and so on.
rgb_pwm<
rgb_pwm_group< // declares one rgb pulse width modulation group
pwm_traits<32,0>, // Red: GPIO pin # 32, PWM channel 0
pwm_traits<25,1>, // Green: GPIO pin # 25, PWM channel 1
pwm_traits<26,2> // Blue: GPIO pin # 26, PWM channel 2p;
If that isn't the ugliest elephanting thing outside of preprocessor macros, I'm not sure what is. Sure you can use typedef/using, but then you just end up adding even more lines of code. I don't know what I want though. I guess JSON wouldn't be much more brief. I do kinda wish C++ allowed you to explicitly pass your arguments by name like you can do in C#. That way this would be at least a little more legible, if verbose.
To err is human. Fortune favors the monsters.
-
I bet I am missing the point but how about something like
std::map pwmPins { {32, 0}, {25, 1}, {26, 2}, };
And of you have a bunch of these also create a type aliasusing PinMap = std::map
"If we don't change direction, we'll end up where we're going"
Ummm, no. I'm not using a map and relegating all of my microsecond fast pin operation code to a hash table. Compile time and runtime are not the same thing. Not even a little bit. Edit: Sorry if I came across as hostile. I didn't mean to be. It's early and my conversation skills are a bit dodgy right now.
To err is human. Fortune favors the monsters.
-
Ummm, no. I'm not using a map and relegating all of my microsecond fast pin operation code to a hash table. Compile time and runtime are not the same thing. Not even a little bit. Edit: Sorry if I came across as hostile. I didn't mean to be. It's early and my conversation skills are a bit dodgy right now.
To err is human. Fortune favors the monsters.
-
Ummm, no. I'm not using a map and relegating all of my microsecond fast pin operation code to a hash table. Compile time and runtime are not the same thing. Not even a little bit. Edit: Sorry if I came across as hostile. I didn't mean to be. It's early and my conversation skills are a bit dodgy right now.
To err is human. Fortune favors the monsters.
-
How about this then? After the template is built the table definitions become neat. constexpr-map/[^]
"If we don't change direction, we'll end up where we're going"
That *would* be nice, but I don't think it's available under the Arduino framework necessarily - on many platforms The STL is only partially implemented. I'd probably have to reimplement much of that instead of using the std:: namespace. Not out of the realm of possibility. I'll poke at it. Thanks!
To err is human. Fortune favors the monsters.
-
That *would* be nice, but I don't think it's available under the Arduino framework necessarily - on many platforms The STL is only partially implemented. I'd probably have to reimplement much of that instead of using the std:: namespace. Not out of the realm of possibility. I'll poke at it. Thanks!
To err is human. Fortune favors the monsters.
-
When I get fed up with all this magic stuff I ask myself: Alrite, how would I do it in plain old C ?
"If we don't change direction, we'll end up where we're going"
You'd most likely have to use a ton of preprocessor macros. :(
To err is human. Fortune favors the monsters.
-
You'd most likely have to use a ton of preprocessor macros. :(
To err is human. Fortune favors the monsters.
If you have to go more than three 'if' levels deep - :elephant: that! Even two levels looks like something I never want to eat! I feel for the MS guys who keep up their #ifdefs in the Windows headers! X|
Our Forgotten Astronomy | Object Oriented Programming with C++
-
If you have to go more than three 'if' levels deep - :elephant: that! Even two levels looks like something I never want to eat! I feel for the MS guys who keep up their #ifdefs in the Windows headers! X|
Our Forgotten Astronomy | Object Oriented Programming with C++
The problem in this case is you can have up to 5 RGB LEDs you can control, each requiring 3 pins. The above was just for one LED. Variadic template arguments are how I accomplish that. It would be really messy to do that with the preprocessor. It's doable I think, but it requires a lot of nonsense.
To err is human. Fortune favors the monsters.