From b5e635a16e23780a5ccb6a0880c37dbd03e14bfc Mon Sep 17 00:00:00 2001 From: Neargye Date: Fri, 31 Aug 2018 18:42:59 +0500 Subject: [PATCH] add cstring::at --- include/nameof.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/nameof.hpp b/include/nameof.hpp index e3faa85..c1505b1 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -147,6 +147,11 @@ class cstring final { constexpr const char& operator[](std::size_t i) const { return str_[i]; } + constexpr const char& at(std::size_t i) const { + return (i < size_) ? str_[i] + : (throw std::out_of_range("cstring::at"), str_[0]); + } + constexpr const char& front() const { return str_[0]; } constexpr const char& back() const { return str_[size_ - 1]; }