https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68515

            Bug ID: 68515
           Summary: std::result_of<F(X)> doesn't work when F is abstract
                    (with pure virtual functions)
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: naupacte at sfr dot fr
  Target Milestone: ---

I had to replace 'typename std::result_of<F(X)>::type' by
'decltype(std::declval<F>()(X()))'

All is in the title. Here is an example:

template <class T, class F, class R=typename result_of<F(T)>::type> vector<R>
make_result(const vector<T>& x, const F& f)
{
 auto n = x.size();
 vector<R> y(n);
 for (uint i=0; i<n; i++) y[i] = f(x[i]);
 return y;
}

template <class R, class T> struct virtual_func
{
    R operator()(T x) const { return _get(x);}

    virtual R _get(T) const = 0;
}

template <class R, class T> struct virtual_sqrt : virtual_func<R,T>
{
    virtual R _get(T x) const { return std::sqrt(x);}
}

std::vector<double> sqrt(const std::vector<double>& v)
{
   return make_result(v,virtual_sqrt{});
}


/opt/local/bin/gcc-mp-5 --version
gcc-mp-5 (MacPorts gcc5 5.2.0_0) 5.2.0

/opt/local/bin/gcc-mp-5 -x c++ -m64 -std=gnu++14 -c foo.cpp

>>>>>>>>>>>


error: no matching function for call to 'make_result(const vector<double>&,
const virtual_func<double,double>&)'

note:   template argument deduction/substitution failed:
error: invalid abstract return type 'virtual_func<double>'

template <class T, class F, class R=Result_of<F(T)>> vector<R>
make_result(const vector<T>& x, const F& f) { auto n = x.size(); vector<R>
y(n); for (uint i=0; i<n; i++) y[i] = f(x[i]); return y;}
                           ^
note:   because the following virtual functions are pure within
'virtual_func<double>':
   template <class R, class T> struct virtual_func
                                      ^
note:   R virtual_func<R,T>::_get(T) const [with R = double; T = double]
    virtual R _get(T) const = 0;


NB: here are the implementation details:

Reply via email to