mardi 3 mars 2015

invalid convertion in std::accumulate

I have a class representing a point in N dimensions with a min static function (minimum field by field)



template<typename T, std::size_t N>
class Point : public std::array<T,N>
{
template<Args...>
Point(Args&&... args) : std::array<T,N>{{args...}} {}
...
static Point min(const Point&, const Point&) {...}
}


Everything works well when I write



Point<float,3> a = {0.f, 1.f, 2.f};
Point<float,3> b = {2.f, 1.f, 0.f};
Point<float,3> c = Point<float,3>::min(a,b); // OK


But if I try to use std::accumulate over an array



Point<float,3> array[100] = ... ;
Point<float,3> min = std::accumulate(array, array+100, array[0], Point<float,3>::min); // Error


I get an error :



error: cannot convert ‘Point<float, 3ul>’ to ‘float’ in initialization
adimx::Point<T,N>::Point(Args&&... args) : std::array<T,N>{{args...}}


Is this an issue with std::accumulate implementation not being compatible with my constructor ?


Aucun commentaire:

Enregistrer un commentaire