I'm not sure what's the dilemma here.
Why can't you just simply throw an exception when the give index was not found?
SharedBox& Truckload::operator[](size_t index) const
{
size_t count{}; // Package count
for (Package* package{ m_head }; package; package = package->m_next)
{
if (count++ == index) // Up to index yet?
return package->m_box; // If so return the pointer to Box
}
throw std::out_of_range("Array index incorrect.");
}
Something else: what's the purpose of inlining the nullBox?