G
Good Guy
We have a structure like below:
template<size_t size>
class Container{
public:
char characters[size];
};
And we have a function like below:
template <size_t size>
void function(Container<size> input,size_t Size){
//all instances do exactly same thing and with regard to Size
that determines the size of object
}
Now in C++ for every value of size, a different instance of function
will be created and apparently that's not right in this case since all
instances do the same thing, to avoid this the first function
parameter should be a pointer(char * pointer) instead of an object so
that accepts any array with any size eliminating the need for function
to be templated, but I'm curious having a single function which
accepts a variable-size parameter like above that's not allowed by C++
is something impossible at all to implement and generate assembly for,
or somehow leads to an inefficient implementation in terms of speed/
memory ?
template<size_t size>
class Container{
public:
char characters[size];
};
And we have a function like below:
template <size_t size>
void function(Container<size> input,size_t Size){
//all instances do exactly same thing and with regard to Size
that determines the size of object
}
Now in C++ for every value of size, a different instance of function
will be created and apparently that's not right in this case since all
instances do the same thing, to avoid this the first function
parameter should be a pointer(char * pointer) instead of an object so
that accepts any array with any size eliminating the need for function
to be templated, but I'm curious having a single function which
accepts a variable-size parameter like above that's not allowed by C++
is something impossible at all to implement and generate assembly for,
or somehow leads to an inefficient implementation in terms of speed/
memory ?