For example:
const std::vector<uint8_t> &BlaBla::toBuffer() const {
return data_;
}
If we use it to make BlaBla and get std::vector<uint8_t> from that and that all.
std::vector<uint8_t> vec = BlaBla().toBuffer(); // <= copy here
Will be better to use ref-qualifier to move data from sigle-used temp object:
const std::vector<uint8_t> &BlaBla::toBuffer() const & { // <= method for case of usual object
return data_;
}
std::vector<uint8_t> BlaBla::toBuffer() const && { // <= method for case of temp object
return std::move(data_);
}
std::vector<uint8_t> &BlaBla::asBuffer() { // <= method to access internal vector
return data_;
}
const std::vector<uint8_t> &BlaBla::asBuffer() const { // <= method to RO-access internal vector
return data_;
}