Skip to content

Commit

Permalink
[vcpkg] Remove use of std::variant and std::visit to fix VS2015. (mic…
Browse files Browse the repository at this point in the history
…rosoft#12242)

Fixes microsoft#12220

Co-authored-by: Robert Schumacher <[email protected]>
  • Loading branch information
ras0219 and ras0219-msft authored Jul 6, 2020
1 parent ae27ca1 commit d50eb9c
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 180 deletions.
15 changes: 1 addition & 14 deletions 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 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

0 comments on commit d50eb9c

Please sign in to comment.