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

Misc cleanups #6570

Merged
merged 5 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/enum_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ struct enum_base : public T
}
};

#define ENUM_AND_ARRAY(...) \
static constexpr std::size_t count = std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value; \
enum class type { __VA_ARGS__ }; \
static constexpr std::array<const char*, count> values{ __VA_ARGS__ };
#define ENUM_AND_ARRAY(...) \
enum class type { __VA_ARGS__ }; \
\
/** Provide a variable template for an array of matching size. */ \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a variable template. A variable template is like template<typename T> bool whatever = something<T>::value;. Please fix the comment.

Also, why remove count? You could leave the count declaration and just use it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right, I meant alias template. I removed count since I made values use the alias so I figured might as well subsume it.

template<typename T> \
using sized_array = std::array<T, std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value>; \
\
static constexpr sized_array<const char*> values{__VA_ARGS__};

} // namespace string_enums
2 changes: 1 addition & 1 deletion src/gui/dialogs/game_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ unit_const_ptr game_stats::get_leader(const int side)

static std::string controller_name(const team& t)
{
static const std::array<t_string, side_controller::size()> names {{_("controller^Idle"), _("controller^Human"), _("controller^AI"), _("controller^Reserved")}};
static const side_controller::sized_array<t_string> names {_("controller^Idle"), _("controller^Human"), _("controller^AI"), _("controller^Reserved")};
return "<span color='#808080'><small>" + names[static_cast<int>(t.controller())] + "</small></span>";
}

Expand Down
6 changes: 3 additions & 3 deletions src/gui/dialogs/multiplayer/mp_create_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ void mp_create_game::pre_show(window& win)
//
// Set up random faction mode menu_button
//
static const std::array<t_string, random_faction_mode::size()> names {{_("Independent"), _("No Mirror"), _("No Ally Mirror")}};
static const std::array<t_string, random_faction_mode::size()> tooltips {{
static const random_faction_mode::sized_array<t_string> names {_("Independent"), _("No Mirror"), _("No Ally Mirror")};
static const random_faction_mode::sized_array<t_string> tooltips {
_("Independent: Random factions assigned independently"),
_("No Mirror: No two players will get the same faction"),
_("No Ally Mirror: No two allied players will get the same faction")
}};
};
std::vector<config> rfm_options;
for(std::size_t i = 0; i < random_faction_mode::size(); i++) {
rfm_options.emplace_back("label", names[i]);
Expand Down
10 changes: 5 additions & 5 deletions src/units/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,8 @@ bool unit_type::resistance_filter_matches(

std::string unit_type::alignment_description(unit_alignments::type align, unit_race::GENDER gender)
{
static const std::array<t_string, unit_alignments::size()> male_names {{_("lawful"), _("neutral"), _("chaotic"), _("liminal")}};
static const std::array<t_string, unit_alignments::size()> female_names {{_("female^lawful"), _("female^neutral"), _("female^chaotic"), _("female^liminal")}};
static const unit_alignments::sized_array<t_string> male_names {_("lawful"), _("neutral"), _("chaotic"), _("liminal")};
static const unit_alignments::sized_array<t_string> female_names {_("female^lawful"), _("female^neutral"), _("female^chaotic"), _("female^liminal")};

if(gender == unit_race::FEMALE) {
return female_names[static_cast<int>(align)];
Expand Down Expand Up @@ -926,7 +926,7 @@ void patch_movetype(movetype& mt,

// These three need to follow movetype's fallback system, where values for
// movement costs are used for vision too.
const auto fallback_children = std::array<std::string, 3>{{"movement_costs", "vision_costs", "jamming_costs"}};
const std::array fallback_children {"movement_costs", "vision_costs", "jamming_costs"};
config cumulative_values;
for(const auto& x : fallback_children) {
if(mt_cfg.has_child(x)) {
Expand All @@ -943,7 +943,7 @@ void patch_movetype(movetype& mt,
}

// These don't need the fallback system
const auto child_names = std::array<std::string, 2>{{"defense", "resistance"}};
const std::array child_names {"defense", "resistance"};
for(const auto& x : child_names) {
if(mt_cfg.has_child(x)) {
const auto& subtag = mt_cfg.child(x);
Expand Down Expand Up @@ -1143,7 +1143,7 @@ void unit_type_data::set_config(const game_config_view& cfg)
std::string alias;
int default_val;
};
const std::array<ter_defs_to_movetype, 4> terrain_info_tags{
const std::array terrain_info_tags{
ter_defs_to_movetype{{"movement_costs"}, {"movement"}, movetype::UNREACHABLE},
ter_defs_to_movetype{{"vision_costs"}, {"vision"}, movetype::UNREACHABLE},
ter_defs_to_movetype{{"jamming_costs"}, {"jamming"}, movetype::UNREACHABLE},
Expand Down