Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Overloaded helper type #165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/fixed_containers/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ struct CompileTimeValuePrinter
{
};

template <class... Ts>
struct Overloaded : Ts...
{
using Ts::operator()...;
};

// a "void-like" type, but without the hassle
// e.g. EmptyValue& is a valid type
struct EmptyValue
Expand Down
18 changes: 18 additions & 0 deletions test/concepts_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

#include "fixed_containers/assert_or_abort.hpp"

#include <gtest/gtest.h>

#include <functional>
#include <variant>

namespace fixed_containers
{
Expand Down Expand Up @@ -51,4 +54,19 @@ static_assert(IsStructuralType<MockStructuralType>);
static_assert(ConstexprDefaultConstructible<MockNonStructuralType>);
static_assert(IsNotStructuralType<MockNonStructuralType>);

TEST(Concepts, Overloaded)
{
constexpr double RESULT = []()
{
Overloaded overloads{
[](double) -> double { return 3.0; },
[](const int&) -> double { return 5.0; },
};

std::variant<double, int> var1 = 9.0;
return std::visit(overloads, var1);
}();

static_assert(RESULT == 3.0);
}
} // namespace fixed_containers
Loading