kennen:lib:mem_fn
no way to compare when less than two revisions
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
— | kennen:lib:mem_fn [2019-11-20 15:50] (aktuell) – angelegt - Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== mem_fn() ====== | ||
+ | ''# | ||
+ | |||
+ | <code cpp> | ||
+ | template< | ||
+ | unspecified mem_fn(R T::* pm) | ||
+ | </ | ||
+ | | ||
+ | die über einen '' | ||
+ | |||
+ | ==== Parameter ==== | ||
+ | | '' | ||
+ | ==== Ergebnis ==== | ||
+ | Rückgabewert: | ||
+ | |||
+ | ==== Siehe auch ==== | ||
+ | [[bind]], | ||
+ | [[..: | ||
+ | [[..: | ||
+ | |||
+ | |||
+ | ==== Beispiel ==== | ||
+ | <code cpp mem_fn.cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | auto f = std:: | ||
+ | |||
+ | std::string woerter[] = { " | ||
+ | for(auto e : woerter) | ||
+ | { | ||
+ | std::cout << e << " : " << f(e) << ' | ||
+ | } | ||
+ | | ||
+ | // === überladene Methoden mit cast spezifiziert: | ||
+ | | ||
+ | // std:: | ||
+ | auto member = | ||
+ | static_cast< | ||
+ | |||
+ | auto fn = std:: | ||
+ | |||
+ | // std:: | ||
+ | auto binder = std:: | ||
+ | |||
+ | // === bind() auch ohne mem_fn() möglich: | ||
+ | | ||
+ | // std:: | ||
+ | auto binder2 = std:: | ||
+ | |||
+ | // === oder Lambda-Ausdruck: | ||
+ | |||
+ | auto lambda = [](std:: | ||
+ | -> std:: | ||
+ | { | ||
+ | return s.append(appendix); | ||
+ | }; | ||
+ | // trailing return type needed here, otherwise std:: | ||
+ | |||
+ | // std:: | ||
+ | auto f = std:: | ||
+ | |||
+ | std::string s = " | ||
+ | (s.*member)(" | ||
+ | fn(s, " of mem_fn" | ||
+ | binder(s); | ||
+ | binder2(s, " with placeholders" | ||
+ | lambda(s, " or lambda" | ||
+ | f(s, " as function" | ||
+ | |||
+ | std::cout << s << ' | ||
+ | } | ||
+ | </ | ||
+ | |||
kennen/lib/mem_fn.txt · Zuletzt geändert: 2019-11-20 15:50 von 127.0.0.1