range-v3
range-v3 copied to clipboard
Error with MSVC when a 'size_type' is smaller then 'size_t'
If the size_type
of a container is smaller then size_t
, MSVC will report range/v3/view/zip_with.hpp(359): error C2397: conversion from 'size_t' to 'size_type' requires a narrowing conversion
on the following lines.
https://github.com/ericniebler/range-v3/blob/3a0881685803c659eba945788f9fe81acfe51c8a/include/range/v3/view/zip_with.hpp#L362-L363
I only know of this happening when a ranges::views::zip
is passed into another ranges function like ranges::views::transform
or ranges::to
. It does not happen used in a range-based for
loop.
This is a very problematic error when working with C++/WinRT, as it uses uint32_t
as size_type
for all of it's containers.
A workaround I have found is to add something to the ranges::views::zip
that uses the right size_type
, like ranges::views::iota(1)
.
Notes:
MSVC reports the error on line 359, but the problematic code isn't there. I don't know why MSVC does that.
Changing C++/WinRT to use
size_t
overuint32_t
is impossible, as C++/WinRT needs to match the Windows ABI.