How did cmath not use patterns and / or overloads

Many of the new features introduced in C ++ 11 using TR1 have ugly C-like signatures. For example, citing the Boost TR1 documentation ( http://www.boost.org/doc/libs/1_52_0/doc/html/boost_tr1/subject_list.html#boost_tr1.subject_list.special ):

// [5.2.1.1] associated Laguerre polynomials: double assoc_laguerre(unsigned n, unsigned m, double x); float assoc_laguerref(unsigned n, unsigned m, float x); long double assoc_laguerrel(unsigned n, unsigned m, long double x); 

Obviously, someone would prefer some templated implementation (which is actually the native signature of these functions in Boost), or at least some overloading instead of multiple identifiers.

I can understand that the desire for compatibility with C supports these identifiers, but then this is a nuisance for pure C ++ speakers. In addition to <cmath> may be several <math> with more natural interfaces.

What am I missing (except perhaps some previously asked questions)?

+4
source share
1 answer

I do not know about Boost, but all standard functions in <cmath> have overloads for three standard types, so you have, for example:

 double cos(double); float cos(float); long double cos(long double); 

instead of C:

 double cos(double); float cosf(float); long double cosl(long double); 

I'm not quite sure why you need a function template instead of Overload. For most mathematical functions there is no common implementation possible; the correct implementation will depend on accuracy, rounding rules, etc., which are different for each type. Thus, an alternative would be a template function without a common implementation and three specializations. And what does it buy you over the β€œsimpler” overloaded functions?

+4
source

All Articles