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

reserve_helper type conversion warning #44

Closed
hmoffatt opened this issue Feb 7, 2023 · 2 comments
Closed

reserve_helper type conversion warning #44

hmoffatt opened this issue Feb 7, 2023 · 2 comments

Comments

@hmoffatt
Copy link

hmoffatt commented Feb 7, 2023

I'm using kdalgorithms with Qt 5.15.12.

The following code generates warnings in Visual Studio about the type of size in reverse_helper.h:

	QVector<int> a{ 1,2,3 };
	auto b = kdalgorithms::filtered(a,
		[](const auto& i) { return i % 2; });
1>...\kdalgorithms\bits\reserve_helper.h(27,5): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>...kdalgorithms\bits\reserve_helper.h(36,5): message : see reference to function template instantiation 'bool kdalgorithms::detail::reserve_helper<Container>(Container &,size_t,std::true_type)' being compiled
1>        with
1>        [
1>            Container=QVector<int>
1>        ]
@jesperkdab
Copy link
Collaborator

Qt5's QVector::reserve takes an int (See https://doc.qt.io/qt-5/qvector.html#reserve), while std's containers and Qt6 for that matter too takes a size_t (https://doc.qt.io/qt-6/qlist.html#reserve).
Not sure what to do about it, besides maybe adding the size type to the template parameter:

template <typename Container, typename Size>
bool reserve_helper(Container &container, Size size, std::true_type)
{
container.reserve(size);
return true;
}

Not sure what can of worms that would open though.

@hmoffatt
Copy link
Author

hmoffatt commented Feb 8, 2023

Can you use Container::size_type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants