aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/overload/overload_test.cpp
blob: 4e0e1fbf315eb610df0da82603cbd85bdfd60d60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Copyright Yahoo. 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()