Is there a way to modify attribute of an “Object”?

I would like to modify the attribute of an Object. For example, I would like to specify the args attribute of CallPattern latter:

CallPattern the_pattern{IsOp("cast"), {}};
the_pattern->args.push_back(IsWildcard());

But this is not allowed since (I think) args is eventually reached via a const ptr.

So is there a way to modify attribute of an “Object”? This requirement may be essential when we define a graph with cycle. (computation graph can not have cycle, but a powerful pattern matching graph should have!)

Oh I know. I can use make_object for such cases. I am awesome.

1 Like

Object cannot be modified once created, make_object creates a raw ObjectPtr object that can be modified. Another way to “modify” some members in an Object is via CopyOnWrite, which actually mutates the attributes in a duplicate of the original Object.

Thank you for providing such useful information.