Use std::array where array size is needed, when appropriate

This commit is contained in:
Charles Dang 2017-04-21 03:41:18 +11:00
parent 323516d3d8
commit ac9ad01be8
3 changed files with 8 additions and 9 deletions

View file

@ -941,8 +941,8 @@ gui::button::TYPE display::string_to_button_type(std::string type)
static const std::string& get_direction(size_t n)
{
static const std::string dirs[6] = { "-n", "-ne", "-se", "-s", "-sw", "-nw" };
return dirs[n >= sizeof(dirs)/sizeof(*dirs) ? 0 : n];
static const std::array<std::string, 6> dirs { "-n", "-ne", "-se", "-s", "-sw", "-nw" };
return dirs[n >= dirs.size() ? 0 : n];
}
std::vector<surface> display::get_fog_shroud_images(const map_location& loc, image::TYPE image_type)
@ -1203,7 +1203,7 @@ void display::drawing_buffer_add(const drawing_layer layer,
// public into the definition of drawing_layer
//
// The drawing is done per layer_group, the range per group is [low, high).
const display::drawing_layer display::drawing_buffer_key::layer_groups[] {
const std::array<display::drawing_layer, 5> display::drawing_buffer_key::layer_groups {
LAYER_TERRAIN_BG,
LAYER_UNIT_FIRST,
LAYER_UNIT_MOVE_DEFAULT,
@ -1213,7 +1213,7 @@ const display::drawing_layer display::drawing_buffer_key::layer_groups[] {
};
// no need to change this if layer_groups above is changed
const unsigned int display::drawing_buffer_key::max_layer_group = sizeof(display::drawing_buffer_key::layer_groups) / sizeof(display::drawing_layer) - 2;
const unsigned int display::drawing_buffer_key::max_layer_group = layer_groups.size() / sizeof(display::drawing_layer) - 2;
enum {
// you may adjust the following when needed:

View file

@ -907,7 +907,7 @@ protected:
private:
unsigned int key_;
static const drawing_layer layer_groups[];
static const std::array<drawing_layer, 5> layer_groups;
static const unsigned int max_layer_group;
public:

View file

@ -80,8 +80,7 @@ static lg::log_domain log_unit("unit");
namespace
{
// "advance" only kept around for backwards compatibility; only "advancement" should be used
const std::string ModificationTypes[] { "advancement", "advance", "trait", "object" };
const size_t NumModificationTypes = sizeof(ModificationTypes)/ sizeof(*ModificationTypes);
const std::array<std::string, 4> ModificationTypes { "advancement", "advance", "trait", "object" };
/**
* Pointers to units which have data in their internal caches. The
@ -1186,7 +1185,7 @@ void unit::expire_modifications(const std::string& duration)
const unit_type* rebuild_from = nullptr;
// Loop through all types of modifications.
for(unsigned int i = 0; i != NumModificationTypes; ++i) {
for(unsigned int i = 0; i != ModificationTypes.size(); ++i) {
const std::string& mod_name = ModificationTypes[i];
// Loop through all modifications of this type.
// Looping in reverse since we may delete the current modification.
@ -2303,7 +2302,7 @@ void unit::apply_modifications()
{
log_scope("apply mods");
for(size_t i = 0; i != NumModificationTypes; ++i) {
for(size_t i = 0; i != ModificationTypes.size(); ++i) {
const std::string& mod = ModificationTypes[i];
if(mod == "advance" && modifications_.has_child(mod)) {
lg::wml_error() << "[modifications][advance] is deprecated, use [advancement] instead" << std::endl;