diff --git a/src/TiledArray/util/index.h b/src/TiledArray/util/index.h index e86560d970..53d8ccb1c1 100644 --- a/src/TiledArray/util/index.h +++ b/src/TiledArray/util/index.h @@ -22,7 +22,7 @@ std::string join(const small_vector &v); template using enable_if_string = std::enable_if_t< std::is_same_v, U>; -/// an n-index, with n a runtime parameter +/// an `n`-index, with `n` a runtime parameter template class Index { public: @@ -36,10 +36,10 @@ class Index { Index(const S &s) : data_(s.begin(), s.end()) {} template - Index(const std::string &s) : Index(index::tokenize(s)) {} + explicit Index(const std::string &s) : Index(index::tokenize(s)) {} template - Index(const char *s) : Index(std::string(s)) {} + explicit Index(const char *s) : Index(std::string(s)) {} template operator std::string() const { return index::join(data_); } @@ -65,11 +65,14 @@ class Index { const auto& operator[](size_t idx) const { return data_.at(idx); } + /// @param[in] v element to seek + /// @pre `this->contains(v)` + /// @return the location of @p v in `*this` size_t indexof(const T& v) const { for (size_t i = 0; i < this->size(); ++i) { - if (this[i] == v) return i; + if ((*this)[i] == v) return i; } - return -1; + TA_ASSERT(false); } /// Returns true if argument exists in the Index object, else returns false