P
Pavel Shved
Is there a program of wide use that automatically extracts template
parameters requirements from source code of template functions?
I mean the following: assume we have a template function that demands
its template parameter(s) to meet certain requirements. For example
simple sorting function
template <typename T> void sort(T* t, int N)
{
for (int i=0;i<N-1; i++)
for (int j=N-1;j>i;j--)
if (t[j-1] < t[j]) {
T temp=t[j];
t[j]=t[j-1];
t[j-1]=temp;
}
}
requires T to have the following members: a) operator<(T) returning
bool; b) copy-constructor, accepting T, and c) operator=(T) (usually
these operators use passing-by-reference, but this assumption is way
too strict).
I know (or at least I'm sure I do) there is a way to formalize and
extract strict requirements (which the above axample doesn't
intgroduce) as there is also possibility to form unstrict, common ones
(common is that hardly anyone would write T:perator= returning
something instead of T). Of course i mean automatic extraction
procedures.
The question is whether someone has done it already.
parameters requirements from source code of template functions?
I mean the following: assume we have a template function that demands
its template parameter(s) to meet certain requirements. For example
simple sorting function
template <typename T> void sort(T* t, int N)
{
for (int i=0;i<N-1; i++)
for (int j=N-1;j>i;j--)
if (t[j-1] < t[j]) {
T temp=t[j];
t[j]=t[j-1];
t[j-1]=temp;
}
}
requires T to have the following members: a) operator<(T) returning
bool; b) copy-constructor, accepting T, and c) operator=(T) (usually
these operators use passing-by-reference, but this assumption is way
too strict).
I know (or at least I'm sure I do) there is a way to formalize and
extract strict requirements (which the above axample doesn't
intgroduce) as there is also possibility to form unstrict, common ones
(common is that hardly anyone would write T:perator= returning
something instead of T). Of course i mean automatic extraction
procedures.
The question is whether someone has done it already.