Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vcpkg] Remove use of std::variant and std::visit to fix VS2015. #12242

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions toolsrc/include/vcpkg/base/stringview.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,7 @@ namespace vcpkg
std::string to_string() const;
void to_string(std::string& out) const;

constexpr StringView substr(size_t pos, size_t count = std::numeric_limits<size_t>::max()) const
{
if (pos > m_size)
{
return StringView();
}

if (count > m_size - pos)
{
return StringView(m_ptr + pos, m_size - pos);
}

return StringView(m_ptr + pos, count);
}
StringView substr(size_t pos, size_t count = std::numeric_limits<size_t>::max()) const;

constexpr char byte_at_index(size_t pos) const { return m_ptr[pos]; }

Expand Down
17 changes: 16 additions & 1 deletion toolsrc/src/vcpkg/base/stringview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,26 @@ namespace vcpkg
return result.front();
}

StringView::StringView(const std::string& s) : m_ptr(s.data()), m_size(s.size()) { }
StringView::StringView(const std::string& s) : m_ptr(s.data()), m_size(s.size()) {}

std::string StringView::to_string() const { return std::string(m_ptr, m_size); }
void StringView::to_string(std::string& s) const { s.append(m_ptr, m_size); }

StringView StringView::substr(size_t pos, size_t count) const
{
if (pos > m_size)
{
return StringView();
}

if (count > m_size - pos)
{
return StringView(m_ptr + pos, m_size - pos);
}

return StringView(m_ptr + pos, count);
}

bool operator==(StringView lhs, StringView rhs) noexcept
{
return lhs.size() == rhs.size() && memcmp(lhs.data(), rhs.data(), lhs.size()) == 0;
Expand Down
Loading