Disclaimer: I am targeting embedded, and the STL isn't always available/compliant/responsible on those platforms, so my code doesn't use it at all. Furthermore, I am self taught in this arena so my terminology may be wrong. I will do my best to describe what I want so even if my vocabulary is off kilter hopefully you'll still understand it. I'd ideally like to target C++14, but C++17 is acceptable. No compiler specific extensions are acceptable, nor is any code that may break a particular compiler from a major vendor.
I have a
pixel<>
template struct, itself composed of one or more
channel_trait<>
template structs that are passed in via a variadic template argument.
template<typename... ChannelTraits>
struct pixel {
using type = pixel<ChannelTraits...>;
...
It has several constructors, some with hateful but unavoidable dummy bool arguments.
constexpr inline pixel() : native_value(0) {
helpers::pixel_init_impl<type,0,ChannelTraits...>::init(*this);
}
constexpr inline pixel(int_type native_value,bool dummy) : native_value(native_value) {
}
constexpr inline pixel(typename ChannelTraits::int_type... values) : native_value(0) {
helpers::pixel_init_impl<type,0,ChannelTraits...>::init(*this,values...);
}
constexpr inline pixel(
bool dummy,
typename ChannelTraits::real_type... values) : native_value(0) {
helpers::pixel_init_impl<type,0,ChannelTraits...>::initf(*this,values...);
}
These constructors - two in fact are what are vexing me.
Say I declare a pixel with some padding bits in it that aren't used:
using rgb18_pixel = pixel<
channel_traits<channel_name::R,6>,
channel_traits<channel_name::nop,2>,
channel_traits<channel_name::G,6>,
channel_traits<channel_name::nop,2>,
channel_traits<channel_name::B,6>,
channel_traits<channel_name::nop,2>
>;
This forces me to use 6 values in the constructor, 3 of which are never going to be used for anything (all the ::nop traits)
#define UNUSED 0
rgb18_pixel foo(1,UNUSED,3,UNUSED,5,UNUSED);
Now, it's easy to query each channel_trait to find out if it's an unused channel or not. But what I can't do is get any kind of ::int_type... values off of a subset of ChannelTraits... that only has the used channels.
I can run a separate query to get that, but I can't repack a parameter pack as far as I know?
What I have tried:
I tried swapping out
::int_type
for another alias I make
::initializer_int_type
I set it to
void
for the nop channels. I got a compiler error, so clearly I can't coerce it into dropping those arguments from the constructor that way.
I'm not sure where to go with this? Some kind of templatized ctor?