auto foo = []() {
std::vector<int> v(10);
// Do some work on 'v'
return v[0];
};
auto foo = []() {
std::vector<bool> v(10);
// Do some work on 'v'
return v[0];
};
I choose "std::vector<bool>" because it's the only type in the standard that I know suffers from this issue
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
People talk of this as "overloading operator auto". There's been lots of talk, but nothing has made it into the language yet.
On 6 April 2018 at 14:23, Tony V E <tvan...@gmail.com> wrote:People talk of this as "overloading operator auto". There's been lots of talk, but nothing has made it into the language yet.I wish we had a better name for this; operator auto already means something else.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Consider the following code:
auto foo = []() {
std::vector<int> v(10);
// Do some work on 'v'
return v[0];
};
The return type of "foo()" is "int", despite the fact that "v[0]" is an expression of type "int&"
#include <vector>
#include <iostream>
int main(int argc, char* argv[]) {
std::vector<int> v;
using T = decltype(v[0]);
std::cout << std::is_same<T,int>::value << std::endl; // 0
std::cout << std::is_same<T,int&>::value << std::endl; // 1
std::cout << std::is_same<T,int&&>::value << std::endl; // 0
std::cout << std::is_same<T,const int&>::value << std::endl; // 0
std::cout << std::is_same<T,const int>::value << std::endl; // 0
return 0;
}
On Saturday, April 7, 2018 at 12:39:16 PM UTC+2, Language Lawyer wrote:пятница, 6 апреля 2018 г., 22:08:40 UTC+3 пользователь schreiber...@gmail.com написал:Consider the following code:
auto foo = []() {
std::vector<int> v(10);
// Do some work on 'v'
return v[0];
};
The return type of "foo()" is "int", despite the fact that "v[0]" is an expression of type "int&"
"v[0]" is an expression of type "int".I'm sorry, but no. "v[0]" returns a "std::vector<T>::reference", which is a "T&".
#include <vector>
#include <iostream>
int main(int argc, char* argv[]) {
std::vector<int> v;
using T = decltype(v[0]);
std::cout << std::is_same<T,int>::value << std::endl; // 0
std::cout << std::is_same<T,int&>::value << std::endl; // 1
std::cout << std::is_same<T,int&&>::value << std::endl; // 0
std::cout << std::is_same<T,const int&>::value << std::endl; // 0
std::cout << std::is_same<T,const int>::value << std::endl; // 0
return 0;
}
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
On Sat, Apr 7, 2018 at 1:52 PM, <schreiber...@gmail.com> wrote:On Saturday, April 7, 2018 at 12:39:16 PM UTC+2, Language Lawyer wrote:пятница, 6 апреля 2018 г., 22:08:40 UTC+3 пользователь schreiber...@gmail.com написал:Consider the following code:
auto foo = []() {
std::vector<int> v(10);
// Do some work on 'v'
return v[0];
};
The return type of "foo()" is "int", despite the fact that "v[0]" is an expression of type "int&"
"v[0]" is an expression of type "int".I'm sorry, but no. "v[0]" returns a "std::vector<T>::reference", which is a "T&".Language Lawyer probably refers to the fact that expressions of type reference to T are adjusted to just T immediately, see [expr.type]p1.
I could not find [expr.type] in the C++17 working draft, I assume you meant [expr] point 5. Looks like bikeshedding on the exact meaning of "the type of an expression", which may be very relevant for a language lawyer, but pretty much irrelevant to me and this discussion.
On Sat, Apr 7, 2018 at 6:52 PM, <schreiber...@gmail.com> wrote:Yes that's the one, I'm on the standard draft from http://eel.is/c++draft/, which has already been updated lots of times since C++17 was finished :). I completely agree that this is irrelevant to your discussion though.I could not find [expr.type] in the C++17 working draft, I assume you meant [expr] point 5. Looks like bikeshedding on the exact meaning of "the type of an expression", which may be very relevant for a language lawyer, but pretty much irrelevant to me and this discussion.
Here's the timeline of p0352 in case you're interested. You might want to contact the authors, because I think they abandoned it:- Oulu, Finland (2016): Postponed- Issaquah, WA (2016): Reviewed with clear majority strongly in favor to encourage work in that direction; to be reviewed again in Kona- Kona, HI (2017): Postponed- never seen again...