Ошибки компиляции с использованием std :: bind в gcc 4.7
У меня много проблем с использованиемstd::bind
в разных местах моего кода. Иногда это работает, иногда нет, поэтому я предполагаю, что делаю что-то в корне неправильно.
Насколько я понимаю, следующее основное использованиеstd::bind
должно работать нормально:
#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);
}
Конечно, типbar_auto
являетсяstd::function<int(int)>
(типfoo
с 1int
аргумент связан), так почему жеbar_fun
не скомпилировать? я включенbar_fun_lvalue
потому что гугл показал мне, чтоЗначения были проблематичными, но это ничего не исправило.
Это напоминаетэта ошибка, но это так старо, я не ожидаю, что это будет актуально.
Вывод gcc не особенно поучителен:
В файле, включенном в bindnew.cpp: 1: 0: /usr/include/c++/4.7/functional: в экземпляре '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: требуется от' std :: function <_Res (_ArgTypes ...)> :: function (_Functor, typename std :: enable_if <(! std :: is_integral <_Functor> :: value), std :: function <_Res (_ArgTypes ...)> :: _ Бесполезно> :: type) [with _Functor = std :: _ Bind)) (int, int )>; _Res = int; _ArgTypes = {int}; имя типа std :: enable_if <(! std :: is_integral <_Functor> :: value), std :: function <_Res (_ArgTypes ...)> :: _ Бесполезно> :: type = std :: function :: _ Бесполезно] ' bindnew.cpp: 15: 52: необходимо отсюда /usr/include/c++/4.7/functional:1912:40: ошибка: нет совпадения для вызова '(std :: _ Bind)) (int, int)>) (int ) '/usr/include/c++/4.7/functional:1140:11: примечание: кандидаты: /usr/include/c++/4.7/functional:1211:2: примечание: шаблон _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:
Ошибка вывода / замены аргумента шаблона: /usr/include/c++/4.7/functional:1206:35: ошибка: невозможно преобразовать 'std :: _ No_tuple_element' в 'int' при передаче аргумента /usr/include/c++/4.7/functional: 1225: 2: примечание: шаблон _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:
Ошибка вывода / замены аргумента шаблона: /usr/include/c++/4.7/functional:1219:35: ошибка: невозможно преобразовать 'std :: _ No_tuple_element' в 'int' при передаче аргумента /usr/include/c++/4.7/functional: 1239: 2: примечание: шаблон _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:
Ошибка вывода / замены аргумента шаблона: /usr/include/c++/4.7/functional:1233:35: ошибка: невозможно преобразовать 'std :: _ No_tuple_element' в 'int' при передаче аргумента /usr/include/c++/4.7/functional: 1253: 2: примечание: шаблон _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: note: сбой вывода / замены аргумента шаблона: /usr/include/c++/4.7/functional:1247 : 35: ошибка: невозможно преобразовать 'std :: _ No_tuple_element' в 'int' при передаче аргумента