diff --git a/include/cista/containers/hash_storage.h b/include/cista/containers/hash_storage.h index b094b5d6..ab6d3845 100644 --- a/include/cista/containers/hash_storage.h +++ b/include/cista/containers/hash_storage.h @@ -292,8 +292,8 @@ struct hash_storage { } hash_storage& operator=(hash_storage const& other) { + clear(); if (other.size() == 0U) { - clear(); return *this; } for (const auto& v : other) { diff --git a/include/cista/containers/variant.h b/include/cista/containers/variant.h index 9c4c2a4b..57b13020 100755 --- a/include/cista/containers/variant.h +++ b/include/cista/containers/variant.h @@ -438,6 +438,11 @@ using cista::variant; namespace std { +template +constexpr auto visit(Visitor&& vis, cista::variant&& v) { + v.apply(vis); +} + using cista::get; } // namespace std diff --git a/test/variant_test.cc b/test/variant_test.cc index 631a54e9..570503b9 100755 --- a/test/variant_test.cc +++ b/test/variant_test.cc @@ -241,3 +241,15 @@ TEST_CASE("variant get_if") { REQUIRE(str != nullptr); CHECK(*str == "hello test test test test"); } + +TEST_CASE("std visit") { + std::visit( + [](auto&& x) { + if constexpr (std::is_same_v>) { + CHECK(true); + } else { + CHECK(false); + } + }, + cista::variant{1}); +}