Skip to content

Make a custom iterator type for OwnPtrVec #1

@dk949

Description

@dk949

Currently the iterator type for OwnPtrVec is just T**, this makes mutating algorithms unnecessarily dangerous, giving access directly to the stored pointer.

Alternative:

Return some sort of a proxy which is (move?) assignable/constructable from (but not to) std::unique_ptr. When assigned from unique_ptr de-allocates old object and releases the unique_ptr.

Something like this should be possible:

class AstNode;
ut::OwnVecPtr<AstNode> nodes;

std::transform(nodes.begin(), nodes.end(), nodes.begin(), [](auto node){
	if (foo)
		return node;
	else
		return std::make_unique<AstNode>(bar);
});

Possibly may require std::make_move_iterator?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions