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

Add a static_cast in args_t::size to silence a conversion warning #966

Merged
merged 2 commits into from
Feb 6, 2024
Merged
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
28 changes: 14 additions & 14 deletions include/cpp2util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,19 @@ class finally_presuccess
};


//-----------------------------------------------------------------------
//
// An implementation of GSL's narrow_cast with a clearly 'unsafe' name
//
//-----------------------------------------------------------------------
//
template <typename C, typename X>
constexpr auto unsafe_narrow( X&& x ) noexcept -> decltype(auto)
{
return static_cast<C>(CPP2_FORWARD(x));
}


//-----------------------------------------------------------------------
//
// args: see main() arguments as a container of string_views
Expand Down Expand Up @@ -1771,7 +1784,7 @@ struct args_t
auto end() const -> iterator { return iterator{ argc, argv, argc }; }
auto cbegin() const -> iterator { return begin(); }
auto cend() const -> iterator { return end(); }
auto size() const -> std::size_t { return argc; }
auto size() const -> std::size_t { return cpp2::unsafe_narrow<std::size_t>(argc); }
auto ssize() const -> int { return argc; }

auto operator[](int i) const {
Expand Down Expand Up @@ -1800,19 +1813,6 @@ template<typename T>
using alien_memory = T volatile;


//-----------------------------------------------------------------------
//
// An implementation of GSL's narrow_cast with a clearly 'unsafe' name
//
//-----------------------------------------------------------------------
//
template <typename C, typename X>
constexpr auto unsafe_narrow( X&& x ) noexcept -> decltype(auto)
{
return static_cast<C>(CPP2_FORWARD(x));
}


//-----------------------------------------------------------------------
//
// has_flags: query whether a flag_enum value has all flags in 'flags' set
Expand Down
Loading