Skip to content

Remove use of const_cast with Options #443

@cmacmackin

Description

@cmacmackin

const_cast gets used on const refs to Options (and GuardedOptions) objects in the following functions:

  • T get(const Options&, const std::string&)
  • T getNoBoundary(const Options&, const std::string&)
  • bool isSetFinal(const Options&, const std::string&)
  • bool isSetFinal(const GuardedOptions&, const std::string&)
  • bool isSetFinalNoBoundary(const Options&, const std::string&)
  • bool isSetFinalNoBoundary(const GuardedOptions&, const std::string&)

Even though the (Guarded)Options arguments are are logically const, the functions are modifying the attributes to mark that they have been read. This requires the const_cast.

I really don't like this. It doesn't look like isSetFinal is called in any context with a const& anyway? I know this is already an issue with the existing function, but can we avoid the const_cast here?

Originally posted by @ZedThree in #421 (comment)

The introduction of access controls (#421) and automatic ordering of components (#428) might make this real-time checking redundant in future, in which case we'd be able to remove these attribute writes, but it will be best to battle-test these new features before removing anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions