From 9ac8978f5125182ac1bd9a1b68533bf9695f7289 Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Wed, 15 Feb 2017 12:51:52 +0100 Subject: [PATCH] Adds a test for polymorphic lambdas in match, resolves #140 --- test/lambda_overload_test.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/lambda_overload_test.cpp b/test/lambda_overload_test.cpp index 9e76d99..b7190e9 100644 --- a/test/lambda_overload_test.cpp +++ b/test/lambda_overload_test.cpp @@ -112,6 +112,37 @@ void test_match_overloads_capture() std::cout << "Got " << ok << " ok, " << err << " err" << std::endl; } +// See #140 +void test_match_overloads_otherwise() +#ifdef HAS_CPP14_SUPPORT +{ + + struct Center + { + }; + struct Indent + { + }; + struct Justify + { + }; + struct None + { + }; + + using Properties = mapbox::util::variant; + + Properties props = Justify{}; + + props.match([&](Center) { std::cout << "Center\n"; }, // + [&](Indent) { std::cout << "Indent\n"; }, // + [&](auto&&) { std::cout << "Otherwise\n"; }); // +} +#else +{ +} +#endif + int main() { test_lambda_overloads(); @@ -122,6 +153,7 @@ int main() test_match_singleton(); test_match_overloads(); test_match_overloads_capture(); + test_match_overloads_otherwise(); } #undef HAS_CPP14_SUPPORT