Size: a a a

2020 August 07

AZ

Alex Zhukovsky in rust_offtopic
polunin.ai
А зачем если можно в плюсах сделать auto?
ну примерно так же где и в идрисе:

foo : (x : a) -> (typeOf x) -> Something
источник

AZ

Alex Zhukovsky in rust_offtopic
polunin.ai
Ну конкретно в этом случае
конкретно в этом не нужно, это пример был
источник

BD

Berkus Decker in rust_offtopic
polunin.ai
А зачем если можно в плюсах сделать auto?
If the argument is an unparenthesized id-expression or an unparenthesized class member access expression, then decltype yields the type of the entity named by this expression. If there is no such entity, or if the argument names a set of overloaded functions, the program is ill-formed.
If the argument is an unparenthesized id-expression naming a non-type template parameter, then decltype yields the type of the template parameter (after performing any necessary type deduction if the template parameter is declared with a placeholder type).
(since C++20)
2) If the argument is any other expression of type T, and
a) if the value category of expression is xvalue, then decltype yields T&&;
b) if the value category of expression is lvalue, then decltype yields T&;
c) if the value category of expression is prvalue, then decltype yields T.
If expression is a prvalue other than a (possibly parenthesized) immediate invocation (since C++20), a temporary object is not materialized from that prvalue: such prvalue has no result object.
(since C++17)
The type need not be complete or have an available destructor, and can be abstract. This rule doesn't apply to sub-expressions: in decltype(f(g())), g() must have a complete type, but f() need not.
Note that if the name of an object is parenthesized, it is treated as an ordinary lvalue expression, thus decltype(x) and decltype((x)) are often different types.


изич, понял теперь, зачем decltype?
источник

BD

Berkus Decker in rust_offtopic
а вот перевод
источник

BD

Berkus Decker in rust_offtopic
decltype is useful when declaring types that are difficult or impossible to declare using standard notation, like lambda-related types or types that depend on template parameters.
источник

BD

Berkus Decker in rust_offtopic
auto f = [](int a, int b) -> int
   {
       return a * b;
   };
 
   decltype(f) g = f; // the type of a lambda function is unique and unnamed
источник

С

Слава in rust_offtopic
Alex Zhukovsky
ты уже лостаточно в идрисе должен был покопаться чтобы это понимать
Да тут и идриса не надо
источник

AZ

Alex Zhukovsky in rust_offtopic
Berkus Decker
auto f = [](int a, int b) -> int
   {
       return a * b;
   };
 
   decltype(f) g = f; // the type of a lambda function is unique and unnamed
так а auto не выведет что они одного типа?
источник

Ct

Casual tears in rust_offtopic
Berkus Decker
auto f = [](int a, int b) -> int
   {
       return a * b;
   };
 
   decltype(f) g = f; // the type of a lambda function is unique and unnamed
Тут тоже auto подойдет
источник

AZ

Alex Zhukovsky in rust_offtopic
Слава
Да тут и идриса не надо
ну в шарпе typeof это дорого в один конец. Вызвать Foo<typeof(x)>(x)  нельзя
источник

Ct

Casual tears in rust_offtopic
Berkus Decker
но decltype просто затыкает проблемы в вы…. так, нету царя тут? .. в выводе типов в плюсах
царь бтв этот чат вроде почитывает, так что жди в запарте наезда за такие высказывания
источник

AZ

Alex Zhukovsky in rust_offtopic
template<class A, class B>
void MultiplyAB(A a, B b, decltype(a*b)& output)
{
   output = a * b;
}

@f0land
источник

С

Слава in rust_offtopic
Alex Zhukovsky
ну в шарпе typeof это дорого в один конец. Вызвать Foo<typeof(x)>(x)  нельзя
Я бы взял пример попроще.
var x = 1;
decltype(x) y = default(decltype(x));
источник

С

Слава in rust_offtopic
В шарпе такое не сделаешь
источник

AZ

Alex Zhukovsky in rust_offtopic
Слава
Я бы взял пример попроще.
var x = 1;
decltype(x) y = default(decltype(x));
левый decltype лишний а так да
источник

KR

Kai Ren in rust_offtopic
Berkus Decker
но decltype просто затыкает проблемы в вы…. так, нету царя тут? .. в выводе типов в плюсах
есть, он регулярно почитывает этот чат
источник

С

Слава in rust_offtopic
Alex Zhukovsky
левый decltype лишний а так да
Соглашусь.

И кстати непонятно, почему этого не добавили в шарп. Простая же конструкция.
источник

AZ

Alex Zhukovsky in rust_offtopic
кек
источник

AZ

Alex Zhukovsky in rust_offtopic
Слава
Соглашусь.

И кстати непонятно, почему этого не добавили в шарп. Простая же конструкция.
они слишком заняты решением стоит ли trailing whitespace сохранять в аст или нет
источник

BD

Berkus Decker in rust_offtopic
Casual tears
Тут тоже auto подойдет
я не виноват, это из cppreference пример, спроси с комитета )
источник