std::function::operator()
Материал из cppreference.com
< cpp | utility | functional | function
![]() |
Эта страница была переведена автоматически с английской версии вики используя Переводчик Google.
Перевод может содержать ошибки и странные формулировки. Наведите курсор на текст, чтобы увидеть оригинал. Вы можете помочь в исправлении ошибок и улучшении перевода. Для инструкций перейдите по ссылке. Щёлкните здесь, чтобы увидеть английскую версию этой страницы |
R operator()( ArgTypes... args ) const; |
(начиная с C++11) | |
Calls the stored callable function target with the parameters args
.
Содержание |
[править] Параметры
args | — | parameters to pass to the stored callable function target |
[править] Возвращаемое значение
None if R
is void. Otherwise the return value of the invocation of the stored callable object.
[править] Исключения
- std::bad_function_call if *this does not store a callable function target, !*this == true.
[править] Пример
The following example shows how std::function can passed to other functions by value. Also, it shown how std::function can store lambdas.
Запустить этот код
#include <iostream> #include <functional> void call(std::function<int()> f) // can be passed by value { std::cout << f() << '\n'; } int normal_function() { return 42; } int main() { int n = 1; std::function<int()> f = [&n](){ return n; }; call(f); n = 2; call(f); f = normal_function; call(f); }
Вывод:
1 2 42
[править] См. также
Этот раздел не завершён |