Skip to content

Commit

Permalink
Add example of using fplus::identity to get the value of a variant, i…
Browse files Browse the repository at this point in the history
…ssue #285
  • Loading branch information
Dobiasd committed Dec 25, 2023
1 parent 739c977 commit 1445d5d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/variant_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ TEST_CASE("variant_test - visit")
REQUIRE_EQ(print_output, "string 3");
print_output.clear();

// One can use fplus::identity to use visit_one as a getter:
const fplus::maybe<int> y = transform_result.visit_one(fplus::identity<int>);
std::cout << fplus::show_maybe(y) << std::endl;

// should not compile
//std::cout << int_or_string.visit(show_int, show_float) << std::endl;

Expand Down

0 comments on commit 1445d5d

Please sign in to comment.