Repository: FreeCAD/FreeCAD
File: src/App/Property.cpp (C++)

Code before:
    if (postfix) {
        ss << postfix;
    }
    return ss.str();
}

// clang-format off
static constexpr auto numProp {6};
static constexpr std::array<std::tuple<Property::Status, PropertyType>, numProp> mapProps {{
    {App::Property::PropReadOnly,    Prop_ReadOnly},
    {App::Property::PropHidden,      Prop_Hidden},
    {App::Property::PropOutput,      Prop_Output},
    {App::Property::PropTransient,   Prop_Transient},
    {App::Property::PropNoRecompute, Prop_NoRecompute},
    {App::Property::PropNoPersist,   Prop_NoPersist}
}};
// clang-format on

short Property::getType() const
{
    short type = 0;
    std::for_each(mapProps.begin(), mapProps.end(), [&type, this](const auto& item) {
        if (testStatus(std::get<0>(item))) {
            type |= std::get<1>(item);
        }
    });
    return type;
}

void Property::syncType(unsigned type)
{
    std::for_each(mapProps.begin(), mapProps.end(), [type, this](const auto& item) {
        if (type & std::get<1>(item)) {
            StatusBits.set((size_t)std::get<0>(item));
        }
    });
}

const char* Property::getGroup() const
{
    return father->getPropertyGroup(this);
}

const char* Property::getDocumentation() const
{
    return father->getPropertyDocumentation(this);
}

void Property::setContainer(PropertyContainer* father)
{
    this->father = father;

Review comment (suggestion):
Is there any benefit of using for_each here instead of simply range-based for loop? With the for loop you could use structured bindings to make the code more readable and give the properties meaningful names instead of relying on indices:

Same thing applies to other for_each uses.

```suggestion
    for (const auto& [propertyStatus, propertyType] : mapProps) {
        if (testStatus(propertyStatus)) {
            type |= propertyType;
        }
    }
```

Code after:
    if (postfix) {
        ss << postfix;
    }
    return ss.str();
}

// clang-format off
static constexpr auto mapProps = std::to_array<std::tuple<Property::Status, PropertyType>>({
    {App::Property::PropReadOnly,    Prop_ReadOnly},
    {App::Property::PropHidden,      Prop_Hidden},
    {App::Property::PropOutput,      Prop_Output},
    {App::Property::PropTransient,   Prop_Transient},
    {App::Property::PropNoRecompute, Prop_NoRecompute},
    {App::Property::PropNoPersist,   Prop_NoPersist}
});
// clang-format on

short Property::getType() const
{
    short type = 0;
    for (const auto& [propertyStatus, propertyType] : mapProps) {
        if (testStatus(propertyStatus)) {
            type |= propertyType;
        }
    }
    return type;
}

void Property::syncType(unsigned type)
{
    for (const auto& [propertyStatus, propertyType] : mapProps) {
        if (type & propertyType) {
            StatusBits.set((size_t)propertyStatus);
        }
    }
}

const char* Property::getGroup() const
{
    return father->getPropertyGroup(this);
}

const char* Property::getDocumentation() const
{
    return father->getPropertyDocumentation(this);
}

void Property::setContainer(PropertyContainer* father)
{
    this->father = father;
}