-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
iterator_base::value_type should not be const #1326
Comments
Values are immutable when they have value semantics. The "values" returned by |
The issue with shallow vs deep constness on reference-like types is a common C++ behaviour, see e.g. pointers, both language and stdlib, or span. Returning const int F1();
auto foo = F1();
Realistically that is already what is going to happen in user code. The code that triggered this is something like this template <typename InputIterator,
typename InputSentinel,
typename ResultType = typename std::iterator_traits<InputIterator>::value_type>
std::vector<ResultType> from_range(InputIterator from, InputSentinel to) {
return std::vector<ResultType>(from, to);
}
template <typename Container>
auto from_range(Container const& cnt) {
using std::begin;
using std::end;
return from_range( begin( cnt ), end( cnt ) );
} which fails to compile with yaml-cpp as the container-like, because you cannot have |
@KitsuneRal You can use |
I cannot because I'm not developing yaml-cpp, I'm only using it and that's how I happen to know the pitfalls. If you look at the library code you will realise that it's much more complicated than "just" separating element types from value types. The Instead of returning a vector in |
I had an issue open against my own project, that boils down to yaml-cpp providing iterators, whose
value_type
isconst
. This should not happen, values are immutable by definition*, and it causes issues in consuming code that doesn't expect this.From a quick glance, I think it is fixable just by adding
std::remove_const_t
here.* this gets a bit muddy with reference-like types, but there it is generally expected that it is the reference that cannot be modified, not the referenced thing.
The text was updated successfully, but these errors were encountered: