• Forum
  • Lounge
  • using std::swap; using std::begin; using

 
using std::swap; using std::begin; using std::end;

http://ericniebler.com/2014/10/21/customization-point-design-in-c11-and-beyond/

For a long time I had never been concerned about having to write using std::swap; before calling swap() - I knew why I had to do it and even though I knew it was a nuance, I didn't care too much because it was trivial extra typing.

Then I saw this commit:
https://github.com/mosra/magnum/commit/65a2e5677a53602395e27d8fa20584dd7c851fbc

From what I understand, if the article's proposed changes are implemented into C++, then that commit wouldn't even have to exist.

ADL is a really powerful feature of C++ and I feel like it is held back by nuances like this. Do you think it's important that this issue be tackled as soon as C++17? Or do you think it can be set on the back burners for a while?

Personally, with the direction C++ is going, I think we will only need it to be fixed more and more, so for me, sooner is better.
Bjarne is fighting the hard fight at making f(x, y) and x.f(y) do the same thing in C++17 (or the closest thing possible to being the same), similar to how member and non-member operators are treated.. Microsoft is pushing for something similar, but giving precedence to x.f(y) (so that intellisense can work).. so things might change quite a bit,
I've actually been thinking that myself, and was planning on making it a feature in my own language. It makes a lot of since and I would be very happy to see it come to C++.
I just realized, if std::swap becomes an object with a templated operator()(), then code that explicitly uses template parameters will break. But, is this even an issue? Why would you ever write code such as std::swap<..., ...>(..., ...) in the first place?
Why would you ever write code such as std::swap<..., ...>(..., ...) in the first place?
To use some questionable methods:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <algorithm>

struct foo
{ int i = 0; };

struct bar : foo
{ int j = 0; };

int main()
{
    bar x, y;
    y.i = 3; y.j = 4;
    std::cout << x.i << ' ' << x.j << '\n' << y.i << ' ' << y.j << "\n\n";
    std::swap<foo>(x, y);
    std::cout << x.i << ' ' << x.j << '\n' << y.i << ' ' << y.j;
}
0 0
3 4

3 0
0 4
Last edited on
my knowledge of UFI's stem from nim (http://nim-lang.org ), which doesnt have a this or a self, which is what allows them to work. how would UFI's work in c++ with a *this?
Sorry, what does UFI stand for?
uniform function interface. its the name for x.foo(y) == foo(x, y); i was referring to:
cubbi wrote:

Bjarne is fighting the hard fight at making f(x, y) and x.f(y) do the same thing in C++17 (or the closest thing possible to being the same), similar to how member and non-member operators are treated.. Microsoft is pushing for something similar, but giving precedence to x.f(y) (so that intellisense can work).. so things might change quite a bit,


edit:
oops... im sorry guys... i meant uniform function call syntax (UFC syntax) not UFI.http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394
Last edited on
Ah, I was more hoping to discuss customization points in this topic :)
fair enough. ill ask on IRC or perhaps in another thread
Topic archived. No new replies allowed.