"'boost::bind' is ambiguous" C++ error - c++

I'm trying to control an arduino from a c++ program, after some research I found this, but the problem is, it does not compile on eclipse.
It gives me 2 errors at line 102 in 3_async>AsyncSerial.cpp
boost::thread t(boost::bind(&asio::io_service::run, &pimpl->io));
Screenshot
If compiled by using its own CMakeLists.txt it gives no errors.
Any way to know what settings am I missing on eclipse if there are any?
EDIT:
as suggested I'm posting the logs:
12:32:18 **** Incremental Build of configuration Debug for project Arduino_SerialTest ****
make all
Building file: ../src/lib/pica_protocol/Receiver.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/lib/pica_protocol/Receiver.d" -MT"src/lib/pica_protocol/Receiver.o" -o "src/lib/pica_protocol/Receiver.o" "../src/lib/pica_protocol/Receiver.cpp"
In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
from /usr/include/boost/thread/thread.hpp:12,
from /usr/include/boost/thread.hpp:13,
from ../src/lib/pica_protocol/../serial/AsyncSerial.h:14,
from ../src/lib/pica_protocol/../serial/BufferedAsyncSerial.h:8,
from ../src/lib/pica_protocol/Receiver.h:12,
from ../src/lib/pica_protocol/Receiver.cpp:8:
/usr/include/boost/thread/detail/thread.hpp: In instantiation of ‘void boost::detail::thread_data<F>::run() [with F = void (pica_protocol::Receiver::*)()]’:
../src/lib/pica_protocol/Receiver.cpp:75:1: required from here
/usr/include/boost/thread/detail/thread.hpp:117:17: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((boost::detail::thread_data<void (pica_protocol::Receiver::*)()>*)this)->boost::detail::thread_data<void (pica_protocol::Receiver::*)()>::f (...)’, e.g. ‘(... ->* ((boost::detail::thread_data<void (pica_protocol::Receiver::*)()>*)this)->boost::detail::thread_data<void (pica_protocol::Receiver::*)()>::f) (...)’
f();
^
In file included from /usr/include/boost/bind.hpp:22:0,
from ../src/lib/pica_protocol/../serial/AsyncSerial.h:13,
from ../src/lib/pica_protocol/../serial/BufferedAsyncSerial.h:8,
from ../src/lib/pica_protocol/Receiver.h:12,
from ../src/lib/pica_protocol/Receiver.cpp:8:
/usr/include/boost/bind/bind.hpp: In instantiation of ‘void boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf1<void, pica_protocol::Receiver, std::basic_string<char> >; A = boost::_bi::list0; A1 = boost::_bi::value<pica_protocol::Receiver*>; A2 = boost::_bi::value<std::basic_string<char>*>]’:
/usr/include/boost/bind/bind_template.hpp:20:59: required from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()() [with R = void; F = boost::_mfi::mf1<void, pica_protocol::Receiver, std::basic_string<char> >; L = boost::_bi::list2<boost::_bi::value<pica_protocol::Receiver*>, boost::_bi::value<std::basic_string<char>*> >; boost::_bi::bind_t<R, F, L>::result_type = void]’
/usr/include/boost/thread/detail/thread.hpp:117:17: required from ‘void boost::detail::thread_data<F>::run() [with F = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pica_protocol::Receiver, std::basic_string<char> >, boost::_bi::list2<boost::_bi::value<pica_protocol::Receiver*>, boost::_bi::value<std::basic_string<char>*> > >]’
../src/lib/pica_protocol/Receiver.cpp:75:1: required from here
/usr/include/boost/bind/bind.hpp:313:34: error: no match for call to ‘(boost::_mfi::mf1<void, pica_protocol::Receiver, std::basic_string<char> >) (pica_protocol::Receiver*&, std::basic_string<char>*&)’
unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
^
In file included from /usr/include/boost/mem_fn.hpp:22:0,
from /usr/include/boost/bind/bind.hpp:26,
from /usr/include/boost/bind.hpp:22,
from ../src/lib/pica_protocol/../serial/AsyncSerial.h:13,
from ../src/lib/pica_protocol/../serial/BufferedAsyncSerial.h:8,
from ../src/lib/pica_protocol/Receiver.h:12,
from ../src/lib/pica_protocol/Receiver.cpp:8:
/usr/include/boost/bind/mem_fn_template.hpp:136:65: note: candidates are:
template<class R, class T, class A1 BOOST_MEM_FN_CLASS_F> class BOOST_MEM_FN_NAME(mf1)
^
In file included from /usr/include/boost/bind/mem_fn.hpp:215:0,
from /usr/include/boost/mem_fn.hpp:22,
from /usr/include/boost/bind/bind.hpp:26,
from /usr/include/boost/bind.hpp:22,
from ../src/lib/pica_protocol/../serial/AsyncSerial.h:13,
from ../src/lib/pica_protocol/../serial/BufferedAsyncSerial.h:8,
from ../src/lib/pica_protocol/Receiver.h:12,
from ../src/lib/pica_protocol/Receiver.cpp:8:
/usr/include/boost/bind/mem_fn_template.hpp:163:7: note: R boost::_mfi::mf1<R, T, A1>::operator()(T*, A1) const [with R = void; T = pica_protocol::Receiver; A1 = std::basic_string<char>]
R operator()(T * p, A1 a1) const
^
/usr/include/boost/bind/mem_fn_template.hpp:163:7: note: no known conversion for argument 2 from ‘std::basic_string<char>*’ to ‘std::basic_string<char>’
/usr/include/boost/bind/mem_fn_template.hpp:168:25: note: template<class U> R boost::_mfi::mf1<R, T, A1>::operator()(U&, A1) const [with U = U; R = void; T = pica_protocol::Receiver; A1 = std::basic_string<char>]
template<class U> R operator()(U & u, A1 a1) const
^
/usr/include/boost/bind/mem_fn_template.hpp:168:25: note: template argument deduction/substitution failed:
In file included from /usr/include/boost/bind.hpp:22:0,
from ../src/lib/pica_protocol/../serial/AsyncSerial.h:13,
from ../src/lib/pica_protocol/../serial/BufferedAsyncSerial.h:8,
from ../src/lib/pica_protocol/Receiver.h:12,
from ../src/lib/pica_protocol/Receiver.cpp:8:
/usr/include/boost/bind/bind.hpp:313:34: note: cannot convert ‘(& a)->boost::_bi::list0::operator[]<std::basic_string<char>*>((* &((boost::_bi::list2<boost::_bi::value<pica_protocol::Receiver*>, boost::_bi::value<std::basic_string<char>*> >*)this)->boost::_bi::list2<boost::_bi::value<pica_protocol::Receiver*>, boost::_bi::value<std::basic_string<char>*> >::<anonymous>.boost::_bi::storage2<boost::_bi::value<pica_protocol::Receiver*>, boost::_bi::value<std::basic_string<char>*> >::a2_))’ (type ‘std::basic_string<char>*’) to type ‘std::basic_string<char>’
unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
^
In file included from /usr/include/boost/bind/mem_fn.hpp:215:0,
from /usr/include/boost/mem_fn.hpp:22,
from /usr/include/boost/bind/bind.hpp:26,
from /usr/include/boost/bind.hpp:22,
from ../src/lib/pica_protocol/../serial/AsyncSerial.h:13,
from ../src/lib/pica_protocol/../serial/BufferedAsyncSerial.h:8,
from ../src/lib/pica_protocol/Receiver.h:12,
from ../src/lib/pica_protocol/Receiver.cpp:8:
/usr/include/boost/bind/mem_fn_template.hpp:176:25: note: template<class U> R boost::_mfi::mf1<R, T, A1>::operator()(const U&, A1) const [with U = U; R = void; T = pica_protocol::Receiver; A1 = std::basic_string<char>]
template<class U> R operator()(U const & u, A1 a1) const
^
/usr/include/boost/bind/mem_fn_template.hpp:176:25: note: template argument deduction/substitution failed:
In file included from /usr/include/boost/bind.hpp:22:0,
from ../src/lib/pica_protocol/../serial/AsyncSerial.h:13,
from ../src/lib/pica_protocol/../serial/BufferedAsyncSerial.h:8,
from ../src/lib/pica_protocol/Receiver.h:12,
from ../src/lib/pica_protocol/Receiver.cpp:8:
/usr/include/boost/bind/bind.hpp:313:34: note: cannot convert ‘(& a)->boost::_bi::list0::operator[]<std::basic_string<char>*>((* &((boost::_bi::list2<boost::_bi::value<pica_protocol::Receiver*>, boost::_bi::value<std::basic_string<char>*> >*)this)->boost::_bi::list2<boost::_bi::value<pica_protocol::Receiver*>, boost::_bi::value<std::basic_string<char>*> >::<anonymous>.boost::_bi::storage2<boost::_bi::value<pica_protocol::Receiver*>, boost::_bi::value<std::basic_string<char>*> >::a2_))’ (type ‘std::basic_string<char>*’) to type ‘std::basic_string<char>’
unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
^
In file included from /usr/include/boost/bind/mem_fn.hpp:215:0,
from /usr/include/boost/mem_fn.hpp:22,
from /usr/include/boost/bind/bind.hpp:26,
from /usr/include/boost/bind.hpp:22,
from ../src/lib/pica_protocol/../serial/AsyncSerial.h:13,
from ../src/lib/pica_protocol/../serial/BufferedAsyncSerial.h:8,
from ../src/lib/pica_protocol/Receiver.h:12,
from ../src/lib/pica_protocol/Receiver.cpp:8:
/usr/include/boost/bind/mem_fn_template.hpp:184:7: note: R boost::_mfi::mf1<R, T, A1>::operator()(T&, A1) const [with R = void; T = pica_protocol::Receiver; A1 = std::basic_string<char>]
R operator()(T & t, A1 a1) const
^
/usr/include/boost/bind/mem_fn_template.hpp:184:7: note: no known conversion for argument 1 from ‘pica_protocol::Receiver*’ to ‘pica_protocol::Receiver&’
make: *** [src/lib/pica_protocol/Receiver.o] Errore 1
12:32:20 Build Finished (took 2s.670ms)
EDIT 2:
ok I fixed the ambiguity error by casting the io_service::run like that:
boost::thread t(boost::bind(static_cast<std::size_t(asio::io_service::*)(void)>(&asio::io_service::run), &pimpl->io));
but the compiler error remains, hope someone knows how to fix that ...

Related

Catkin build fails when a lambda is added to it

rand_dat1_sub_handle = node.subscribe<geometry_msgs::Vector3>(
"random/data1", 100,
[](geometry_msgs::Vector3::ConstPtr& data){std::cout<<data->x;});
rand_dat2_sub_handle = node.subscribe<geometry_msgs::Vector3>(
"random/data2", 100,
[](geometry_msgs::Vector3::ConstPtr& data){std::cout<<data->x;});
when I use the above block of code in my class definition script, my build fails giving me the following errors.
In file included from /usr/include/boost/function/detail/maybe_include.hpp:18:0,
from /usr/include/boost/function/detail/function_iterate.hpp:14,
from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
from /usr/include/boost/function.hpp:64,
from /opt/ros/melodic/include/ros/forwards.h:40,
from /opt/ros/melodic/include/ros/common.h:37,
from /opt/ros/melodic/include/ros/ros.h:43,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.h:7,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:2:
/usr/include/boost/function/function_template.hpp: In instantiation of ‘static void boost::detail::function::void_function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&]’:
/usr/include/boost/function/function_template.hpp:925:38: required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&]’
/usr/include/boost/function/function_template.hpp:716:7: required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/usr/include/boost/function/function_template.hpp:1061:16: required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:85:83: required from here
/usr/include/boost/function/function_template.hpp:159:11: error: no match for call to ‘(TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>) (const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&)’
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
^
/usr/include/boost/function/function_template.hpp:159:11: note: candidate: void (*)(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&) {aka void (*)(boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&)} <conversion>
/usr/include/boost/function/function_template.hpp:159:11: note: conversion of argument 2 would be ill-formed:
/usr/include/boost/function/function_template.hpp:159:11: error: binding reference of type ‘geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr& {aka boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&}’ to ‘const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >’ discards qualifiers
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:85:50: note: candidate: TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)> <near match>
[](geometry_msgs::Vector3::ConstPtr& data){std::cout<<data->x<<std::endl;});
^
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:85:50: note: conversion of argument 1 would be ill-formed:
In file included from /usr/include/boost/function/detail/maybe_include.hpp:18:0,
from /usr/include/boost/function/detail/function_iterate.hpp:14,
from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
from /usr/include/boost/function.hpp:64,
from /opt/ros/melodic/include/ros/forwards.h:40,
from /opt/ros/melodic/include/ros/common.h:37,
from /opt/ros/melodic/include/ros/ros.h:43,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.h:7,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:2:
/usr/include/boost/function/function_template.hpp:159:11: error: binding reference of type ‘geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr& {aka boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&}’ to ‘const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >’ discards qualifiers
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
^
/usr/include/boost/function/function_template.hpp: In instantiation of ‘static void boost::detail::function::void_function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&]’:
/usr/include/boost/function/function_template.hpp:925:38: required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&]’
/usr/include/boost/function/function_template.hpp:716:7: required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/usr/include/boost/function/function_template.hpp:1061:16: required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:89:83: required from here
/usr/include/boost/function/function_template.hpp:159:11: error: no match for call to ‘(TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>) (const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&)’
/usr/include/boost/function/function_template.hpp:159:11: note: candidate: void (*)(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&) {aka void (*)(boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&)} <conversion>
/usr/include/boost/function/function_template.hpp:159:11: note: conversion of argument 2 would be ill-formed:
/usr/include/boost/function/function_template.hpp:159:11: error: binding reference of type ‘geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr& {aka boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&}’ to ‘const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >’ discards qualifiers
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:89:50: note: candidate: TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)> <near match>
[](geometry_msgs::Vector3::ConstPtr& data){std::cout<<data->x<<std::endl;});
^
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:89:50: note: conversion of argument 1 would be ill-formed:
In file included from /usr/include/boost/function/detail/maybe_include.hpp:18:0,
from /usr/include/boost/function/detail/function_iterate.hpp:14,
from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
from /usr/include/boost/function.hpp:64,
from /opt/ros/melodic/include/ros/forwards.h:40,
from /opt/ros/melodic/include/ros/common.h:37,
from /opt/ros/melodic/include/ros/ros.h:43,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.h:7,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:2:
/usr/include/boost/function/function_template.hpp:159:11: error: binding reference of type ‘geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr& {aka boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&}’ to ‘const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >’ discards qualifiers
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
^
gui_pkg/CMakeFiles/TCPSERVER.dir/build.make:62: recipe for target 'gui_pkg/CMakeFiles/TCPSERVER.dir/src/tcpserver.cpp.o' failed
make[2]: *** [gui_pkg/CMakeFiles/TCPSERVER.dir/src/tcpserver.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:1735: recipe for target 'gui_pkg/CMakeFiles/TCPSERVER.dir/all' failed
make[1]: *** [gui_pkg/CMakeFiles/TCPSERVER.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
when i used the regular function callback as shown below, it works fine
rand_dat1_sub_handle = node.subscribe<geometry_msgs::Vector3>(
"random/data1", 100,
&TCPServer::update_data1, this);
How do I use lamdas properly to represent callbacks in subscriber nodes?
I've edited the question showing the new errors after switching from geometry_msgs::Vector3Ptr& to geometry_msgs::Vector3::ConstPtr&.

using std::bind with std::reference_wrapper::get

I'm trying to use std::bind to call std::reference_wrapper::get but I can't get it to compile. I'm sure I'm overlooking something obvious but the compiler errors are not helping me out. This code is contrived and doesn't represent my actual use case:
#include <functional>
#include <iostream>
struct A
{
void p() {std::cout << this << '\n';};
};
using ARef = std::reference_wrapper< A >;
int main()
{
A a;
a.p();
auto p = std::bind (&A::p, std::placeholders::_1);
p (a); // ok
ARef ar (a);
p (ar.get()); // ok
auto get = std::bind (&ARef::get, std::placeholders::_1);
p (get (ar)); // error
}
Edit: This compiles fine with clang.
gcc 6.3.0 output: http://coliru.stacked-crooked.com/a/00bffc7549193cb8
main.cpp: In function 'int main()':
main.cpp:21:19: error: no match for call to '(std::_Bind<std::_Mem_fn<A& (std::reference_wrapper<A>::*)() const noexcept>(std::_Placeholder<1>)>) (ARef&)'
p (get (ar)); // error
^
In file included from main.cpp:1:0:
/usr/local/include/c++/6.3.0/functional:989:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) [with _Args = {_Args ...}; _Result = _Result; _Functor = std::_Mem_fn<A& (std::reference_wrapper<A>::*)() const noexcept>; _Bound_args = {std::_Placeholder<1>}]
operator()(_Args&&... __args)
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:989:2: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional:985:39: error: no match for call to '(std::_Mem_fn<A& (std::reference_wrapper<A>::*)() const noexcept>) (std::reference_wrapper<A>&)'
= decltype( std::declval<_Functor&>()(
~~~~~~~~~~~~~~~~~~~~~~~~~^
_Mu<_Bound_args>()( std::declval<_Bound_args&>(),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
std::declval<tuple<_Args...>&>() )... ) )>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/6.3.0/functional:600:2: note: candidate: template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _MemFunPtr = A& (std::reference_wrapper<A>::*)() const noexcept; bool __is_mem_fn = true]
operator()(_Args&&... __args) const
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:600:2: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional: In substitution of 'template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {std::reference_wrapper<A>&}]':
/usr/local/include/c++/6.3.0/functional:985:39: required from here
/usr/local/include/c++/6.3.0/functional:603:27: error: no matching function for call to '__invoke(A& (std::reference_wrapper<A>::* const&)() const noexcept, std::reference_wrapper<A>&)'
-> decltype(std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/6.3.0/functional:245:5: note: candidate: template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...)
__invoke(_Callable&& __fn, _Args&&... __args)
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:245:5: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional: In substitution of 'template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = A& (std::reference_wrapper<A>::* const&)() const noexcept; _Args = {std::reference_wrapper<A>&}]':
/usr/local/include/c++/6.3.0/functional:603:27: required by substitution of 'template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {std::reference_wrapper<A>&}]'
/usr/local/include/c++/6.3.0/functional:985:39: required from here
/usr/local/include/c++/6.3.0/functional:245:5: error: no type named 'type' in 'class std::result_of<A& (std::reference_wrapper<A>::* const&(std::reference_wrapper<A>&))() const noexcept>'
/usr/local/include/c++/6.3.0/functional:1003:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _Result = _Result; _Functor = std::_Mem_fn<A& (std::reference_wrapper<A>::*)() const noexcept>; _Bound_args = {std::_Placeholder<1>}]
operator()(_Args&&... __args) const
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:1003:2: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional:999:53: error: no match for call to '(const std::_Mem_fn<A& (std::reference_wrapper<A>::*)() const noexcept>) (std::reference_wrapper<A>&)'
= decltype( std::declval<typename enable_if<(sizeof...(_Args) >= 0),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
typename add_const<_Functor>::type&>::type>()(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/local/include/c++/6.3.0/functional:600:2: note: candidate: template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _MemFunPtr = A& (std::reference_wrapper<A>::*)() const noexcept; bool __is_mem_fn = true]
operator()(_Args&&... __args) const
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:600:2: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional: In substitution of 'template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {std::reference_wrapper<A>&}]':
/usr/local/include/c++/6.3.0/functional:999:53: required from here
/usr/local/include/c++/6.3.0/functional:603:27: error: no matching function for call to '__invoke(A& (std::reference_wrapper<A>::* const&)() const noexcept, std::reference_wrapper<A>&)'
-> decltype(std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/6.3.0/functional:245:5: note: candidate: template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...)
__invoke(_Callable&& __fn, _Args&&... __args)
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:245:5: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional: In substitution of 'template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = A& (std::reference_wrapper<A>::* const&)() const noexcept; _Args = {std::reference_wrapper<A>&}]':
/usr/local/include/c++/6.3.0/functional:603:27: required by substitution of 'template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {std::reference_wrapper<A>&}]'
/usr/local/include/c++/6.3.0/functional:999:53: required from here
/usr/local/include/c++/6.3.0/functional:245:5: error: no type named 'type' in 'class std::result_of<A& (std::reference_wrapper<A>::* const&(std::reference_wrapper<A>&))() const noexcept>'
/usr/local/include/c++/6.3.0/functional:1017:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = std::_Mem_fn<A& (std::reference_wrapper<A>::*)() const noexcept>; _Bound_args = {std::_Placeholder<1>}]
operator()(_Args&&... __args) volatile
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:1017:2: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional:1013:70: error: no match for call to '(volatile std::_Mem_fn<A& (std::reference_wrapper<A>::*)() const noexcept>) (std::reference_wrapper<A>&)'
= decltype( std::declval<typename enable_if<(sizeof...(_Args) >= 0),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
typename add_volatile<_Functor>::type&>::type>()(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/local/include/c++/6.3.0/functional:600:2: note: candidate: template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _MemFunPtr = A& (std::reference_wrapper<A>::*)() const noexcept; bool __is_mem_fn = true]
operator()(_Args&&... __args) const
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:600:2: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional: In substitution of 'template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {std::reference_wrapper<A>&}]':
/usr/local/include/c++/6.3.0/functional:1013:70: required from here
/usr/local/include/c++/6.3.0/functional:603:27: error: no matching function for call to '__invoke(A& (std::reference_wrapper<A>::* const&)() const noexcept, std::reference_wrapper<A>&)'
-> decltype(std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/6.3.0/functional:245:5: note: candidate: template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...)
__invoke(_Callable&& __fn, _Args&&... __args)
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:245:5: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional: In substitution of 'template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = A& (std::reference_wrapper<A>::* const&)() const noexcept; _Args = {std::reference_wrapper<A>&}]':
/usr/local/include/c++/6.3.0/functional:603:27: required by substitution of 'template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {std::reference_wrapper<A>&}]'
/usr/local/include/c++/6.3.0/functional:1013:70: required from here
/usr/local/include/c++/6.3.0/functional:245:5: error: no type named 'type' in 'class std::result_of<A& (std::reference_wrapper<A>::* const&(std::reference_wrapper<A>&))() const noexcept>'
/usr/local/include/c++/6.3.0/functional:1031:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = std::_Mem_fn<A& (std::reference_wrapper<A>::*)() const noexcept>; _Bound_args = {std::_Placeholder<1>}]
operator()(_Args&&... __args) const volatile
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:1031:2: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional:1027:64: error: no match for call to '(const volatile std::_Mem_fn<A& (std::reference_wrapper<A>::*)() const noexcept>) (std::reference_wrapper<A>&)'
= decltype( std::declval<typename enable_if<(sizeof...(_Args) >= 0),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
typename add_cv<_Functor>::type&>::type>()(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/local/include/c++/6.3.0/functional:600:2: note: candidate: template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _MemFunPtr = A& (std::reference_wrapper<A>::*)() const noexcept; bool __is_mem_fn = true]
operator()(_Args&&... __args) const
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:600:2: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional: In substitution of 'template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {std::reference_wrapper<A>&}]':
/usr/local/include/c++/6.3.0/functional:1027:64: required from here
/usr/local/include/c++/6.3.0/functional:603:27: error: no matching function for call to '__invoke(A& (std::reference_wrapper<A>::* const&)() const noexcept, std::reference_wrapper<A>&)'
-> decltype(std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/6.3.0/functional:245:5: note: candidate: template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...)
__invoke(_Callable&& __fn, _Args&&... __args)
^~~~~~~~
/usr/local/include/c++/6.3.0/functional:245:5: note: template argument deduction/substitution failed:
/usr/local/include/c++/6.3.0/functional: In substitution of 'template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = A& (std::reference_wrapper<A>::* const&)() const noexcept; _Args = {std::reference_wrapper<A>&}]':
/usr/local/include/c++/6.3.0/functional:603:27: required by substitution of 'template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {std::reference_wrapper<A>&}]'
/usr/local/include/c++/6.3.0/functional:1027:64: required from here
/usr/local/include/c++/6.3.0/functional:245:5: error: no type named 'type' in 'class std::result_of<A& (std::reference_wrapper<A>::* const&(std::reference_wrapper<A>&))() const noexcept>'
It is illegal to take the address of standard library member functions, because implementations can add overloads and mutilate their signatures at will. Therefore, the standard library, and in particular the INVOKE protocol used by bind and friends, is designed around the assumption that it won't be passed a pointer to member of std::reference_wrapper. Invoking a pointer to member pm with a reference_wrapper r is equivalent to invoking pm with r.get(); i.e., the reference is unconditionally unwrapped.
See also LWG issue 2219, which added reference_wrapper handling to INVOKE.

Where is piecewise_construct for boost::container::map::emplace()?

Using Boost, I am trying to emplace() a key/value pair into a boost::container::map. The value needs multiple arguments for the constructor. From what I've been able to find, I need to use piecewise_construct and pass the constructor args in tuples. This works with std::map<K,V>, but I can't get it to work using boost::container::map<K,V> The closest Boost doc I can find shows boost::unordered_multimap<K,V>, but not a plain map<K,V>.
#include <map>
#include <boost/tuple/tuple.hpp>
#include <boost/container/map.hpp>
#include <boost/unordered_set.hpp>
class A {
public:
/**/ A( int ) { }
bool operator<( const A & ) const { return false; }
} ;
class B {
public:
/**/ B( int, const char * ) { }
} ;
int
main( int, char ** )
{
A a( 100 );
B b( 200, "foo" );
std::map<A,B> mgood;
mgood.emplace( std::piecewise_construct,
std::make_tuple( 100 ),
std::make_tuple( 200, "Hello" ) );
#if 1
boost::container::map<A,B> mbad;
mbad.emplace( boost::unordered::piecewise_construct,
boost::make_tuple( 300 ),
boost::make_tuple( 400, "World" ) );
#endif
}
The g++-4.9.2 error messages are impenetrable (to me, anyway):
make -k tst g++ -DBOOST_LOG_DYN_LINK -g -std=c++11 -c -o tst.o
tst.cc In file included from
/usr/local/include/boost/container/detail/tree.hpp:25:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp: In
instantiation of âstatic void
boost::container::allocator_traits::priv_construct(boost::move_detail::false_type,
Allocator&, T*, Args&& ...) [with T =
boost::container::container_detail::pair; Args = {const
boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Allocator =
boost::container::new_allocator, void*, (boost::container::tree_type_enum)0u, true> >;
boost::move_detail::false_type =
boost::move_detail::integral_constant]â:
/usr/local/include/boost/container/allocator_traits.hpp:353:86:
required from âstatic void
boost::container::allocator_traits::construct(Allocator&,
T*, Args&& ...) [with T = boost::container::container_detail::pair; Args = {const boost::unordered::piecewise_construct_t&,
boost::tuples::tuple,
boost::tuples::tuple}; Allocator =
boost::container::new_allocator, void*, (boost::container::tree_type_enum)0u, true> >]â
/usr/local/include/boost/container/detail/node_alloc_holder.hpp:167:81:
required from
âboost::container::container_detail::node_alloc_holder::NodePtr
boost::container::container_detail::node_alloc_holder::create_node(Args&& ...) [with Args = {const
boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Allocator =
boost::container::new_allocator >; ICont =
boost::intrusive::rbtree_impl, void*, (boost::container::tree_type_enum)0u, true>,
boost::intrusive::rbtree_node_traits,
(boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>,
void,
boost::container::value_to_node_compare, void*, (boost::container::tree_type_enum)0u, true>,
boost::intrusive::tree_value_compare,
std::less,
boost::container::container_detail::select1st >
, long unsigned int, true, void>; boost::container::container_detail::node_alloc_holder::NodePtr =
boost::container::container_detail::tree_node,
void*, (boost::container::tree_type_enum)0u, true>]â
/usr/local/include/boost/container/detail/tree.hpp:922:94: required
from
âstd::pair,
Options:: tree_type, Options:: optimize_size>::type::iterator, false>,
bool> boost::container::container_detail::tree::emplace_unique(Args&& ...) [with Args =
{const boost::unordered::piecewise_construct_t&,
boost::tuples::tuple,
boost::tuples::tuple}; Key = A; T = std::pair;
KeyOfValue =
boost::container::container_detail::select1st >;
Compare = std::less; Allocator =
boost::container::new_allocator >; Options =
boost::container::tree_opt<(boost::container::tree_type_enum)0u,
true>; typename
boost::container::container_detail::intrusive_tree_type,
Options:: tree_type, Options:: optimize_size>::type::iterator =
boost::intrusive::tree_iterator, void*, (boost::container::tree_type_enum)0u, true>,
boost::intrusive::rbtree_node_traits,
(boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>,
false>]â /usr/local/include/boost/container/map.hpp:665:72:
required from âstd::pair, boost::container::container_detail::select1st >, Compare, Allocator, MapOptions>::iterator, bool> boost::container::map::emplace(Args&& ...) [with Args = {const
boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Key = A; T = B;
Compare = std::less; Allocator =
boost::container::new_allocator >; MapOptions =
boost::container::tree_opt<(boost::container::tree_type_enum)0u,
true>; typename boost::container::container_detail::tree,
boost::container::container_detail::select1st >, Compare, Allocator, MapOptions>::iterator = boost::container::container_detail::iterator_from_iiterator, void*, (boost::container::tree_type_enum)0u, true>,
boost::intrusive::rbtree_node_traits,
(boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>,
false>, false>]â tst.cc:90:53: required from here
/usr/local/include/boost/container/allocator_traits.hpp:408:10: error:
no matching function for call to
âboost::container::container_detail::pair::pair(const
boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple)â
{ ::new((void)p, boost_container_new_t()) T(::boost::forward(args)...); }
^ /usr/local/include/boost/container/allocator_traits.hpp:408:10: note:
candidates are: In file included from
/usr/local/include/boost/container/detail/tree.hpp:36:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:146:4: note:
template
boost::container::container_detail::pair::pair(std::pair<_U1,
_U2>&&)
pair(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p)
^ /usr/local/include/boost/container/detail/pair.hpp:146:4: note: template argument deduction/substitution failed: In file included from
/usr/local/include/boost/container/detail/tree.hpp:25:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note:
types âstd::pair<_T1, _T2>â and âconst
boost::unordered::piecewise_construct_tâ have incompatible
cv-qualifiers
{ ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); }
^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:141:4: note:
boost::container::container_detail::pair::pair(std::pair<_T1,
_T2>&&) [with T1 = A; T2 = B]
pair(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p)
^ /usr/local/include/boost/container/detail/pair.hpp:141:4: note: candidate expects 1 argument, 3 provided
/usr/local/include/boost/container/detail/pair.hpp:137:4: note:
template
boost::container::container_detail::pair::pair(const
std::pair<_U1, _U2>&)
pair(const std::pair& p)
^ /usr/local/include/boost/container/detail/pair.hpp:137:4: note: template argument deduction/substitution failed: In file included from
/usr/local/include/boost/container/detail/tree.hpp:25:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note:
âconst boost::unordered::piecewise_construct_tâ is not derived
from âconst std::pair<_T1, _T2>â
{ ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); }
^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:132:4: note:
boost::container::container_detail::pair::pair(const
std::pair<_T1, _T2>&) [with T1 = A; T2 = B]
pair(const std::pair& x)
^ /usr/local/include/boost/container/detail/pair.hpp:132:4: note: candidate expects 1 argument, 3 provided
/usr/local/include/boost/container/detail/pair.hpp:126:4: note:
template
boost::container::container_detail::pair::pair(U&&, V&&)
pair(BOOST_FWD_REF(U) u, BOOST_FWD_REF(V) v)
^ /usr/local/include/boost/container/detail/pair.hpp:126:4: note: template argument deduction/substitution failed: In file included from
/usr/local/include/boost/container/detail/tree.hpp:25:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note:
candidate expects 2 arguments, 3 provided
{ ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); }
^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:120:4: note:
boost::container::container_detail::pair::pair(const T1&,
const T2&) [with T1 = A; T2 = B]
pair(const T1 &t1, const T2 &t2)
^ /usr/local/include/boost/container/detail/pair.hpp:120:4: note: candidate expects 2 arguments, 3 provided
/usr/local/include/boost/container/detail/pair.hpp:115:4: note:
template
boost::container::container_detail::pair::pair(boost::container::container_detail::pair&&)
pair(BOOST_RV_REF_BEG pair BOOST_RV_REF_END p)
^ /usr/local/include/boost/container/detail/pair.hpp:115:4: note: template argument deduction/substitution failed: In file included from
/usr/local/include/boost/container/detail/tree.hpp:25:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note:
types âboost::container::container_detail::pairâ and
âconst boost::unordered::piecewise_construct_tâ have incompatible
cv-qualifiers
{ ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); }
^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:110:4: note:
template
boost::container::container_detail::pair::pair(const
boost::container::container_detail::pair&)
pair(const pair &p)
^ /usr/local/include/boost/container/detail/pair.hpp:110:4: note: template argument deduction/substitution failed: In file included from
/usr/local/include/boost/container/detail/tree.hpp:25:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note:
âconst boost::unordered::piecewise_construct_tâ is not derived
from âconst boost::container::container_detail::pairâ
{ ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); }
^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0,
from /usr/local/include/boost/container/map.hpp:30,
from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:105:4: note:
boost::container::container_detail::pair::pair(boost::container::container_detail::pair&&) [with T1
= A; T2 = B]
pair(BOOST_RV_REF(pair) p)
^ /usr/local/include/boost/container/detail/pair.hpp:105:4: note: candidate expects 1 argument, 3 provided
/usr/local/include/boost/container/detail/pair.hpp:100:4: note:
boost::container::container_detail::pair::pair(const
boost::container::container_detail::pair&) [with T1 = A; T2 =
B]
pair(const pair& x)
^ /usr/local/include/boost/container/detail/pair.hpp:100:4: note: candidate expects 1 argument, 3 provided
/usr/local/include/boost/container/detail/pair.hpp:95:4: note:
boost::container::container_detail::pair::pair() [with T1 = A;
T2 = B]
pair()
^ /usr/local/include/boost/container/detail/pair.hpp:95:4: note: candidate expects 0 arguments, 3 provided : recipe for target
'tst.o' failed make: *** [tst.o] Error 1 make: Target 'tst' not remade
because of errors.
Compilation exited abnormally with code 2 at Sat Apr 2 17:11:28
Can you point me in a useful direction? (I'd prefer not to mix boost and std containers; it should be possible to emplace into a boost::container::map, right?)
It appears that piecewise_construct is not implemented for boost::pair (which is the type for boost::container::map entries). See .../boost/container/detail/pair.hpp:151:
//piecewise_construct missing
//template <class U, class V> pair(pair<U, V>&& p);
//template <class... Args1, class... Args2>
// pair(piecewise_construct_t, tuple<Args1...> first_args,
// tuple<Args2...> second_args);
I guess the implementation for this is tough.
piecewise_construct support for both C++03 and C++11 capable compilers was added in commit:
https://github.com/boostorg/container/commit/79a75f470e75f35f5f2a91e10fcc67d03b0a2160
and will be officially released in Boost 1.62. The following code compiles fine:
#include <boost/tuple/tuple.hpp>
#include <tuple>
#include <boost/container/map.hpp>
class A {
public:
/**/ A( int ) { }
bool operator<( const A & ) const { return false; }
} ;
class B {
public:
/**/ B( int, const char * ) { }
} ;
int main( int, char *[] )
{
A a( 100 );
B b( 200, "foo" );
boost::container::map<A,B> m;
//1) Both Boost.Tuple and std tuple supported
//2) std:: or boost::container::piecewise_construct supported
m.emplace( boost::container::piecewise_construct,
boost::make_tuple( 300 ),
boost::make_tuple( 400, "World" ) );
m.emplace( std::piecewise_construct,
std::make_tuple( 400 ),
std::make_tuple( 500, "World2" ) );
}

Convert C *FILE to C++ iostream with boost

I am fairly new to C++ and wanted to convert a *FILE (such as returned by popen()) to a iostream to be used with functions such as getline etc. I found the following code http://fw-geekycoder.blogspot.co.za/2011/06/how-to-convert-c-file-to-c-iostream.html, as well as similar code from a bunch of places, but the compiler moans about boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink> bis(fd); and boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink> bis(fd);
#include <iostream>
#include <cstdio>
#include <unistd.h>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
void write() {
FILE* fp = fopen("whatever.txt", "w");
if (fp == NULL) {
perror("fopen error");
}
int fd = fileno(fp);
boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink> bis(fd);
std::ostream os(&bis);
os << "Hello World!" << std::endl;
fclose(fp);
}
void read() {
FILE* fp = fopen("whatever.txt", "r");
if (fp == NULL) {
perror("fopen error");
}
int fd = fileno(fp);
boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_source> bis(fd);
std::istream is(&bis);
while (is) {
std::string line;
std::getline(is, line);
std::cout << line << std::endl;
}
fclose(fp);
}
int main() {
write();
read();
return 0;
}
It seems like my system finds boost, but as if the API or something changed. What is the problem, here is my output from eclipse:
make all
Building file: ../src/boostPopenHandler.cpp
Invoking: GCC C++ Compiler
g++ -D__GXX_EXPERIMENTAL_CXX0X__ -I../../emdw/src -I../../patrecII/src -I../../ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"src/boostPopenHandler.d" -MT"src/boostPopenHandler.d" -o"src/boostPopenHandler.o" "../src/boostPopenHandler.cpp"
In file included from ../src/boostPopenHandler.cpp:4:0:
/usr/include/boost/iostreams/device/file_descriptor.hpp: In instantiation of ‘boost::iostreams::file_descriptor_sink::file_descriptor_sink(const Path&, std::ios_base::openmode) [with Path = char; std::ios_base::openmode = std::_Ios_Openmode]’:
/usr/include/boost/iostreams/stream_buffer.hpp:94:5: required from ‘boost::iostreams::stream_buffer<T, Tr, Alloc, Mode>::stream_buffer(U100&, typename boost::disable_if<boost::is_same<U0, T> >::type*) [with U100 = char; T = boost::iostreams::file_descriptor_sink; Tr = std::char_traits<char>; Alloc = std::allocator<char>; Mode = boost::iostreams::output_seekable; typename boost::disable_if<boost::is_same<U0, T> >::type = void]’
../src/boostPopenHandler.cpp:13:83: required from here
/usr/include/boost/iostreams/device/file_descriptor.hpp:276:36: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
{ open(detail::path(path), mode); }
^
In file included from /usr/include/boost/iostreams/device/file_descriptor.hpp:26:0,
from ../src/boostPopenHandler.cpp:4:
/usr/include/boost/iostreams/detail/path.hpp:52:5: error: initializing argument 1 of ‘boost::iostreams::detail::path::path(const char*)’ [-fpermissive]
path(const char* p) : narrow_(p), wide_(), is_wide_(false) { }
^
In file included from ../src/boostPopenHandler.cpp:4:0:
/usr/include/boost/iostreams/device/file_descriptor.hpp: In instantiation of ‘boost::iostreams::file_descriptor_source::file_descriptor_source(const Path&, std::ios_base::openmode) [with Path = char; std::ios_base::openmode = std::_Ios_Openmode]’:
/usr/include/boost/iostreams/stream_buffer.hpp:94:5: required from ‘boost::iostreams::stream_buffer<T, Tr, Alloc, Mode>::stream_buffer(U100&, typename boost::disable_if<boost::is_same<U0, T> >::type*) [with U100 = char; T = boost::iostreams::file_descriptor_source; Tr = std::char_traits<char>; Alloc = std::allocator<char>; Mode = boost::iostreams::input_seekable; typename boost::disable_if<boost::is_same<U0, T> >::type = void]’
../src/boostPopenHandler.cpp:26:85: required from here
/usr/include/boost/iostreams/device/file_descriptor.hpp:194:36: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
{ open(detail::path(path), mode); }
^
In file included from /usr/include/boost/iostreams/device/file_descriptor.hpp:26:0,
from ../src/boostPopenHandler.cpp:4:
/usr/include/boost/iostreams/detail/path.hpp:52:5: error: initializing argument 1 of ‘boost::iostreams::detail::path::path(const char*)’ [-fpermissive]
path(const char* p) : narrow_(p), wide_(), is_wide_(false) { }
^
make: *** [src/boostPopenHandler.o] Error 1
Edit:Following the answer from Selçuk Cihan, I changed the relevant code to:
boost::iostreams::file_descriptor_source fds(fd);
boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink>
...
boost::iostreams::file_descriptor_source fds(fd);
boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_source>
But I still get a list of compile errors:
**** Build of configuration Debug for project boostPopenHandler ****
make all
Building file: ../src/boostPopenHandler.cpp
Invoking: GCC C++ Compiler
g++ -I../../emdw/src -I../../patrecII/src -I../../ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"src/boostPopenHandler.d" -MT"src/boostPopenHandler.d" -o"src/boostPopenHandler.o" "../src/boostPopenHandler.cpp"
In file included from ../src/boostPopenHandler.cpp:4:0:
/usr/include/boost/iostreams/device/file_descriptor.hpp: In instantiation of ‘boost::iostreams::file_descriptor_source::file_descriptor_source(const Path&, std::ios_base::openmode) [with Path = int; std::ios_base::openmode = std::_Ios_Openmode]’:
../src/boostPopenHandler.cpp:13:52: required from here
/usr/include/boost/iostreams/device/file_descriptor.hpp:194:36: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]
{ open(detail::path(path), mode); }
^
In file included from /usr/include/boost/iostreams/device/file_descriptor.hpp:26:0,
from ../src/boostPopenHandler.cpp:4:
/usr/include/boost/iostreams/detail/path.hpp:52:5: error: initializing argument 1 of ‘boost::iostreams::detail::path::path(const char*)’ [-fpermissive]
path(const char* p) : narrow_(p), wide_(), is_wide_(false) { }
^
In file included from ../src/boostPopenHandler.cpp:4:0:
/usr/include/boost/iostreams/device/file_descriptor.hpp: In instantiation of ‘boost::iostreams::file_descriptor_sink::file_descriptor_sink(const Path&, std::ios_base::openmode) [with Path = boost::iostreams::file_descriptor_source; std::ios_base::openmode = std::_Ios_Openmode]’:
/usr/include/boost/iostreams/stream_buffer.hpp:94:5: required from ‘boost::iostreams::stream_buffer<T, Tr, Alloc, Mode>::stream_buffer(U100&, typename boost::disable_if<boost::is_same<U0, T> >::type*) [with U100 = boost::iostreams::file_descriptor_source; T = boost::iostreams::file_descriptor_sink; Tr = std::char_traits<char>; Alloc = std::allocator<char>; Mode = boost::iostreams::output_seekable; typename boost::disable_if<boost::is_same<U0, T> >::type = void]’
../src/boostPopenHandler.cpp:14:84: required from here
/usr/include/boost/iostreams/device/file_descriptor.hpp:276:36: error: no matching function for call to ‘boost::iostreams::detail::path::path(const boost::iostreams::file_descriptor_source&)’
{ open(detail::path(path), mode); }
^
/usr/include/boost/iostreams/device/file_descriptor.hpp:276:36: note: candidates are:
In file included from /usr/include/boost/iostreams/device/file_descriptor.hpp:26:0,
from ../src/boostPopenHandler.cpp:4:
/usr/include/boost/iostreams/detail/path.hpp:138:5: note: boost::iostreams::detail::path::path(const wstring&)
path(const std::wstring&);
^
/usr/include/boost/iostreams/detail/path.hpp:138:5: note: no known conversion for argument 1 from ‘const boost::iostreams::file_descriptor_source’ to ‘const wstring& {aka const std::basic_string<wchar_t>&}’
/usr/include/boost/iostreams/detail/path.hpp:70:5: note: boost::iostreams::detail::path::path(const boost::iostreams::detail::path&)
path(const path& p)
^
/usr/include/boost/iostreams/detail/path.hpp:70:5: note: no known conversion for argument 1 from ‘const boost::iostreams::file_descriptor_source’ to ‘const boost::iostreams::detail::path&’
/usr/include/boost/iostreams/detail/path.hpp:64:14: note: template<class Path> boost::iostreams::detail::path::path(const Path&, typename Path::codecvt_type*)
explicit path(const Path& p, typename Path::codecvt_type* = 0)
^
/usr/include/boost/iostreams/detail/path.hpp:64:14: note: template argument deduction/substitution failed:
/usr/include/boost/iostreams/detail/path.hpp: In substitution of ‘template<class Path> boost::iostreams::detail::path::path(const Path&, typename Path::codecvt_type*) [with Path = boost::iostreams::file_descriptor_source]’:
/usr/include/boost/iostreams/device/file_descriptor.hpp:276:36: required from ‘boost::iostreams::file_descriptor_sink::file_descriptor_sink(const Path&, std::ios_base::openmode) [with Path = boost::iostreams::file_descriptor_source; std::ios_base::openmode = std::_Ios_Openmode]’
/usr/include/boost/iostreams/stream_buffer.hpp:94:5: required from ‘boost::iostreams::stream_buffer<T, Tr, Alloc, Mode>::stream_buffer(U100&, typename boost::disable_if<boost::is_same<U0, T> >::type*) [with U100 = boost::iostreams::file_descriptor_source; T = boost::iostreams::file_descriptor_sink; Tr = std::char_traits<char>; Alloc = std::allocator<char>; Mode = boost::iostreams::output_seekable; typename boost::disable_if<boost::is_same<U0, T> >::type = void]’
../src/boostPopenHandler.cpp:14:84: required from here
/usr/include/boost/iostreams/detail/path.hpp:64:14: error: no type named ‘codecvt_type’ in ‘class boost::iostreams::file_descriptor_source’
/usr/include/boost/iostreams/device/file_descriptor.hpp: In instantiation of ‘boost::iostreams::file_descriptor_sink::file_descriptor_sink(const Path&, std::ios_base::openmode) [with Path = boost::iostreams::file_descriptor_source; std::ios_base::openmode = std::_Ios_Openmode]’:
/usr/include/boost/iostreams/stream_buffer.hpp:94:5: required from ‘boost::iostreams::stream_buffer<T, Tr, Alloc, Mode>::stream_buffer(U100&, typename boost::disable_if<boost::is_same<U0, T> >::type*) [with U100 = boost::iostreams::file_descriptor_source; T = boost::iostreams::file_descriptor_sink; Tr = std::char_traits<char>; Alloc = std::allocator<char>; Mode = boost::iostreams::output_seekable; typename boost::disable_if<boost::is_same<U0, T> >::type = void]’
../src/boostPopenHandler.cpp:14:84: required from here
/usr/include/boost/iostreams/detail/path.hpp:57:14: note: template<class Path> boost::iostreams::detail::path::path(const Path&, typename Path::external_string_type*)
explicit path(const Path& p, typename Path::external_string_type* = 0)
^
/usr/include/boost/iostreams/detail/path.hpp:57:14: note: template argument deduction/substitution failed:
/usr/include/boost/iostreams/detail/path.hpp: In substitution of ‘template<class Path> boost::iostreams::detail::path::path(const Path&, typename Path::external_string_type*) [with Path = boost::iostreams::file_descriptor_source]’:
/usr/include/boost/iostreams/device/file_descriptor.hpp:276:36: required from ‘boost::iostreams::file_descriptor_sink::file_descriptor_sink(const Path&, std::ios_base::openmode) [with Path = boost::iostreams::file_descriptor_source; std::ios_base::openmode = std::_Ios_Openmode]’
/usr/include/boost/iostreams/stream_buffer.hpp:94:5: required from ‘boost::iostreams::stream_buffer<T, Tr, Alloc, Mode>::stream_buffer(U100&, typename boost::disable_if<boost::is_same<U0, T> >::type*) [with U100 = boost::iostreams::file_descriptor_source; T = boost::iostreams::file_descriptor_sink; Tr = std::char_traits<char>; Alloc = std::allocator<char>; Mode = boost::iostreams::output_seekable; typename boost::disable_if<boost::is_same<U0, T> >::type = void]’
../src/boostPopenHandler.cpp:14:84: required from here
/usr/include/boost/iostreams/detail/path.hpp:57:14: error: no type named ‘external_string_type’ in ‘class boost::iostreams::file_descriptor_source’
/usr/include/boost/iostreams/device/file_descriptor.hpp: In instantiation of ‘boost::iostreams::file_descriptor_sink::file_descriptor_sink(const Path&, std::ios_base::openmode) [with Path = boost::iostreams::file_descriptor_source; std::ios_base::openmode = std::_Ios_Openmode]’:
/usr/include/boost/iostreams/stream_buffer.hpp:94:5: required from ‘boost::iostreams::stream_buffer<T, Tr, Alloc, Mode>::stream_buffer(U100&, typename boost::disable_if<boost::is_same<U0, T> >::type*) [with U100 = boost::iostreams::file_descriptor_source; T = boost::iostreams::file_descriptor_sink; Tr = std::char_traits<char>; Alloc = std::allocator<char>; Mode = boost::iostreams::output_seekable; typename boost::disable_if<boost::is_same<U0, T> >::type = void]’
../src/boostPopenHandler.cpp:14:84: required from here
/usr/include/boost/iostreams/detail/path.hpp:52:5: note: boost::iostreams::detail::path::path(const char*)
path(const char* p) : narrow_(p), wide_(), is_wide_(false) { }
^
/usr/include/boost/iostreams/detail/path.hpp:52:5: note: no known conversion for argument 1 from ‘const boost::iostreams::file_descriptor_source’ to ‘const char*’
/usr/include/boost/iostreams/detail/path.hpp:49:5: note: boost::iostreams::detail::path::path(const string&)
path(const std::string& p) : narrow_(p), wide_(), is_wide_(false) { }
^
/usr/include/boost/iostreams/detail/path.hpp:49:5: note: no known conversion for argument 1 from ‘const boost::iostreams::file_descriptor_source’ to ‘const string& {aka const std::basic_string<char>&}’
/usr/include/boost/iostreams/detail/path.hpp:46:5: note: boost::iostreams::detail::path::path()
path() : narrow_(), wide_(), is_wide_(false) { }
^
/usr/include/boost/iostreams/detail/path.hpp:46:5: note: candidate expects 0 arguments, 1 provided
make: *** [src/boostPopenHandler.o] Error 1
Oh, you should be first declaring a file_descriptor_source as in
boost::iostreams::file_descriptor_source fds(fd);
and then comes your stream buffer
boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_source> bis(fds);
Edit:
Sorry for the confusion, that ctor with an int parameter is deprecated and it seems that you do not have that ctor because otherwise your code would compile perfectly. That is why the above code i supplied needs a second mandatory parameter of either boost::iostreams::never_close_handle or boost::iostreams::close_handle
So it should read
boost::iostreams::file_descriptor_source fds(fd, boost::iostreams::close_handle);
otherwise you would still get that error. And same fix goes with the file_descriptor_sink also.
Now as for how you should read the errors:
/usr/include/boost/iostreams/device/file_descriptor.hpp: In
instantiation of
‘boost::iostreams::file_descriptor_source::file_descriptor_source(const
Path&, std::ios_base::openmode) [with Path = char;
std::ios_base::openmode = std::_Ios_Openmode]’:
Says that it tried to instantiate a file_descriptor_source with a template parameter choice of
[with Path = char; std::ios_base::openmode = std::_Ios_Openmode]
Since you only supplied an integer, the compiler tried to match that version of the ctor and failed to make the conversion.
You don't need Boost for this.
wanted to convert a *FILE (such as returned by popen()) to a iostream
Use pstreams instead (disclaimer, I wrote it, if that matters).
Some compilers provide extensions to create a streambuf from a C file without needing Boost, e.g. with GCC:
#include <ext/stdio_filebuf.h>
...
__gnu_cxx::stdio_filebuf<char> fb(fp, std::ios::out);
std::ostream os(&fb);

gtkmm compiler error when connecting signal

I'm working on an application with a GUI and I'm having trouble when trying to emit a signal (sig_showList, from View) at the connect for another signal (signal_changed, from Gtk::ComboBox), I'd really appreciate your help. The code looks something like this:
"view.h"
class View{
private:
Gtk::ComboBox* combo;
sigc::signal<void,int> sig_showList;
public:
View();
...
};
"view.c"
#include "view.h"
View::View(Glib::RefPtr<Gtk::Builder>& builder){
builder -> get_widget("combo",combo);
combo->signal_changed().connect(sigc::mem_fun(&sig_showList,&sigc::signal<void,int>::emit));
...
}
I compile it with g++ -std=c++98 *.cpp -o out $(pkg-config gtkmm-3.0 --cflags --libs). The error I'm getting is:
In file included from /usr/include/sigc++-2.0/sigc++/functors/slot.h:7:0,
from /usr/include/sigc++-2.0/sigc++/signal_base.h:29,
from /usr/include/sigc++-2.0/sigc++/signal.h:8,
from /usr/include/sigc++-2.0/sigc++/sigc++.h:80,
from /usr/include/glibmm-2.4/glibmm/thread.h:58,
from /usr/include/glibmm-2.4/glibmm.h:87,
from /usr/include/gtkmm-3.0/gtkmm.h:87,
from vista.cpp:2:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h: In instantiation of ‘sigc::adaptor_functor<T_functor>::result_type sigc::adaptor_functor<T_functor>::operator()() const [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; sigc::adaptor_functor<T_functor>::result_type = void]’:
/usr/include/sigc++-2.0/sigc++/functors/slot.h:103:36: required from ‘static T_return sigc::internal::slot_call0<T_functor, T_return>::call_it(sigc::internal::slot_rep*) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:110:37: required from ‘static void* (* sigc::internal::slot_call0<T_functor, T_return>::address())(void*) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void; sigc::internal::hook = void* (*)(void*)]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:454:83: required from ‘sigc::slot0<T_return>::slot0(const T_functor&) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:1130:26: required from ‘sigc::slot<T_return, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>::slot(const T_functor&) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void]’
vista.cpp:80:105: required from here
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:251:21: error: no match for call to ‘(sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>) ()’
{ return functor_(); }
^
In file included from /usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:9:0,
from /usr/include/sigc++-2.0/sigc++/functors/slot.h:7,
from /usr/include/sigc++-2.0/sigc++/signal_base.h:29,
from /usr/include/sigc++-2.0/sigc++/signal.h:8,
from /usr/include/sigc++-2.0/sigc++/sigc++.h:80,
from /usr/include/glibmm-2.4/glibmm/thread.h:58,
from /usr/include/glibmm-2.4/glibmm.h:87,
from /usr/include/gtkmm-3.0/gtkmm.h:87,
from vista.cpp:2:
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:2373:7: note: candidate is:
class bound_const_mem_functor1
^
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:2402:12: note: T_return sigc::bound_const_mem_functor1<T_return, T_obj, T_arg1>::operator()(typename sigc::type_trait<T_arg3>::take) const [with T_return = void; T_obj = sigc::signal<void, int>; T_arg1 = const int&; typename sigc::type_trait<T_arg3>::take = const int&]
T_return operator()(typename type_trait<T_arg1>::take _A_a1) const
^
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:2402:12: note: candidate expects 1 argument, 0 provided
In file included from /usr/include/sigc++-2.0/sigc++/functors/slot.h:7:0,
from /usr/include/sigc++-2.0/sigc++/signal_base.h:29,
from /usr/include/sigc++-2.0/sigc++/signal.h:8,
from /usr/include/sigc++-2.0/sigc++/sigc++.h:80,
from /usr/include/glibmm-2.4/glibmm/thread.h:58,
from /usr/include/glibmm-2.4/glibmm.h:87,
from /usr/include/gtkmm-3.0/gtkmm.h:87,
from vista.cpp:2:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:251:21: error: return-statement with a value, in function returning 'void' [-fpermissive]
{ return functor_(); }
^
make: *** [all] Error 1
[The actual class is called "Vista"]
So well, I have no idea what that means! Moreover this had already happened and somehow I managed to solve it but after some reformat and redesign it showed up again and I don't know what to do. It definitely has to do with the combo->signal_clicked().connect(...) line, because when I remove it compiles fine.
I found out what was wrong: the signal I'm trying to emit is of type sigc::signal so it should take one int as an argument when emitted, but I wasn't passing any arguments
Please try to used below namespace:
namespace sigc { SIGC_FUNCTORS_HAVE_RESULT_TYPE }