Last active
October 5, 2018 10:30
-
-
Save acgetchell/6d31a905deee37388ef8ba695182ec81 to your computer and use it in GitHub Desktop.
The magic of function_ref. For more details see https://github.com/acgetchell/CDT-plusplus/commit/c2c59bb971064e1f1c0efc5815030b3b631f803b
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
| #include <utility> | |
| #include "Function_ref.h" | |
| #include "S3ErgodicMoves.h" | |
| #include "SimplicialManifold.h" | |
| auto increment_lambda = [](int a) { return ++a; }; | |
| function_ref<int(int)> lambda_ref(increment_lambda); | |
| increment_lambda(0); // = 1 | |
| lambda_ref(5); // = 6 | |
| SimplicialManifold test_universe(6400, 13); | |
| Move_tuple moves(std::make_tuple(0, 0, 0, 0, 0)); | |
| auto move_23_lambda = [](SimplicialManifold manifold, | |
| Move_tuple& attempted_moves) -> SimplicialManifold { | |
| return make_23_move(std::move(manifold), attempted_moves); | |
| }; | |
| function_ref<SimplicialManifold(SimplicialManifold, Move_tuple&)> complex_ref( | |
| move_23_lambda); | |
| test_universe = move_23_lambda(test_universe, moves); // compiles, fails at runtime | |
| test_universe2 = complex_ref(test_universe, moves); // works perfectly! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment