On 20 February 2013 at 01:15, Yan Zhou wrote:
| Hi Dirk,
| 
| It is actually a problem with Rcpp, though unrelated to Ken's original 
question anymore, below is an example reproduce the problem.
| 
| #include <iostream>
| 
| class Wrapper
| {
|     public :
| 
|     Wrapper (double x) : x_(x) {}
| 
|     template <typename T> operator T () const {return x_;}
|     operator int () const {return x_;}
|     operator bool () const {return x_;}
| 
|     private :
| 
|     double x_;
| };
| 
| int main ()
| {
|     Wrapper x(1.2);
|     double a = x; // ERROR
| 
|     std::cout << a << std::endl;
| }
| 
| The error is quite compiler dependent. Clang and G++ considers three 
operators, template one with T = double, operator int, operator bool and 
conclude it is ambiguous. Intel icpc does not consider the template one and 
also consider it is ambiguous for obvious reason. Why the template one is not a 
perfect match is still a mysterious to me right now.

I see nothing Rcpp-specific here.  It's more about how to avoid ambiguity
within C++.  Might make a good question for the C++ tag on StackOverflow.

Dirk
 
| On Feb 20, 2013, at 1:11 AM, Dirk Eddelbuettel <e...@debian.org> wrote:
| 
| > 
| > On 19 February 2013 at 23:46, Ken Williams wrote:
| > | > From: Dirk Eddelbuettel [mailto:e...@debian.org]
| > | > You are relying on an implicit conversion here to make df(.,.) a 
double. The
| > | > compiler tells you that it is trying sugar operators.  Sugar is good to 
have in
| > | > Rcpp, but occassionally there is a cost. This may be one of those times.
| > | >
| > | > Try
| > | >
| > | >       double a = df(j,i);
| > | >       double b = df(j,last_i);
| > | >         if (fabs(a - b) > thresh) {
| > | >
| > | > and see if that works.
| > | 
| > | Unfortunately no, I get a similar error when I try that:
| > | 
| > | window.cpp:68:24: error: conversion from 'Rcpp::Vector<19>::Proxy {aka 
Rcpp::internal::generic_proxy<19>}' to 'double' is ambiguous
| > | window.cpp:68:24: note: candidates are:
| > | 
C:/mybin/R/R-2.15.2/library/Rcpp/include/Rcpp/vector/string_proxy.h:273:4: 
note: Rcpp::internal::generic_proxy<RTYPE>::operator int() const [with int 
RTYPE = 19]
| > | 
C:/mybin/R/R-2.15.2/library/Rcpp/include/Rcpp/vector/string_proxy.h:272:4: 
note: Rcpp::internal::generic_proxy<RTYPE>::operator bool() const [with int 
RTYPE = 19]
| > | 
C:/mybin/R/R-2.15.2/library/Rcpp/include/Rcpp/vector/string_proxy.h:267:26: 
note: Rcpp::internal::generic_proxy<RTYPE>::operator U() const [with U = 
double, int RTYPE = 19]
| > 
| > Maybe try std::fabs() instead of fabs() ?
| > 
| > That is one of the reasons I do not like a global 'using namespace Rcpp' in
| > my code.  Explicit namespaces are, well, explicit.
| > 
| > Dirk
| > | 
| > | 
| > | >
| > | > Not every conceivable operation is implemented in Rcpp,
| > | 
| > | Of course. =)
| > | 
| > | > but we are always
| > | > open to patches to make it more complete.
| > | 
| > | If I can get myself up to speed with my understanding, I'll be happy to 
contribute what I can.
| > | 
| > |  -Ken
| > | 
| > | ________________________________
| > | 
| > | CONFIDENTIALITY NOTICE: This e-mail message is for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
Any unauthorized review, use, disclosure or distribution of any kind is 
strictly prohibited. If you are not the intended recipient, please contact the 
sender via reply e-mail and destroy all copies of the original message. Thank 
you.
| > 
| > -- 
| > Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com  
| > _______________________________________________
| > Rcpp-devel mailing list
| > Rcpp-devel@lists.r-forge.r-project.org
| > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
| 

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com  
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to