diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-10-03 15:51:04 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-10-03 15:51:24 -0700 |
| commit | 3838d5880470fdc884f035ed3d1c67d3bdd1e16e (patch) | |
| tree | a12cdb0b99a4999649d93a7710d7a0a96fc1ffe9 /toolsrc/include | |
| parent | 85f0a060db8be34f4fce134be450bd1e4bd2b06f (diff) | |
| download | vcpkg-3838d5880470fdc884f035ed3d1c67d3bdd1e16e.tar.gz vcpkg-3838d5880470fdc884f035ed3d1c67d3bdd1e16e.zip | |
[vcpkg] Add more operator== to CStringView. Uppercase Span to follow naming convention.
Diffstat (limited to 'toolsrc/include')
| -rw-r--r-- | toolsrc/include/CStringView.h | 44 | ||||
| -rw-r--r-- | toolsrc/include/SourceParagraph.h | 2 | ||||
| -rw-r--r-- | toolsrc/include/Span.h | 28 |
3 files changed, 64 insertions, 10 deletions
diff --git a/toolsrc/include/CStringView.h b/toolsrc/include/CStringView.h index 282caad3a..c1810b4f1 100644 --- a/toolsrc/include/CStringView.h +++ b/toolsrc/include/CStringView.h @@ -11,13 +11,36 @@ namespace vcpkg constexpr BasicCStringView(const BasicCStringView&) = default; BasicCStringView(const std::basic_string<CharType>& str) : cstr(str.c_str()) {} - constexpr operator const CharType*() const { return cstr; } constexpr const CharType* c_str() const { return cstr; } private: const CharType* cstr; }; + namespace details + { + inline bool vcpkg_strcmp(const char* l, const char* r) { return strcmp(l, r) == 0; } + inline bool vcpkg_strcmp(const wchar_t* l, const wchar_t* r) { return wcscmp(l, r) == 0; } + } + + template<class CharType> + bool operator==(const BasicCStringView<CharType>& l, const BasicCStringView<CharType>& r) + { + return details::vcpkg_strcmp(l.c_str(), r.c_str()); + } + + template<class CharType> + bool operator==(const CharType* l, const BasicCStringView<CharType>& r) + { + return details::vcpkg_strcmp(l, r.c_str()); + } + + template<class CharType> + bool operator==(const BasicCStringView<CharType>& r, const CharType* l) + { + return details::vcpkg_strcmp(l, r.c_str()); + } + template<class CharType> bool operator==(const std::basic_string<CharType>& l, const BasicCStringView<CharType>& r) { @@ -30,6 +53,25 @@ namespace vcpkg return l == r.c_str(); } + // notequals + template<class CharType> + bool operator!=(const BasicCStringView<CharType>& l, const BasicCStringView<CharType>& r) + { + return !details::vcpkg_strcmp(l.c_str(), r.c_str()); + } + + template<class CharType> + bool operator!=(const CharType* l, const BasicCStringView<CharType>& r) + { + return !details::vcpkg_strcmp(l, r.c_str()); + } + + template<class CharType> + bool operator!=(const BasicCStringView<CharType>& r, const CharType* l) + { + return !details::vcpkg_strcmp(l, r.c_str()); + } + template<class CharType> bool operator!=(const BasicCStringView<CharType>& r, const std::basic_string<CharType>& l) { diff --git a/toolsrc/include/SourceParagraph.h b/toolsrc/include/SourceParagraph.h index 1357b3769..ccf9faf4f 100644 --- a/toolsrc/include/SourceParagraph.h +++ b/toolsrc/include/SourceParagraph.h @@ -57,7 +57,7 @@ namespace vcpkg std::vector<std::unique_ptr<FeatureParagraph>> feature_paragraphs; }; - void print_error_message(span<const std::unique_ptr<Parse::ParseControlErrorInfo>> error_info_list); + void print_error_message(Span<const std::unique_ptr<Parse::ParseControlErrorInfo>> error_info_list); inline void print_error_message(const std::unique_ptr<Parse::ParseControlErrorInfo>& error_info_list) { return print_error_message({&error_info_list, 1}); diff --git a/toolsrc/include/Span.h b/toolsrc/include/Span.h index b16af2cef..b2c9acdbc 100644 --- a/toolsrc/include/Span.h +++ b/toolsrc/include/Span.h @@ -5,7 +5,7 @@ #include <vector>
template<class T>
-struct span
+struct Span
{
public:
using element_type = T;
@@ -13,18 +13,18 @@ public: using reference = T&;
using iterator = T*;
- constexpr span() noexcept : m_ptr(nullptr), m_count(0) {}
- constexpr span(std::nullptr_t) noexcept : span() {}
- constexpr span(T* ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {}
- constexpr span(T* ptr_begin, T* ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {}
+ constexpr Span() noexcept : m_ptr(nullptr), m_count(0) {}
+ constexpr Span(std::nullptr_t) noexcept : Span() {}
+ constexpr Span(T* ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {}
+ constexpr Span(T* ptr_begin, T* ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {}
template<size_t N>
- constexpr span(T (&arr)[N]) noexcept : span(arr, N)
+ constexpr Span(T (&arr)[N]) noexcept : Span(arr, N)
{
}
- span(std::vector<T>& v) noexcept : span(v.data(), v.size()) {}
- span(const std::vector<std::remove_const_t<T>>& v) noexcept : span(v.data(), v.size()) {}
+ Span(std::vector<T>& v) noexcept : Span(v.data(), v.size()) {}
+ Span(const std::vector<std::remove_const_t<T>>& v) noexcept : Span(v.data(), v.size()) {}
constexpr iterator begin() const { return m_ptr; }
constexpr iterator end() const { return m_ptr + m_count; }
@@ -36,3 +36,15 @@ private: pointer m_ptr;
size_t m_count;
};
+
+template<class T>
+Span<T> make_span(std::vector<T>& v)
+{
+ return {v.data(), v.size()};
+}
+
+template<class T>
+Span<const T> make_span(const std::vector<T>& v)
+{
+ return {v.data(), v.size()};
+}
|
