I'm trying to use auto for all local variables inside my functions.
Take the following code:
class obj
{
public:
obj() {};
obj( obj&& o ) = delete;
};
int main()
{
obj test0;
auto test1 = obj();
return 0;
}
$ g++ --std=c++1z main.cpp
main.cpp: In function ‘int main()’:
main.cpp:13:20: error: use of deleted function ‘obj::obj(obj&&)’
auto test1 = obj();
This is OK in C++17; guaranteed copy elision adjusts the rules so that a move constructor isn't even conceptually called, so it doesn't matter if it's deleted or inaccessible.
Before then, if you love auto
so much, you can do
auto&& test1 = obj();