[Rcpp-devel] Defining template specialisation for wrap on Windows 64bit (Compilation error: 'result_type' does not name a type)

Steve Jaffe sjaffe at riskspan.com
Fri Oct 4 00:58:57 CEST 2013


This looks like it may be a compiler difference in terms of the c++ standard's requirement for template function specializations.

I see

	template <> octave_value as( SEXP );

in rcpp_octave.h

This is meant to be a specialization of 
template <typename T> T as( SEXP );

But this is one of those peculiar -- but perfectly legal -- template functions where the template parameter appears only in the return value, ie cannot be deduced from the arguments. 

I believe the correct syntax for the specialization is 

	template <> octave_value as<octave_value>( SEXP );

Omitting the "<octave_value>" qualifier is a shorthand that is allowed (but not required) when the template parameter can be deduced from the function arguments, ie under the same conditions that one is allowed to call the function without specifying the template parameter and allow the compiler to "deduce" it.

Thus the corresponding specialization of the template wrap function:

	template <> SEXP wrap( const octave_value& );

*is* allowed, for the same reason that one can write:

octave_value ov;
SEXP sx = wrap(ov); // compiler turns this into wrap<octave_value>(ov)

but one cannot write:
SEXP sx;
octave_value ov = as(sx); // type deduction applies only to arguments, not return value!

// correct:
// ov = as<octave_value>(sx);

Since the compiler doesn't recognize the declaration of "as" in rcpp_octave.h as a specialization of the generic template, when it sees as<octave_value>(...) the only thing it can do is apply the generic definition in as.h, which it reports:

note: candidate is:"
  [43] "C:/R/R-3.0.2/library/Rcpp/include/Rcpp/as.h:144:29: note:
template<class T> T Rcpp::as(SEXP)" 

Regards,
Steve


-----Original Message-----
To: Renaud Gaujoux <renaud at mancala.cbio.uct.ac.za>
Cc: rcpp-devel at lists.r-forge.r-project.org
Subject: Re: [Rcpp-devel] Defining template specialisation for wrap on
	Windows 64bit (Compilation error: 'result_type' does not name a type)

...

Renaud Gaujoux wrote:

  [35] "In file included from
C:/R/R-3.0.2/library/Rcpp/include/Rcpp.h:50:0,"
  [36] "                 from rcpp_octave.h:25,"
  [37] "                 from rcpp_octave.cpp:21:"
  [38] "C:/R/R-3.0.2/library/Rcpp/include/Rcpp/Language.h:156:21:
error: 'result_type' does not name a type"
...
  [41] "C:/R/R-3.0.2/library/Rcpp/include/Rcpp/Language.h:162:41:
error: no matching function for call to 'as(SEXPREC*&)'"
  [42] "C:/R/R-3.0.2/library/Rcpp/include/Rcpp/Language.h:162:41:
note: candidate is:"
  [43] "C:/R/R-3.0.2/library/Rcpp/include/Rcpp/as.h:144:29: note:
template<class T> T Rcpp::as(SEXP)"


More information about the Rcpp-devel mailing list