C++ Weekly - Ep 17 C++17's `std::invoke`

preview_player
Показать описание
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

This week I preview one of my favorite up coming new features of C++17: `std::invoke`. T-SHIRTS AVAILABLE!

WANT MORE JASON?

SUPPORT THE CHANNEL

GET INVOLVED

JASON'S BOOKS

► C++23 Best Practices

► C++ Best Practices

JASON'S PUZZLE BOOKS

► Object Lifetime Puzzlers Book 1

► Object Lifetime Puzzlers Book 2

► Object Lifetime Puzzlers Book 3

► Copy and Reference Puzzlers Book 1

► Copy and Reference Puzzlers Book 2

► Copy and Reference Puzzlers Book 3

► OpCode Puzzlers Book 1


RECOMMENDED BOOKS

AWESOME PROJECTS

O'Reilly VIDEOS

Рекомендации по теме
Комментарии
Автор

Its still unclear- why do we need std::invoke when we can simply call function

badassopenpolling
Автор

Thank you for this interesting topic that you covered. You talked about member function pointer that I did not manipulate too much with pedagogical examples for understanding this feature std::invoke from C++17

danielphd
Автор

Instead of

template <typename Function>
void Call(Function function) {
::std::invoke(function);
}

Why don't I just do this:

template <typename Function>
void Call(Function function) {
function();
}

? Or this:

void Call(::std::function<void()> function) {
function();
}

?? I'm really not getting the pointof invoke????

allyourcode
Автор

Jason, cool video as always, thank you. Did you test std::invoke in terms of perfromance? How does that compare to using a function pointer? If you haven't tested it yet, I just gave you an idea for next video :)

TrueWodzu
Автор

why does c++ documentation looks so scary to me :(

kuldeepadhikari
Автор

wonder what effect this would have if you placed it in a function expecting to call the method from a base type, but instead passed it a derived type with an override of that member

freeNode
Автор

interesting topic and great explanation. thank you for video

nullptr
Автор

Jason, by far I prefer the light solarized color scheme in your earlier videos in this series.

Best Wishes,
Jonathan

jonathanwatmough
Автор

could invoke be used to write to data member j also at the end there? e.g., does something like this work?: std::invoke(&S::j, s) = 6

stancartmankenny
Автор

What are some of the pros and cons of using std::invoke vs alternative methods like std::bind or s.do_something(5)?

DCOneFourSeven
Автор

Hey Jason,

What status bar are you using? It looks like airline or powerline but with some tweaks?

BradHubbardbadone
Автор

Could I use this to expose functions from a class to chaiscript?

GIJOEG
Автор

std::bind can do the SAME thing as std::invoke when they are used to call member function with an object, am I right? I mean std::invoke(&S::do_something, s, 42) can also be written in std::bind(...)

focker
Автор

So the differences between invoke and std::function are that the latter 1. gives a function object and then i need to invoke it 2. Need to know the exact signature for declaration. Right?

janasandeep
Автор

very nice explanation. Curious to know why do we need `const int `. can’t we just mention `int`.

Praveer
Автор

What's the difference compared to standard C function pointer calls:

Do you get better compiler error or anything else?

carstenhansen
Автор

What about function templates? It's a little verbose.

template<typename Func, typename... Args>
auto invoke_with_timing(Func&& func, Args&&... args)
{
boost::timer::auto_cpu_timer t;
return std::invoke(std::forward<Func>(func), std::forward<Args>(args)...);
}

int main()
{
std::vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
invoke_with_timing(std::sort<std::vector<int>::iterator, std::greater<>>,
v.begin(),
v.end(),
std::greater<>{});

std::copy(v.cbegin(), v.cend(), std::ostream_iterator<int>{std::cout, "\n"});

std::cin.get();
}

erhuncool