Skip to content

Reconsider Raw pattern #7479

@fricklerhandwerk

Description

@fricklerhandwerk

We discussed in Nix team meeting on 2022-12-19, that there are multiple instances in the code which follow this pattern:

typedef std::variant<AllOutputs, OutputNames> _OutputsSpecRaw;

struct OutputsSpec : _OutputsSpecRaw {
    using Raw = _OutputsSpecRaw;
    using Raw::Raw;

    using Names = OutputNames;
    using All = AllOutputs;

    inline const Raw & raw() const {
        return static_cast<const Raw &>(*this);
    }

    inline Raw & raw() {
        return static_cast<Raw &>(*this);
    }

@edolstra asks whether we should do it that way, because it's quite verbose. Also adding aliases like in this case keeps both names around in the codebase.

@Ericson2314 do we have alternatives that are as convenient to use at the call site? Does there speak anything against having the variants as fields?

Metadata

Metadata

Assignees

Labels

contributor-experienceDeveloper experience for Nix contributorsidea approvedThe given proposal has been discussed and approved by the Nix team. An implementation is welcome.
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions