diff options
author | Håvard Pettersen <havardpe@oath.com> | 2020-01-03 15:31:12 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2020-01-03 15:31:12 +0000 |
commit | 95a11020a168f9f068ac730f40eec0370571ca5a (patch) | |
tree | e23d798b336b025ae6cc93450ada77e98e21c4dc /vespalib/src/tests/overload/overload_test.cpp | |
parent | dbe3a67718104c4150ae770294c23d8a41f0a16c (diff) |
introduce overload class
and use it with std::visit when inspecting std::alternative
Diffstat (limited to 'vespalib/src/tests/overload/overload_test.cpp')
-rw-r--r-- | vespalib/src/tests/overload/overload_test.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/vespalib/src/tests/overload/overload_test.cpp b/vespalib/src/tests/overload/overload_test.cpp new file mode 100644 index 00000000000..ceae29ac02f --- /dev/null +++ b/vespalib/src/tests/overload/overload_test.cpp @@ -0,0 +1,19 @@ +// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/vespalib/util/overload.h> +#include <vespa/vespalib/gtest/gtest.h> +#include <variant> +#include <string> + +using namespace vespalib; + +TEST(OverloadTest, visit_with_overload_works) { + std::variant<std::string,int> a = 10; + std::variant<std::string,int> b = "foo"; + std::visit(overload{[](int v){ EXPECT_EQ(v,10); }, + [](const std::string &){ FAIL() << "invalid visit"; }}, a); + std::visit(overload{[](int){ FAIL() << "invalid visit"; }, + [](const std::string &v){ EXPECT_EQ(v, "foo"); }}, b); +} + +GTEST_MAIN_RUN_ALL_TESTS() |