Skip to content

add support for toml::get<std::unordered_set>#288

Merged
ToruNiina merged 7 commits intoToruNiina:mainfrom
evanwporter:patch-1
Mar 31, 2025
Merged

add support for toml::get<std::unordered_set>#288
ToruNiina merged 7 commits intoToruNiina:mainfrom
evanwporter:patch-1

Conversation

@evanwporter
Copy link
Contributor

@evanwporter evanwporter commented Mar 30, 2025

Easier than calling toml::get<std::vector<T>> then having to convert it to std::unordered_set

As part of the PR I added a couple of basic tests. They are mostly for demonstrating that this works.

@evanwporter evanwporter marked this pull request as draft March 30, 2025 16:33
@evanwporter evanwporter marked this pull request as ready for review March 30, 2025 17:12
@evanwporter
Copy link
Contributor Author

evanwporter commented Mar 30, 2025

@ToruNiina

I though about adding a is_set_like condition that copies is_array_like with the exception of the push_back (instead it requires insert) but I thought it might be too broad, since for example std::vector support insert but with different parameters.

Also it might be good to add a condition for std::set.

@ToruNiina ToruNiina merged commit 650e4c1 into ToruNiina:main Mar 31, 2025
278 checks passed
@ToruNiina
Copy link
Owner

std::unordered_map is a standard library container, so it is well-known enough to introduce a dedicated meta function. I have no complaint about this approach. The same applies to std::set. Adding std::set sounds good. But for now, I will merge this as it is.

Thank you!

github-actions bot pushed a commit that referenced this pull request Mar 31, 2025
add support for `toml::get<std::unordered_set>` 650e4c1
@evanwporter
Copy link
Contributor Author

@ToruNiina

Yes! std::unordered_set is just something I need in my implementation of toml11, but I'll create a PR for std::set when I have time

@evanwporter
Copy link
Contributor Author

@ToruNiina

I was thinking about it and it may be better to implement an is_set_like trait. This way we can cleanly include std::set and std::unordered_set. This will also support something like ankerl::unordered_dense::set.

The conditions for is_set_like can be as follows:

  • T has an iterator
  • T has a value_type
  • T supports insert(x)
  • T is not toml::value::array_type
  • T is not std::string
  • T is not std::string_view
  • T is not map-like
  • T does not have from_toml() member function
  • toml::from is not defined
  • A constructor from toml::basic_value is not defined
  • T has key_type

The distinguishing part here is that sets have the key_type.

Not urgent, just something to think about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants