Open mohitanand001 opened 6 years ago
Changes needed here: https://github.com/farziengineer/underscore_cpp/blob/master/underscore.cpp#L60 https://github.com/farziengineer/underscore_cpp/blob/master/underscore.cpp#L76 https://github.com/farziengineer/underscore_cpp/blob/master/underscore.cpp#L91 https://github.com/farziengineer/underscore_cpp/blob/master/underscore.cpp#L104 https://github.com/farziengineer/underscore_cpp/blob/master/underscore.cpp#L152 https://github.com/farziengineer/underscore_cpp/blob/master/underscore.cpp#L167 https://github.com/farziengineer/underscore_cpp/blob/master/underscore.cpp#L182
I dont think its possible.
Okay I'll look into it this weekend.
cool
I tried it for sometime (an hour or so), but failed. Now we have two options.
Hi! I looked into this for a little while and I think the code is (mostly) ok as far as "const-correctness" goes. I might be wrong, but since the Iterator
types are templated, the code should work with const
containers and const_iterator
s as well as their non-const
counterparts.
In some cases this might actually be desirable. For instance, you might want to modify an element found with find_if
. However, if the container or the iterators are already const
, the compiler will enforce that the predicate's operator()
does not receive a non-const
reference. In that regard, max
and min
actually restrict you significantly by only returning const_iterator
s.
There are some fringe cases though: functions that no not return an Iterator
(such as every
or any
) should usually be fine with const_iterators
. Also, ideally a Predicate
never modifies a reference passed to it (always takes const
refs or values). However, enforcing these concepts is nigh impossible in C++11 (or maybe even C++17, since the Concepts TS didn't make the cut).
Personally, I think the code is fine as-is in terms of "const-correctness", although the signatures are a bit inconsistent (max
takes a Collection
but find_if
takes 2 Iterator
s). I wouldn't worry too much about it, it sounds like a user issue more than a library issue.
@Gotham13121997 There are some functions , which take iterator as param. I think const_iterator would be better in cases where read only operations are needed. For pointers use https://stackoverflow.com/questions/5346890/what-is-the-difference-between-const-iterator-and-iterator