boost::bind C2664 error with two non-const references
Hi, Relatively to this thread http://lists.boost.org/Archives/boost/2015/03/220930.php and this correcting commit 42b5cef177603328ead66bc6a98a3067aebc433d, I still have errors using boost::bind. #include <boost/bind.hpp> #include <boost/function.hpp> struct A { void f(int&, std::vector<int*>&); }; int main(){ A a; auto f = boost::bind(&A:f, &a, _1, _2); } results in error C2664: cannot convert from 'const std::vector<int*> &' to 'std::vector<int*> &' Defining BOOST_NO_CXX11_RVALUE_REFERENCES solves the issue for now. Nicolas FRANCOIS Software Department L-ACOUSTICS Tel : +33 (0) 1 69 63 23 90 Fax : +33 (0) 1 69 63 69 64 www.l-acoustics.com<http://www.l-acoustics.com/> Please consider the environment before printing this email.
Nicolas FRANCOIS wrote:
#include <boost/bind.hpp> #include <boost/function.hpp>
struct A { void f(int&, std::vector<int*>&); };
int main(){ A a; auto f = boost::bind(&A:f, &a, _1, _2); }
results in error C2664: cannot convert from 'const std::vector<int*> &' to 'std::vector<int*> &'
This code (after #include <vector> and A:f -> A::f) works for me under VS2013 and the current develop branch. What compiler are you using?
Using VS2013 and yes the code I gave is only a non-working sample code to expose the problem. Working with VS2013 on boost 1.58.0 release.
Le 22 mai 2015 à 13:12, Peter Dimov <lists@pdimov.com> a écrit :
Nicolas FRANCOIS wrote:
#include <boost/bind.hpp> #include <boost/function.hpp>
struct A { void f(int&, std::vector<int*>&); };
int main(){ A a; auto f = boost::bind(&A:f, &a, _1, _2); }
results in error C2664: cannot convert from 'const std::vector<int*> &' to 'std::vector<int*> &'
This code (after #include <vector> and A:f -> A::f) works for me under VS2013 and the current develop branch. What compiler are you using?
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Nicolas FRANCOIS wrote:
Using VS2013 and yes the code I gave is only a non-working sample code to expose the problem. Working with VS2013 on boost 1.58.0 release.
The code still compiles for me; VS2013, boost- 1.58.0.
Le 22 mai 2015 à 13:12, Peter Dimov <lists@pdimov.com> a écrit :
Nicolas FRANCOIS wrote:
#include <boost/bind.hpp> #include <boost/function.hpp>
struct A { void f(int&, std::vector<int*>&); };
int main(){ A a; auto f = boost::bind(&A:f, &a, _1, _2); }
results in error C2664: cannot convert from 'const std::vector<int*> &' to 'std::vector<int*> &'
This code (after #include <vector> and A:f -> A::f) works for me under VS2013 and the current develop branch. What compiler are you using?
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Does BOOST_NO_CXX11_RVALUE_REFERENCES is defined ? I managed to make it work defining it, but when it is not defined then the code goes to line 917 of bind.hpp; and it does not work because of the list_add_cref function which cast the reference in a const one. Le 22 mai 2015 à 14:53, Peter Dimov <lists@pdimov.com<mailto:lists@pdimov.com>> a écrit : Nicolas FRANCOIS wrote: Using VS2013 and yes the code I gave is only a non-working sample code to expose the problem. Working with VS2013 on boost 1.58.0 release. The code still compiles for me; VS2013, boost- 1.58.0. Le 22 mai 2015 à 13:12, Peter Dimov <lists@pdimov.com<mailto:lists@pdimov.com>> a écrit : Nicolas FRANCOIS wrote: #include <boost/bind.hpp> #include <boost/function.hpp> struct A { void f(int&, std::vector<int*>&); }; int main(){ A a; auto f = boost::bind(&A:f, &a, _1, _2); } results in error C2664: cannot convert from 'const std::vector<int*> &' to 'std::vector<int*> &' This code (after #include <vector> and A:f -> A::f) works for me under VS2013 and the current develop branch. What compiler are you using? _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Nicolas FRANCOIS wrote:
Does BOOST_NO_CXX11_RVALUE_REFERENCES is defined ?
No. This is what I'm compiling: #include <boost/bind.hpp> #include <boost/function.hpp> #include <vector> #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES #error #endif struct A { void f(int&, std::vector<int*>&); }; int main(){ A a; auto f = boost::bind(&A::f, &a, _1, _2); } It compiles and the linker complains that A::f hasn't been defined. Could you post the exact example that doesn't compile for you?
Nicolas FRANCOIS wrote:
Does BOOST_NO_CXX11_RVALUE_REFERENCES is defined ?
No. This is what I'm compiling: ...
I changed it to call the function. Still works. #include <boost/bind.hpp> #include <boost/function.hpp> #include <vector> #include <iostream> #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES #error #endif struct A { void f( int& x, std::vector<int*>& v ) { v.push_back( &x ); } }; int main() { A a; auto f = boost::bind(&A::f, &a, _1, _2); int x; std::vector<int*> v; f( x, v ); std::cout << &x << "; " << v.front() << std::endl; } Output: 0024F898; 0024F898
I’m really sorry, all is my own fault… I declared the signal object with the reference symbol for the std::vector… My bad, sorry.
Le 22 mai 2015 à 16:37, Peter Dimov <lists@pdimov.com> a écrit :
Nicolas FRANCOIS wrote:
Does BOOST_NO_CXX11_RVALUE_REFERENCES is defined ? No. This is what I'm compiling: ...
I changed it to call the function. Still works.
#include <boost/bind.hpp> #include <boost/function.hpp> #include <vector> #include <iostream>
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES #error #endif
struct A { void f( int& x, std::vector<int*>& v ) { v.push_back( &x ); } };
int main() { A a; auto f = boost::bind(&A::f, &a, _1, _2);
int x; std::vector<int*> v;
f( x, v );
std::cout << &x << "; " << v.front() << std::endl; }
Output:
0024F898; 0024F898
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Nicolas FRANCOIS
-
Peter Dimov