Closed qqiangwu closed 8 months ago
That is an interesting question.
I think it would be possible to implement free functions like template<typename Container> auto gsl::front(Container container)
and template<typename Container> auto gsl::back(Container container)
that Ensure(!container.empty())
and then forward to container.front()
or container.back()
.
But from my understanding the GSL here only implements what the CppCoreGuidelines define/specify.
I understand. Maybe I should make a fork and add such functions, and use the fork in my organization.
GSL.util provides
at
to bound-check std containers. But how can I force bound-checkfront()
orback()
for std containers. Are there any good practice?I've written a clang-tidy checker to enforce bound-check
operator[]
operations, but I have no idea how to flagfront
orback
.