// Copyright 2018 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
// constexpr version of http://en.cppreference.com/w/cpp/string/char_traits. // This currently just implements the bits needed to support a (mostly) // constexpr StringPiece. // // TODO(dcheng): Once we switch to C++17, most methods will become constexpr and // we can switch over to using the one in the standard library. template <typename T> struct CharTraits { // Performs a lexographical comparison of the first N characters of |s1| and // |s2|. Returns 0 if equal, -1 if |s1| is less than |s2|, and 1 if |s1| is // greater than |s2|. static constexpr int compare(const T* s1, const T* s2, size_t n) noexcept;
// Returns the length of |s|, assuming null termination (and not including the // terminating null). static constexpr size_t length(const T* s) noexcept;
};
template <typename T>
constexpr int CharTraits<T>::compare(const T* s1, const T* s2,
size_t n) noexcept { for (; n; --n, ++s1, ++s2) { if (*s1 < *s2) return -1; if (*s1 > *s2) return 1;
} return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.