Kompiliere Fehler mit std :: bind in gcc 4.7
Ich habe große Probleme bei der Verwendungstd::bind
an verschiedenen Stellen meines Codes. Manchmal funktioniert es, manchmal nicht, also gehe ich davon aus, dass ich etwas grundlegend Falsches tue.
Soweit ich verstehe, die folgende grundlegende Verwendung vonstd::bind
sollte gut funktionieren:
#include <functional>
int foo(int a, int b){ return a+b; }
int main(){
using namespace std::placeholders;
// works
auto bar_auto=std::bind(foo,1,_2);
// compile error
std::function<int(int)> bar_fun=std::bind(foo,1,_2);
int quux=1;
// compile error
std::function<int(int)> bar_fun_lvalue=std::bind(foo,quux,_2);
}
Sicher die Art vonbar_auto
iststd::function<int(int)>
(Art derfoo
mit 1int
Argument gebunden), also warumbar_fun
nicht kompilieren? Ich schloss einbar_fun_lvalue
weil mir ein bisschen googeln das gezeigt hatFrüher waren die Werte problematisch. aber das hat nichts behoben.
Es ähneltdieser Bug, aber das ist so alt, dass ich nicht erwarte, dass es relevant ist.
Die Ausgabe von gcc ist nicht besonders aufschlussreich:
In Datei aus bindnew.cpp enthalten: 1: 0: /usr/include/c++/4.7/functional: In Instantiierung von 'static _Res std :: _ Function_handler <_Res (_ArgTypes ...), _Functor> :: _ M_invoke (const std :: _ Any_data &, _ArgTypes ...) [with _Res = int; _Functor = std :: _ Bind)) (int, int)>; _ArgTypes = {int}] ': /usr/include/c++/4.7/functional:2298:6: erforderlich für' std :: function <_Res (_ArgTypes ...)> :: function (_Functor, Typname std :: enable_if <(! std :: is_integral <_Functor> :: value), std :: function <_Res (_ArgTypes ...)> :: _ Useless> :: type) [mit _Functor = std :: _ Bind)) (int, int )>; _Res = int; _ArgTypes = {int}; Typname std :: enable_if <(! std :: is_integral <_Functor> :: value), std :: function <_Res (_ArgTypes ...)> :: _ Useless> :: type = std :: function :: _ Useless] ' bindnew.cpp: 15: 52: erforderlich ab hier /usr/include/c++/4.7/functional:1912:40: Fehler: Keine Übereinstimmung für den Aufruf von '(std :: _ Bind)) (int, int)>) (int ) '/usr/include/c++/4.7/functional:1140:11: note: Kandidaten sind: /usr/include/c++/4.7/functional:1211:2: note: template _Result std :: _ Bind <_Functor (_Bound_args. ..)> :: operator () (_ Args && ...) [with _Args = {_Args ...}; _Result = _Result; _Functor = int (*) (int, int); _Bound_args = {int, std :: _ Placeholder <2>}] /usr/include/c++/4.7/functional:1211:2: note:
Abzug / Ersetzung des Template-Arguments fehlgeschlagen: /usr/include/c++/4.7/functional:1206:35: Fehler: Konvertierung von 'std :: _ No_tuple_element' in 'int' bei Übergabe des Arguments nicht möglich /usr/include/c+++/4.7/functional: 1225: 2: note: template _Result std :: _ Bind <_Functor (_Bound_args ...)> :: operator () (_ Args && ...) const [with _Args = {_Args ...}; _Result = _Result; _Functor = int (*) (int, int); _Bound_args = {int, std :: _ Placeholder <2>}] /usr/include/c++/4.7/functional:1225:2: note:
Abzug / Ersetzung des Template-Arguments fehlgeschlagen: /usr/include/c++/4.7/functional:1219:35: Fehler: Konvertierung von 'std :: _ No_tuple_element' in 'int' bei Übergabe des Arguments nicht möglich /usr/include/c+++/4.7/functional: 1239: 2: note: template _Result std :: _ Bind <_Functor (_Bound_args ...)> :: operator () (_ Args && ...) volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = int (*) (int, int); _Bound_args = {int, std :: _ Placeholder <2>}] /usr/include/c++/4.7/functional:1239:2: note:
Abzug / Ersetzung des Template-Arguments fehlgeschlagen: /usr/include/c++/4.7/functional:1233:35: Fehler: Konvertierung von 'std :: _ No_tuple_element' in 'int' bei Übergabe des Arguments nicht möglich /usr/include/c+++/4.7/functional: 1253: 2: note: template _Result std :: _ Bind <_Functor (_Bound_args ...)> :: operator () (_ Args && ...) const volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = int (*) (int, int); _Bound_args = {int, std :: _ Placeholder <2>}] /usr/include/c++/4.7/functional:1253:2: Hinweis: Der Abzug / die Ersetzung von Vorlagenargumenten ist fehlgeschlagen: /usr/include/c+++/4.7/functional:1247 : 35: Fehler: 'std :: _ No_tuple_element' kann bei der Übergabe von Argumenten nicht in 'int' konvertiert werden