Błędy kompilacji przy użyciu std :: bind w gcc 4.7
Mam wiele problemów z używaniemstd::bind
w różnych miejscach mojego kodu. Czasami działa, czasem nie, więc zakładam, że robię coś fundamentalnie złego.
O ile rozumiem, następujące podstawowe użyciestd::bind
powinien działać dobrze:
#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);
}
Z pewnością typbar_auto
jeststd::function<int(int)>
(typfoo
z 1int
związany z argumentem), więc dlaczegobar_fun
nie skompilować? Włączyłembar_fun_lvalue
ponieważ jakiś googling mi to pokazałwartości były kiedyś problematyczne. ale to niczego nie poprawiło.
To przypominaten błąd, ale to takie stare, nie spodziewam się, że będzie istotne.
Wyjście gcc nie jest szczególnie pouczające:
W pliku dołączonym z bindnew.cpp: 1: 0: /usr/include/c++/4.7/functional: W instancji 'static _Res std :: _ Function_handler <_Res (_ArgTypes ...), _Functor> :: ____vvoke (const std :: _ Any_data &, _ArgTypes ...) [z _Res = int; _Functor = std :: _ Bind)) (int, int)>; _ArgTypes = {int}] ': /usr/include/c++/4.7/functional: 2298:6: wymagane od' std :: function <_Res (_ArgTypes ...)> :: function (_Functor, typename std :: enable_if <(! std :: is_integral <_Functor> :: value), std :: function <_Res (_ArgTypes ...)> :: _ Useless> :: type) [with _Functor = std :: _ Bind)) (int, int )>; _Res = int; _ArgTypes = {int}; typename std :: enable_if <(! std :: is_integral <_Functor> :: value), std :: function <_Res (_ArgTypes ...)> :: _ Useless> :: type = std :: function :: _ Useless] ' bindnew.cpp: 15: 52: wymagany stąd /usr/include/c++/4.7/functional: 1912:40: błąd: brak dopasowania dla call to '(std :: _ Bind)) (int, int)>) (int ) '/usr/include/c++/4.7/functional: 1140:11: uwaga: kandydatami są: /usr/include/c++/4.7/functional: 1211:2: uwaga: template _Result std :: _ Bind <_Functor (_Bound_args. ..)> :: operator () (_ Args && ...) [z _Args = {_Args ...}; _Result = _Result; _Functor = int (*) (int, int); _Bound_args = {int, std :: _ Placeholder <2>}] /usr/include/c++/4.7/functional:1211:2: uwaga:
odrzucenie / zastąpienie argumentu szablonu: /usr/include/c++/4.7/functional :1206:35: błąd: nie można przekonwertować 'std :: _ No_tuple_element' na 'int' w przekazywaniu argumentów /usr/include/c++/4.7/functional: 1225: 2: uwaga: szablon _Result std :: _ Bind <_Functor (_Bound_args ...)> :: operator () (_ Args && ...) const [z _Args = {_Args ...}; _Result = _Result; _Functor = int (*) (int, int); _Bound_args = {int, std :: _ Placeholder <2>}] /usr/include/c++/4.7/functional:1225:2: uwaga:
odrzucenie / zastąpienie argumentu szablonu: /usr/include/c++/4.7/functional: 1219:35: błąd: nie można przekonwertować 'std :: _ No_tuple_element' na 'int' w przekazywaniu argumentu /usr/include/c++/4.7/functional: 1239: 2: uwaga: szablon _Result std :: _ Bind <_Functor (_Bound_args ...)> :: operator () (_ Args && ...) volatile [z _Args = {_Args ...}; _Result = _Result; _Functor = int (*) (int, int); _Bound_args = {int, std :: _ Placeholder <2>}] /usr/include/c++/4.7/functional:1239:2: uwaga:
odrzucenie / zastąpienie argumentu szablonu: /usr/include/c++/4.7/functional: 1233:35: błąd: nie można przekonwertować 'std :: _ No_tuple_element' na 'int' w przekazywaniu argumentu /usr/include/c++/4.7/functional: 1253: 2: uwaga: szablon _Result std :: _ Bind <_Functor (_Bound_args ...)> :: operator () (_ Args && ...) jest niestabilny [z _Args = {_Args ...}; _Result = _Result; _Functor = int (*) (int, int); _Bound_args = {int, std :: _ Placeholder <2>}] /usr/include/c++/4.7/functional: 1253:2: note: odrzucenie / zastąpienie argumentu szablonu nie powiodło się: /usr/include/c++/4.7/functional:1247 : 35: error: nie można przekonwertować 'std :: _ No_tuple_element' na 'int' w przekazywaniu argumentu