Skip to content

Commit

Permalink
[MISC] Also check member types of both configs
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Feb 5, 2024
1 parent 3f190ab commit 7c2adeb
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions include/sharg/detail/poison_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,43 @@ struct poison_config_size_comp_validator : public detail::default_validator
* \tparam validator_t The validator to use. Defaults to sharg::detail::poison_config_size_comp_validator.
* \details
* * Sizes of sharg::config and sharg::detail::poison_config are the same.
* * sharg::config and sharg::detail::poison_config have the same member types (except validator).
* * sharg::detail::poison_config can be constructed with designated initializers from sharg::config's members.
* * sharg::config can be constructed with designated initializers from sharg::detail::poison_config's members.
* The latter two ensure that the order of the members is the same.
*/
template <typename validator_t = poison_config_size_comp_validator>
concept poison_config_valid = (sizeof(poison_config) == sizeof(config<validator_t>))
&& requires (config<validator_t> cfg, poison_config poison_cfg) {
{
poison_config{.short_id = cfg.short_id,
.long_id = cfg.long_id,
.description = cfg.description,
.default_message = cfg.default_message,
.advanced = cfg.advanced,
.hidden = cfg.hidden,
.required = cfg.required,
.validator = cfg.validator}
};
{
config<validator_t>{.short_id = poison_cfg.short_id,
.long_id = poison_cfg.long_id,
.description = poison_cfg.description,
.default_message = poison_cfg.default_message,
.advanced = poison_cfg.advanced,
.hidden = poison_cfg.hidden,
.required = poison_cfg.required,
.validator = std::any_cast<validator_t>(poison_cfg.validator)}
};
};
concept poison_config_valid =
(sizeof(poison_config) == sizeof(config<validator_t>))
&& std::same_as<decltype(poison_config{}.short_id), decltype(config<validator_t>{}.short_id)>
&& std::same_as<decltype(poison_config{}.long_id), decltype(config<validator_t>{}.long_id)>
&& std::same_as<decltype(poison_config{}.description), decltype(config<validator_t>{}.description)>
&& std::same_as<decltype(poison_config{}.default_message), decltype(config<validator_t>{}.default_message)>
&& std::same_as<decltype(poison_config{}.advanced), decltype(config<validator_t>{}.advanced)>
&& std::same_as<decltype(poison_config{}.hidden), decltype(config<validator_t>{}.hidden)>
&& std::same_as<decltype(poison_config{}.required), decltype(config<validator_t>{}.required)>
&& requires (config<validator_t> cfg, poison_config poison_cfg) {
{
poison_config{.short_id = cfg.short_id,
.long_id = cfg.long_id,
.description = cfg.description,
.default_message = cfg.default_message,
.advanced = cfg.advanced,
.hidden = cfg.hidden,
.required = cfg.required,
.validator = cfg.validator}
};
{
config<validator_t>{.short_id = poison_cfg.short_id,
.long_id = poison_cfg.long_id,
.description = poison_cfg.description,
.default_message = poison_cfg.default_message,
.advanced = poison_cfg.advanced,
.hidden = poison_cfg.hidden,
.required = poison_cfg.required,
.validator = std::any_cast<validator_t>(poison_cfg.validator)}
};
};

static_assert(poison_config_valid<>, "sharg::detail::poison_config must have the same members as sharg::config!");

Expand Down

0 comments on commit 7c2adeb

Please sign in to comment.