Invoke c# là gì

      53
The concept of callable is defined in http://en.cppreference.com/w/cpp/concept/Callable.

Bạn đang xem: Invoke c# là gì

Bạn sẽ xem: In C++ 11

Suppose I have a callable object f that has one argument of type T* & return type void. f can be any callable type (a function object, a pointer to member function, a pointer lớn data member, etc). How can I invoke f?

Simply calling f(x) fails since f can be a pointer to member function or data member. Is there a simple way to hotline f? One possible solution is std::bind(f, x)(), but this solution becomes more complex when f has more arguments.


*

This is exactly what std::invoke does, but it won"t be standard until C++17. You can make your own version, but it can be pretty complicated if it is fully general.

Here"s the basic idea for two cases (code taken from cppreference.com):

template inline tự động INVOKE(F&& f, Args&&... Args) -> decltype(std::forward(f)(std::forward(args)...)) return std::forward(f)(std::forward(args)...);template inline tự động hóa INVOKE(T Base::*pmd, Derived&& ref) -> decltype(std::forward(ref).*pmd) return std::forward(ref).*pmd;

*

Rather than implementing INVOKE yourself, use one of the library features that uses it. In particular, std::reference_wrapper works. Thus you can have the effect of std::invoke(f, args...) with std::ref(f)(args...):

templateauto invoke(F f, Args&&... Args) -> decltype(std::ref(f)(std::forward(args)...)) return std::ref(f)(std::forward(args)...);I didn"t forward f because std::reference_wrapper requires that the object passed in is not an rvalue. Using std::bind instead of std::ref doesn"t fix the problem. What this means is that for a function object lượt thích this:

I found the technique from this paper



Use boost::hof::apply:

#include // ...boost::hof::apply(f, args...);boost::hof::apply performs the same operation that INVOKE does.

Xem thêm: Tên Đăng Nhập Là Gì - Tên Đăng Nhập Của Tài Khoản Shopee

Alternatively, use boost::hana::apply, which does the same thing



Thanks for contributing an answer lớn Stack Overflow!Please be sure to lớn answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to lớn other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Post Your Answer Discard

By clicking “Post Your Answer”, you agree lớn our terms of service, privacy policy và cookie policy

Not the answer you're looking for? Browse other questions tagged c++ callable or ask your own question.

Trying to call the first element of a parameter pack as a function và pass the rest of the pack to it as arguments
*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.


PREVIOUS

Involved in tức là gì

NEXT

Invoice trong xuất nhập vào là gì


Leave a Reply Cancel reply

Your e-mail address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.


BÀI coi NHIỀU


Lệnh ato là lệnh gì


Lượng xoàn tiếng anh là gì


Cấp phối giờ anh là gì


Tiền hiện đại số là gì


Giáo dục huấn luyện và đào tạo là gì


Đau vùng thắt lưng


Cấp đúng là gì


Hệ thống ahu là gì


*

Premium WordPress Themes that"s perfect for magazine & personal blog.


DANH MỤC


In Ấn Thủ Tục kỹ năng và kiến thức Tin Tức

ĐĂNG KÝ TIN


Leave this field empty if you"re human:

No Result
View All Result