You can either use torch::gather or torch::index. torch::index is the implementation for Python indexing (e.g. x[tensor1, tensor2]).
Here’s how you can do it with gather:
  auto x = torch::randn({8, 6});
  int64_t idx_data[8] = { 0, 3, 4, 4, 4, 4, 4, 4 };
  auto idx = x.type().toScalarType(torch::kLong).tensorFromBlob(idx_data, 8);
  auto result = x.gather(1, idx.unsqueeze(1).expand_as(x));

Here’s how you can do it with torch::index:
  auto x = torch::randn({8, 6});
  int64_t idx_data[8] = { 0, 3, 4, 4, 4, 4, 4, 4 };
  auto idx = x.type().toScalarType(torch::kLong).tensorFromBlob(idx_data, 8);
  auto rows = torch::arange(0, x.size(0), torch::kLong);
  auto result = x.index({rows, idx});