This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename F> | |
| void PrePost(F&& f) { | |
| std::cout << "pre\n"; | |
| std::forward<F>(f)(); | |
| std::cout << "post\n"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Foo { | |
| void operator()() const & { | |
| std::cout << "l-value" << "\n"; | |
| } | |
| void operator()() const && { | |
| std::cout << "r-value" << "\n"; | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Foo { | |
| // used when Foo instance is an l-value | |
| void operator()() const & { | |
| std::cout << "l-value" << "\n"; | |
| } | |
| // used when Foo isntance is an r-value | |
| void operator()() const && { | |
| std::cout << "r-value" << "\n"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename F> | |
| void PrePost(F&& f) { | |
| std::cout << "pre\n"; | |
| f(); | |
| std::cout << "post\n"; | |
| } | |
| int main() { | |
| double a = 1.1; | |
| double b = 2.2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename F> | |
| void PrePost(const F& f) { | |
| std::cout << "pre\n"; | |
| f(); | |
| std::cout << "post\n"; | |
| } | |
| int main() { | |
| double a = 1.1; | |
| double b = 2.2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename F, typename... ARGS> | |
| void PrePost(const F& f, ARGS&&...args) { | |
| std::cout << "pre\n"; | |
| f(std::forward<ARGS>(args)...); | |
| std::cout << "post\n"; | |
| } | |
| int main() { | |
| double a = 1.1; | |
| double b = 2.2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename F> | |
| void PrePost(const F& f) { | |
| std::cout << "pre\n"; | |
| f(); | |
| std::cout << "post\n"; | |
| } | |
| int main() { | |
| double a = 1.1; | |
| double b = 2.2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void PrePost(const std::function<void(void)>& f) { | |
| std::cout << "pre\n"; | |
| f(); | |
| std::cout << "post\n"; | |
| } | |
| int main() { | |
| double a = 1.1; | |
| double b = 2.2; | |
| double c = 3.3; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| double a = 1.1; | |
| double b = 2.2; | |
| class __lambda__ { | |
| public: | |
| __lambda__(double& a, double& b):a_(a),b_(b) {} | |
| void operator()() const { | |
| std::cout << "a: " << a_ << " - b: " << b_ << "\n"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| double a = 1.1; | |
| double b = 2.2; | |
| [&a, &b](){ | |
| std::cout << "a: " << a << " - b: " << b << "\n"; | |
| }(); |
NewerOlder