Skip to content

Mark Timezone member functions as const if they don't modify member data#188

Open
Abrynos wants to merge 1 commit into
ropg:masterfrom
Abrynos:const
Open

Mark Timezone member functions as const if they don't modify member data#188
Abrynos wants to merge 1 commit into
ropg:masterfrom
Abrynos:const

Conversation

@Abrynos

@Abrynos Abrynos commented Jun 10, 2026

Copy link
Copy Markdown

Member functions that do not modify any member data can be marked as const.

Example usage:

namespace whatever {
    static Timezone tz;

    const Timezone * get_time() {
        if (!ezt::waitForSync(1)) {
            return nullptr;
        }

        tz.setLocation("Europe/Vienna");
        &tz;
    }
}

void other_code() {
    const Timezone * tz = whatever::get_time();
    if (tz == nullptr) {
        return;
    }

    // previously not possible because the local variable "tz" is marked const but the method dateTime() is not
    Serial.printLn(tz->dateTime());
}

@Abrynos

Abrynos commented Jun 11, 2026

Copy link
Copy Markdown
Author

@ropg Any thoughts on this?

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.

1 participant