view: return unsigned types for size
This commit is contained in:
parent
2840810f64
commit
ad02c94511
@ -360,7 +360,7 @@ namespace util::format {
|
||||
if (spec.precision >= 0) {
|
||||
std::copy_n (
|
||||
std::begin (val),
|
||||
util::min (spec.precision, val.size ()),
|
||||
util::min (spec.precision, static_cast<int> (val.size ())),
|
||||
std::ostream_iterator<char> (os)
|
||||
);
|
||||
return os;
|
||||
|
@ -11,7 +11,7 @@ main (int, char**)
|
||||
util::TAP::logger tap;
|
||||
|
||||
tap.expect_eq (
|
||||
std::size (util::make_view ("foo")), 3,
|
||||
std::size (util::make_view ("foo")), 3u,
|
||||
"character array view does not include trailing null"
|
||||
);
|
||||
|
||||
|
11
view.hpp
11
view.hpp
@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright 2015-2017 Danny Robson <danny@nerdcruft.net>
|
||||
* Copyright 2015-2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
|
||||
@ -228,10 +228,17 @@ namespace util {
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// the return type of size _should_ be whatever std::distance returns,
|
||||
// or something else that makes sense for the iterators we've been
|
||||
// handed.
|
||||
//
|
||||
// but it's a pain in the arse to use sizes that aren't unsigned given
|
||||
// that other libraries need to compare sizes pretty often and
|
||||
// everything else in the world tends to be unsigned.
|
||||
constexpr auto
|
||||
size (void) const noexcept
|
||||
{
|
||||
return std::distance (m_begin, m_end);
|
||||
return static_cast<std::size_t> (std::distance (m_begin, m_end));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user