From the doc : https://pytorch.org/cppdocs/api/classtorch_1_1data_1_1datasets_1_1_stateful_dataset.html#exhale-class-classtorch-1-1data-1-1datasets-1-1-stateful-dataset 4

Note that when subclassing a from StatefulDataset<Self, T>, the return type of get_batch(), which the subclass must override, will be optional (i.e. the type specified in the StatefulDataset specialization is automatically boxed into an optional for the dataset’s BatchType).

So you should define your dataset as
class YourDataset : public torch::data::datasets::StatefulDataset<YourDataset,std::vector<std::vector<int>>>

And in that case, get_batch will return c10::optional<std::vector<std::vector<int>>>
I took StatefulDataset as a base class because I don’t know what kind of dataset you need, but it should work the same for the other types.