boostorg / bind Goto Github PK
View Code? Open in Web Editor NEWBoost.org bind module
Home Page: http://boost.org/libs/bind
Boost.org bind module
Home Page: http://boost.org/libs/bind
As deduced from here, BOOST_CXX_VERSION
>= 201700L for Clang 5.0 with -std=c++1z
, yet std::bit_not
etc. are not available in that environment, which causes compilation errors with include/boost/bind/detail/result_traits.hpp
.
boost::protect(std::bind()) warns about result_type which is deprecated since C++17:
2>.../boost/bind/protect.hpp(28): warning C4996: 'std::_Weak_result_type<std::_Is_memfunptr<void (__thiscall jetbrains::controller::pipe_client::* )(jetbrains::controller::pipe_client::client_context_ptr,uint32_t,jetbrains::controller::pipe_client::monitoring_context_ptr)>,void>::result_type': warning STL4007: Many result_type typedefs and all argument_type, first_argument_type, and second_argument_type typedefs are deprecated in C++17.
When compiling the following code requiring C++17 (or higher) with any recent compiler that has made exception specification part of the function type (Clang 12, gcc 11, VC 2019),
#include <boost/type.hpp>
#include <boost/bind/bind.hpp>
struct P
{
P()
{
boost::bind(boost::type<void>(), &P::launch_me, this)();
}
void launch_me() noexcept {}
};
the build fails, e.g. as follows:
In file included from prog.cc:2:
In file included from /opt/wandbox/boost-1.73.0/clang-head/include/boost/bind/bind.hpp:26:
In file included from /opt/wandbox/boost-1.73.0/clang-head/include/boost/mem_fn.hpp:22:
/opt/wandbox/boost-1.73.0/clang-head/include/boost/bind/mem_fn.hpp:356:16: error: reference to non-static member function must be called; did you mean to call it with no arguments?
return (p->*f_);
^~~~~~~~
()
/opt/wandbox/boost-1.73.0/clang-head/include/boost/bind/bind.hpp:259:9: note: in instantiation of member function 'boost::_mfi::dm<void () noexcept, P>::operator()' requested here
unwrapper<F>::unwrap(f, 0)(a[base_type::a1_]);
^
/opt/wandbox/boost-1.73.0/clang-head/include/boost/bind/bind.hpp:1294:16: note: in instantiation of function template specialization 'boost::_bi::list1<boost::_bi::value<P *>>::operator()<void (P::*)() noexcept, boost::_bi::list0>' requested here
return l_( type<result_type>(), f_, a, 0 );
^
prog.cc:8:58: note: in instantiation of member function 'boost::_bi::bind_t<void, void (P::*)() noexcept, boost::_bi::list1<boost::_bi::value<P *>>>::operator()' requested here
boost::bind(boost::type<void>(), &P::launch_me, this)();
^
In file included from prog.cc:2:
In file included from /opt/wandbox/boost-1.73.0/clang-head/include/boost/bind/bind.hpp:26:
In file included from /opt/wandbox/boost-1.73.0/clang-head/include/boost/mem_fn.hpp:22:
/opt/wandbox/boost-1.73.0/clang-head/include/boost/bind/mem_fn.hpp:356:16: error: non-const lvalue reference to type 'void () noexcept' cannot bind to a temporary of type 'void'
return (p->*f_);
^~~~~~~~~
2 errors generated.
The problem has been verified to exist at least for Boost 1.73 and the most recent version 1.74 as well.
The problem was found by a more indirect usage of boost::bind via boost::thread in our code base using this kind of code:
#include <boost/thread.hpp>
struct S
{
S()
{
boost::thread th(&S::launch_me, this);
}
void launch_me() noexcept {}
};
We are in the process of making B2 build changes to all of the B2 build files
to support "modular" consumption of the Boost Libraries by users. See this list
post for some details: https://lists.boost.org/Archives/boost/2024/01/255704.php
The process requires making a variety of changes to make each Boost library
independent of the super-project structure. But the changes do not remove the
super-project structure or the comprehensive Boost release. The changes make
solely make it possible, optionally, for users, like package manages, to easily
consume libraries individually.
Generally the changes include:
Some examples of such changes:
We are asking how you would like us to handle the changes. We would prefer if
you allow the owners of the Boost.org GitHub project to make changes to B2
build files, as needed, to accomplish the changes. But understand
that you may want to manage the proposed changes yourself.
We previously sent emails to all known maintainers to fill out a form with their
preference. We are contacting you in this issue as we have not gotten a response
to that email. You can see the ongoing responses for that form and the responses
to these issues here https://github.com/users/grafikrobot/projects/1/views/6
We are now asking if you can reply directly to this issue to indicate your
preference of handling the changes. Please supply a response to this question
and close the issue (so that we can verify you are a maintainer).
How would you like the build changes to be processed?
Also please indicate any special instructions you want us to consider. Or other
information you want us to be aware of.
Thanks you, René
boost::apply does not compile when injecting rvalue at function/arguments positions using nested boost::bind:
#include<iostream>
#include<functional>
#include<boost/bind/bind.hpp>
#include<boost/bind/apply.hpp>
class f_t
{
public:
void operator()(int&)&
{
std::cout << 1 << std::endl;
}
void operator()(int&&)&
{
std::cout << 2 << std::endl;
}
void operator()(int&)&&
{
std::cout << 3 << std::endl;
}
void operator()(int&&)&&
{
std::cout << 4 << std::endl;
}
}f;
int& get_lvalue_arg()
{
static int a;
return a;
}
int get_prvalue_arg()
{
return 1;
}
auto& get_lvalue_f()
{
return f;
}
auto get_prvalue_f() // function returning [(prvalue) function object]; the same goes for function returning [(prvalue) function pointer]
{
return f;
}
int main()
{
boost::bind(boost::apply<void>(), boost::bind(get_lvalue_f), boost::bind(get_lvalue_arg))();
boost::bind(boost::apply<void>(), boost::bind(get_lvalue_f), boost::bind(get_prvalue_arg))(); //compile error
boost::bind(boost::apply<void>(), boost::bind(get_prvalue_f), boost::bind(get_lvalue_arg))(); //compile error
boost::bind(boost::apply<void>(), boost::bind(get_prvalue_f), boost::bind(get_prvalue_arg))(); //compile error
boost::bind(boost::apply<void>(), boost::bind(boost::apply<f_t&>(), boost::placeholders::_1), boost::bind(boost::apply<int&>(), boost::placeholders::_2))(get_lvalue_f, get_lvalue_arg);
boost::bind(boost::apply<void>(), boost::bind(boost::apply<f_t&>(), boost::placeholders::_1), boost::bind(boost::apply<int>(), boost::placeholders::_2))(get_lvalue_f, get_prvalue_arg); //compile error
boost::bind(boost::apply<void>(), boost::bind(boost::apply<f_t>(), boost::placeholders::_1), boost::bind(boost::apply<int&>(), boost::placeholders::_2))(get_prvalue_f, get_lvalue_arg); //compile error
boost::bind(boost::apply<void>(), boost::bind(boost::apply<f_t>(), boost::placeholders::_1), boost::bind(boost::apply<int>(), boost::placeholders::_2))(get_prvalue_f, get_prvalue_arg); //compile error
std::bind(f, std::bind(get_lvalue_arg))();
std::bind(f, std::bind(get_prvalue_arg))();
}
expected output:
1
2
3
4
1
2
3
4
1
2
workaround:
in <boost/bind/apply.hpp>, change:
template<class F, class A1> result_type operator()(F & f, A1 & a1) const
{
return f(a1);
}
to:
template<class F, class A1> result_type operator()(F&& f, A1&& a1) const
{
return ((F&&)f)((A1&&)a1);
}
I'm using Boost 1.73 the error is reported in:
c:\boost\boost_1_73_0\boost\bind\mem_fn_template.hpp(271): error C2672: 'get_pointer': no matching overloaded function found c:\boost\boost_1_73_0\boost\bind\mem_fn_template.hpp(286): note: see reference to function template instantiation 'R boost::_mfi::mf2<R,IProcessChangeObserver,SystemObjectPtrRef,ProcessControl::ProcessChange>::call<U,const SystemObjectPtr,A2>(U &,const void *,B1 &,B2 &) const' being compiled with [ R=void, U=std::_Ph<1>, A2=ProcessControl::ProcessChange, B1=const SystemObjectPtr, B2=ProcessControl::ProcessChange ] c:\boost\boost_1_73_0\boost\bind\mem_fn_template.hpp(286): note: see reference to function template instantiation 'R boost::_mfi::mf2<R,IProcessChangeObserver,SystemObjectPtrRef,ProcessControl::ProcessChange>::call<U,const SystemObjectPtr,A2>(U &,const void *,B1 &,B2 &) const' being compiled with [ R=void, U=std::_Ph<1>, A2=ProcessControl::ProcessChange, B1=const SystemObjectPtr, B2=ProcessControl::ProcessChange ] c:\boost\boost_1_73_0\boost\bind\bind.hpp(398): note: see reference to function template instantiation 'R boost::_mfi::mf2<R,IProcessChangeObserver,SystemObjectPtrRef,ProcessControl::ProcessChange>::operator ()<T>(U &,A1,A2) const' being compiled with [ R=void, T=std::_Ph<1>, U=std::_Ph<1>, A1=SystemObjectPtrRef, A2=ProcessControl::ProcessChange ] c:\boost\boost_1_73_0\boost\bind\bind.hpp(398): note: see reference to function template instantiation 'R boost::_mfi::mf2<R,IProcessChangeObserver,SystemObjectPtrRef,ProcessControl::ProcessChange>::operator ()<T>(U &,A1,A2) const' being compiled with [ R=void, T=std::_Ph<1>, U=std::_Ph<1>, A1=SystemObjectPtrRef, A2=ProcessControl::ProcessChange ] c:\boost\boost_1_73_0\boost\bind\bind.hpp(1306): note: see reference to function template instantiation 'void boost::_bi::list3<boost::_bi::value<T>,boost::_bi::value<boost::shared_ptr<ISystemObject>>,boost::_bi::value<ProcessControl::ProcessChange>>::operator ()<F,boost::_bi::rrlist1<A1>>(boost::_bi::type<void>,F &,A &,int)' being compiled with [ T=std::_Ph<1>, F=boost::_mfi::mf2<void,IProcessChangeObserver,SystemObjectPtrRef,ProcessControl::ProcessChange>, A1=const boost::intrusive_ptr<IProcessChangeObserver> &, A=boost::_bi::rrlist1<const boost::intrusive_ptr<IProcessChangeObserver> &> ] c:\boost\boost_1_73_0\boost\bind\bind.hpp(1306): note: see reference to function template instantiation 'void boost::_bi::list3<boost::_bi::value<T>,boost::_bi::value<boost::shared_ptr<ISystemObject>>,boost::_bi::value<ProcessControl::ProcessChange>>::operator ()<F,boost::_bi::rrlist1<A1>>(boost::_bi::type<void>,F &,A &,int)' being compiled with [ T=std::_Ph<1>, F=boost::_mfi::mf2<void,IProcessChangeObserver,SystemObjectPtrRef,ProcessControl::ProcessChange>, A1=const boost::intrusive_ptr<IProcessChangeObserver> &, A=boost::_bi::rrlist1<const boost::intrusive_ptr<IProcessChangeObserver> &> ] c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\algorithm(92): note: see reference to function template instantiation 'void boost::_bi::bind_t<void,boost::_mfi::mf2<void,IProcessChangeObserver,SystemObjectPtrRef,ProcessControl::ProcessChange>,boost::_bi::list3<boost::_bi::value<T>,boost::_bi::value<boost::shared_ptr<ISystemObject>>,boost::_bi::value<ProcessControl::ProcessChange>>>::operator ()<const boost::intrusive_ptr<IProcessChangeObserver>&>(A1)' being compiled with [ T=std::_Ph<1>, A1=const boost::intrusive_ptr<IProcessChangeObserver> & ] c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\algorithm(92): note: see reference to function template instantiation 'void boost::_bi::bind_t<void,boost::_mfi::mf2<void,IProcessChangeObserver,SystemObjectPtrRef,ProcessControl::ProcessChange>,boost::_bi::list3<boost::_bi::value<T>,boost::_bi::value<boost::shared_ptr<ISystemObject>>,boost::_bi::value<ProcessControl::ProcessChange>>>::operator ()<const boost::intrusive_ptr<IProcessChangeObserver>&>(A1)' being compiled with [ T=std::_Ph<1>, A1=const boost::intrusive_ptr<IProcessChangeObserver> & ]
I discovered that boost::bind
strongly requires to have result_type
meta-field from the type of the passed functional object. I was surprised, because why not to use boost::result_of
when possible?
Can we fix it, even it will be a breaking change?
The shortest-reproducible example here:
https://godbolt.org/z/5fhb1hdYa
Starting (at least) in MSVC 19.20, /std:c++latest
results in internal _HAS_CXX20
macro being defined, which effectively removes result_type
nested typedef from std library function objects such as std::equal_to
etc. This breaks code using boost::bind
without explicit R
specification.
std::bind_front
seems to be a great addition to the standard. However, it's only available from C++20. As I'm working in a C++11 shop, I'm looking for an open source C++11 alternative, but can't seem to find one. I think Boost.Bind would be a great home for it, if someone's up for creating it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.