-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed #48 (using nonmember begin/end)
- Loading branch information
Showing
2 changed files
with
7 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abc6137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will just call the
begin
andend
functions in thestd
namespace, but won't use those in the namespace of the corresponding type. For enabling ADL to kick in, the right way to do it is:C++ sucks :D
abc6137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment. But isn't
std::begin(foo)
just a function that returnsfoo.begin()
for any type offoo
?abc6137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In standarese
std::swap
,std::begin
,std::end
,std::iter_swap
, ... are customization points. They are defined in thestd
namespace and overloaded for some standard types, but when used as:argument dependent look-up is going to try and find a swap function declared in the namespace where the types of
a
andb
are defined. Iff it doesn't find any, is going to try anyswap
function in scope (e.g.std::swap
which is brought into scope by theusing
directive).That is:
doesn't do the same thing as
using std::swap
+ unqualified call toswap
.std::begin
is a free function, that can be overloaded for other types. It is, in particular, overloaded for C-Arrays, which don't have member functions. Since you don't have to modify the type to implement non-member non-friendbegin
for a type, it allows you to adapt e.g. third-party code (that you cannot modify) such that it can e.g. be used with the range-for statement.abc6137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I just do not know any user-defined types with iterators where
std::begin
would not do the job. But I understand your explanation and trust you that there is demand :-)I'll update the code in a minute.
abc6137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use this on e.g. Eigen3 vectors and matrices which do not provide
begin
andend
.