for example, I have a pair array (which is a static variable) a[] which represents coordinates of points A,B,C:
pair<float,float> MyClass::a[]={{0,0},{320,568},{640,0}};
and I want another array b[] which stores the length of AB and BC:
float MyClass::b[sizeof(a)/sizeof(pair<float,float>)-1]={
sqrt((a[1].first-a[0].first)*(a[1].first-a[0].first)+(a[1].second-a[0].second)*(a[1].second-a[0].second)),
sqrt((a[2].first-a[1].first)*(a[2].first-a[1].first)+(a[2].second-a[1].second)*(a[2].second-a[1].second))
};
but b[] is not very maintainable because if I add elements to a[], I need to change b[] manually. Is there any methods which can generate b[] automatically? Is there anything such like e.g.: macros
float b[]={MACRO(a)};
or
float b[]={MACRO(sizeof(a)/sizeof(pair<float,float>))};
or template:
template<int i>
struct s{
float b[]={something a[i+1]-a[i]};
};
s<sizeof(a)/sizeof(pair<float,float>)> _s;
or other design patterns that allows me to change size of a[] without changing b[] manually or even no need to modify other parts of codes?