Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
auto lmbd = [](auto i){...}; // Сейчас - нет, но в С++14 - даIn C++14 you just write «auto auto(auto auto) { auto; }». The compiler infers the rest from context.auto smth = new Heavy_class<Some_class<Foo_bar>,int>();
//....
delete smth; // error: smth is not pointer
auto foo(auto v1, auto v2) -> decltype(v1+v2) ;
int foo(auto v1, bool v2);
template<class V1, class V2>
auto foo(V1 v1, V2 v2) -> decltype(v1+v2) ;
template<class V1, class V2>
int foo(V1 v1, V2 v2);
Что, разумеется, приводит к неопределнности при вызове с любыми параметрами — по уже существующим правилам.
template<class V1, class V2>
auto foo(V1 v1, V2 v2) -> decltype(v1+v2);
template<class V1>
int foo(V1 v1, bool v2);
Крайне неинтуитивные конструкции.
class Foo {
static auto self() -> decltype(this);
};using self = Foo;#define DECLARE_SELF \
static auto selfTypeHelper() -> UnPtr<decltype(this)>; \
using Self = decltype(selfTypeHelper())class Foo {
DECLARE_SELF;
};...
offsetof(Self, field);
...
Секреты auto и decltype