I’d like to write an n-dimensional histogram class. It should be in the form of bins that contains other bins etc. where each bin contains min and max range, and a pointer to the next dimension bins
a bin is defined like
template<typename T>
class Bin {
float minRange, maxRange;
vector<Bin<either Bin or ObjectType>> bins;
}
This definition is recursive. So in run time the user defines the dimension of the histogram
so if its just 1-dimension, then
Bin<Obj>
while 3-dimensions
Bin<Bin<Bin<Obj>>>
Is this possible?
Regards
Certainly, C++11 has variable length parameter lists for templates. Even without C++11 you can use specialisation, if all your dimensions have the same type:
You can only specify the dimension at runtime to a certain degree. If it is bound by a fixed value you can select the appropriate type even dynamically. However, consider using a one-dimensional vector instead of a multi-dimensional jagged vector!