From a0cda88c6c64d624f7136ea60519f8432ce0a019 Mon Sep 17 00:00:00 2001 From: Evan <115374841+evanwporter@users.noreply.github.com> Date: Sun, 30 Mar 2025 09:26:36 -0700 Subject: [PATCH 1/7] Update get.hpp --- include/toml11/get.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/toml11/get.hpp b/include/toml11/get.hpp index 3805d09..ecf62c7 100644 --- a/include/toml11/get.hpp +++ b/include/toml11/get.hpp @@ -398,6 +398,25 @@ get(const basic_value& v) cxx::make_index_sequence::value>{}); } +// ============================================================================ +// std::unordered_set + +template +cxx::enable_if_t::value, T> +get(const basic_value& v) +{ + using value_type = T; + const auto& a = v.as_array(); + + std::unordered_set container; + for (const auto& elem : a) + { + container.insert(get(elem)); + } + return container; +} + + // ============================================================================ // map-like types; most likely STL map, like std::map or std::unordered_map. From a6de44505e570824db2dbe7195c9f0a201b5b7d1 Mon Sep 17 00:00:00 2001 From: Evan <115374841+evanwporter@users.noreply.github.com> Date: Sun, 30 Mar 2025 09:28:32 -0700 Subject: [PATCH 2/7] Update traits.hpp --- include/toml11/traits.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/toml11/traits.hpp b/include/toml11/traits.hpp index 49b7ff3..6121f02 100644 --- a/include/toml11/traits.hpp +++ b/include/toml11/traits.hpp @@ -165,6 +165,12 @@ struct is_std_tuple_impl> : std::true_type{}; template using is_std_tuple = is_std_tuple_impl>; +template struct is_unordered_set_impl : std::false_type {}; +template +struct is_unordered_set_impl> : std::true_type {}; +template +using is_unordered_set = is_unordered_set_impl>; + #if defined(TOML11_HAS_OPTIONAL) template struct is_std_optional_impl : std::false_type{}; template From 33b0d1a4d61dc3f8ba788b382ecf3463d8924adc Mon Sep 17 00:00:00 2001 From: Evan <115374841+evanwporter@users.noreply.github.com> Date: Sun, 30 Mar 2025 09:40:45 -0700 Subject: [PATCH 3/7] Update traits.hpp --- include/toml11/traits.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/toml11/traits.hpp b/include/toml11/traits.hpp index 6121f02..11575f4 100644 --- a/include/toml11/traits.hpp +++ b/include/toml11/traits.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #if defined(TOML11_HAS_STRING_VIEW) From db99017e996eed7e7d2eb67fe5f127d15cf139d1 Mon Sep 17 00:00:00 2001 From: Evan <115374841+evanwporter@users.noreply.github.com> Date: Sun, 30 Mar 2025 09:44:31 -0700 Subject: [PATCH 4/7] Update traits.hpp --- include/toml11/traits.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/toml11/traits.hpp b/include/toml11/traits.hpp index 11575f4..27ef1d4 100644 --- a/include/toml11/traits.hpp +++ b/include/toml11/traits.hpp @@ -167,8 +167,8 @@ template using is_std_tuple = is_std_tuple_impl>; template struct is_unordered_set_impl : std::false_type {}; -template -struct is_unordered_set_impl> : std::true_type {}; +template +struct is_unordered_set_impl> : std::true_type {}; template using is_unordered_set = is_unordered_set_impl>; From 924a6c5d50f478c13f58db9ff26c009e2cce616b Mon Sep 17 00:00:00 2001 From: Evan <115374841+evanwporter@users.noreply.github.com> Date: Sun, 30 Mar 2025 09:50:30 -0700 Subject: [PATCH 5/7] Update test_get.cpp --- tests/test_get.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_get.cpp b/tests/test_get.cpp index 3c00d2d..137ce0c 100644 --- a/tests/test_get.cpp +++ b/tests/test_get.cpp @@ -406,6 +406,44 @@ TEST_CASE("testing toml::get") } } +TEST_CASE("testing toml::get") +{ + using value_type = toml::value; + + { + const value_type v(toml::array{1, 2, 3, 4}); + const std::unordered_set uset = toml::get>(v); + + CHECK_EQ(uset.size(), 4u); + CHECK(uset.count(1) == 1); + CHECK(uset.count(2) == 1); + CHECK(uset.count(3) == 1); + CHECK(uset.count(4) == 1); + } + + { + const value_type v(toml::array{"alpha", "beta", "delta"}); + const std::unordered_set uset = toml::get>(v); + + CHECK_EQ(uset.size(), 3u); + CHECK(uset.count("alpha") == 1); + CHECK(uset.count("beta") == 1); + CHECK(uset.count("delta") == 1); + } + + { + value_type v(toml::array{42, 42, 54, 69}); + const std::unordered_set uset = toml::get>(std::move(v)); + + // Set will only have one "42" + CHECK_EQ(uset.size(), 3u); + CHECK(uset.count(42) == 1); + CHECK(uset.count(54) == 1); + CHECK(uset.count(69) == 1); + } +} + + TEST_CASE("testing toml::get") { using value_type = toml::value; From b58182191e6d2f043dcc278ffad941bcfdef20fd Mon Sep 17 00:00:00 2001 From: Evan <115374841+evanwporter@users.noreply.github.com> Date: Sun, 30 Mar 2025 17:01:42 +0000 Subject: [PATCH 6/7] tiny fix --- include/toml11/get.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/toml11/get.hpp b/include/toml11/get.hpp index ecf62c7..a147493 100644 --- a/include/toml11/get.hpp +++ b/include/toml11/get.hpp @@ -405,7 +405,7 @@ template cxx::enable_if_t::value, T> get(const basic_value& v) { - using value_type = T; + using value_type = typename T::value_type; const auto& a = v.as_array(); std::unordered_set container; From 3d9b9a2e63235df0e466708bbe3d1cec313ef26d Mon Sep 17 00:00:00 2001 From: Evan <115374841+evanwporter@users.noreply.github.com> Date: Sun, 30 Mar 2025 17:02:47 +0000 Subject: [PATCH 7/7] tinier fix --- include/toml11/get.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/toml11/get.hpp b/include/toml11/get.hpp index a147493..0704471 100644 --- a/include/toml11/get.hpp +++ b/include/toml11/get.hpp @@ -408,7 +408,7 @@ get(const basic_value& v) using value_type = typename T::value_type; const auto& a = v.as_array(); - std::unordered_set container; + T container; for (const auto& elem : a) { container.insert(get(elem));