C++ Templates: Convincing self against code bloat
- by ArunSaha
I have heard about code bloats in context of C++ templates. I know that is not the case with modern C++ compilers. But, I want to construct an example and convince myself.
Lets say we have a class
template< typename T, size_t N >
class Array {
public:
T * data();
private:
T elems_[ N };
};
template< typename T, size_t N >
T * Array<T>::data() {
return elems_;
}
Further, let's say types.h contains
typedef Array< int, 100 > MyArray;
x.cpp contains
MyArray ArrayX;
and y.cpp contains
MyArray ArrayY;
Now, how can I verify that the code space for MyArray::data() is same for both ArrayX and ArrayY?
What else I should know and verify from this (or other similar simple) examples? If there is any g++ specific tips, I am interested for that too.
PS: Regarding bloat, I am concerned even for the slightest of bloats, since I come from embedded context.