How do I refer to std::sin(const valarray &)?

后端 未结 3 463
故里飘歌
故里飘歌 2020-12-19 08:18

I\'m having trouble with some valarray function pointer code:

double (*fp)(double) = sin;
valarray (*fp)(const valarray &) =          


        
3条回答
  •  佛祖请我去吃肉
    2020-12-19 09:10

    26 3.1/3

    Any function returning a valarray is permitted to return an object of another type, provided all the const member functions of valarray are also applicable to this type.

    The aim is to allow template expressions to be used to optimize the result (i.e. looping one time on the whole array doing each times the computation, directly assigning to the resulting valarray<> instead of building a temporary).

    z = sin(x+y);
    

    can be optimized to

    for (i = 0; i < N; ++i)
       z[i] = sin(x[i] + y[i]);
    

提交回复
热议问题