How to create a similar tensor except shape in C++?

This is about creating a PyTorch tensor using C++.
I have an input tensor A. I want to create a new zero tensor B, which has the same properties as A except for a different shape (for example, A.shape=(3,) and B.shape=(3, 2)). Is there an elegant way to achieve this?
I know if A and B have the same shape, I can use B = torch::zeros_like(A), but now they have different shapes, what can I do?