read all of chapter 19 here:
https://www.learncpp.com/cpp-tutorial/template-classes/
Templates are one of the most aggravating / complicated syntax items in c++. I struggle with them as well, because I do not need them often outside of the provided stl ones.
unions are a C construct, and if you are not using the semistandard but illegal 'union hack' (where you can use any field of the union at any time, the c++ strict rules are that you can only ever use ONE of them per variable) their usefulness is greatly reduced.
here, I don't even see you use the unsigned char. I would just do this:
struct ripemd_union
{
char r_char[max_in];
uint8_t* r_int{(uint8_t*)r_char};
};
this should work in 99% of anything you try to do here, because the auto array to pointer combined with the array notation allowed on pointers lets you say
ripemd_union x;
x.r_int[3]; //ok, pointer using array notation
cout << x.r_char; //ok, c-string override and array to pointer auto conversions
and so on.
the only place it will hiccup is if you had an explicit type problem, where it expected - for example - a fixed sized array in a function but got the pointer (auto pointer back to array isnt a thing). This can be avoided.
its still very C-ish, but its simple and gets the job done if you are willing to work within its limitations. If you need more, you can get it (see the above much more complicated and much more C++ friendly answer) or move on toward templates if you like.
this struct can be initialized via
ripemd_union x[3] {{"abc"},{"def"},{"123456"}};
1 2 3 4 5 6 7 8
|
all that aside, you can use this, maybe?
ripemd_union ripemd_input[rm_count ][ max_in ] =
{
{ .r_char = {""} },
{ .r_char = {"a"} },
...
|
that maybe only works in C. I don't know right now.