シグナルスロットのテンプレート関数をバインドする際のプレースホルダの使用

私はシグナリング中にテンプレート関数をバインドしようとしています。しかし、私がスロット関数でプレースホルダを使用すると、 "負の添字"コンパイラエラーが発生します。私はVisual Studioを使用しています ありがとう。

コード:

class My
{
private:
    boost::signals2::signal sig;

public:
    template < typename F, typename T, typename A1 >
    void proxy( F f, T t, A1 a1 )
    {
        boost::bind( f, t, a1 );   //this gets messaged elsewhere
    }

    int foo( int i )
    {
        return i-1;
    }

    int bar( int i )
    {
        return i+1;
    }

    template < typename F, typename T, typename A1 >
    boost::signals2::connection connect( F f, T t, A1 a1 )
    {
        return sig.connect( boost::bind( &My::proxy< F, T, A1 >, t, f, t, a1 ) );
    }

    void main()
    {
        boost::signals2::connection c1 = connect( &My::foo, this, 11 );    //ok
        boost::signals2::connection c2 = connect( &My::bar, this, _1 );    //negative subscript
    }
};

エラー:

boost/bind/arg.hpp(37) : error C2118: negative subscript
boost/bind/bind.hpp(450) : see reference to function template instantiation 'boost::arg::arg(const T &)' being compiled
with
[
    I=1,
    A1=int,
    T=int
]
boost/bind/bind_template.hpp(32) : see reference to function template instantiation 'void boost::_bi::list4::operator ()>(boost::_bi::type,F &,A &,int)' being compiled
with
[
    A1=boost::_bi::value,
    A2=boost::_bi::value,
    A3=boost::_bi::value,
    A4=boost::arg<1>,
    F=boost::_mfi::mf3<1>>,
    T=void,
    A=boost::_bi::list1
]
boost/function/function_template.hpp(153) : see reference to function template instantiation 'void boost::_bi::bind_t::operator ()(A1 &)' being compiled
with
[
    R=void,
    F=boost::_mfi::mf3<1>>,
    L=boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>,
    T0=int,
    A1=int
]
boost/function/function_template.hpp(147) : while compiling class template member function 'void boost::detail::function::void_function_obj_invoker1::invoke(boost::detail::function::function_buffer &,T0)'
with
[
    FunctionObj=boost::_bi::bind_t<1>>,boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>>,
    R=void,
    T0=int
]
boost/function/function_template.hpp(913) : see reference to class template instantiation 'boost::detail::function::void_function_obj_invoker1' being compiled
with
[
    FunctionObj=boost::_bi::bind_t<1>>,boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>>,
    R=void,
    T0=int
]
boost/function/function_template.hpp(722) : see reference to function template instantiation 'void boost::function1::assign_to(Functor)' being compiled
with
[
    R=void,
    T0=int,
    Functor=boost::_bi::bind_t<1>>,boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>>
]
boost/function/function_template.hpp(1065) : see reference to function template instantiation 'boost::function1::function1(Functor,int)' being compiled
with
[
    R=void,
    T0=int,
    F=boost::_bi::bind_t<1>>,boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>>,
    Functor=boost::_bi::bind_t<1>>,boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>>
]
boost/function/function_template.hpp(1105) : see reference to function template instantiation 'boost::function::function(Functor,int)' being compiled
with
[
    Signature=void (int),
    F=boost::_bi::bind_t<1>>,boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>>,
    Functor=boost::_bi::bind_t<1>>,boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>>
]
boost/signals2/detail/slot_template.hpp(137) : see reference to function template instantiation 'boost::function &boost::function::operator =(Functor)' being compiled
with
[
    Signature=void (int),
    F=boost::_bi::bind_t<1>>,boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>>,
    Functor=boost::_bi::bind_t<1>>,boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>>
]
boost/signals2/detail/slot_template.hpp(81) : see reference to function template instantiation 'void boost::signals2::slot1::init_slot_function(const F &)' being compiled
with
[
    R=void,
    T1=int,
    SlotFunction=boost::function,
    F=boost::_bi::bind_t<1>>,boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>>
]
test.cpp(179) : see reference to function template instantiation 'boost::signals2::slot1::slot1>(const boost::_bi::bind_t &)' being compiled
with
[
    R=void,
    T1=int,
    SlotFunction=boost::function,
    F=boost::_mfi::mf3<1>>,
    L=boost::_bi::list4,boost::_bi::value,boost::_bi::value,boost::arg<1>>
]
test.cpp(196) : see reference to function template instantiation 'boost::signals2::connection My::connect>(F,T,A1)' being compiled
with
[
    I=1,
    F=int (__thiscall My::* )(int),
    T=My *,
    A1=boost::arg<1>
]
1

1 答え

Possibly typo? The member function &My::proxy< F, T, A1 > in the question takes the placeholder _1's type itself instead of the actual parameter int.
So in this case, changing &My::proxy< F, T, A1 > to &My::proxy< F, T, int > will resolve the error.
Here is a test on ideone.

0
追加された
どういたしまして!私自身はしばしばこのようなタイプミスをします:)
追加された 著者 Ise Wisteria,
確かに、それは "タイプミス"でした...笑。プレースホルダを渡す正しい方法はわかりませんでしたが、プレースホルダがどのような型を表現しているのかコンパイラに何らかの形で伝えなければならないことが分かりました。ありがとう!
追加された 著者 user1005752,