--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
Sounds good to me. One question is what to do with existing typedefs - I'd say leave them alone unless the type is being modified anyway, then switch to using.
Should we suggest that no new code use "typedef", then? And if that's the case, maybe we actually should rewrite these? Note that in the non-function-pointer case, the new syntax is the same number of characters overall.
PK
Should we suggest that no new code use "typedef", then? And if that's the case, maybe we actually should rewrite these? Note that in the non-function-pointer case, the new syntax is the same number of characters overall.That's what I would recommend too. And being the same number of characters doesn't mean that it's as easy/difficult to read as typedef (unless you mean this as a positive thing, in fact that automatic rewrites would not change formatting too much and overflow 80 chars - which is true for simple typdefs that already fit on one line).
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
I think we should do it.
This is now on chromium-cpp.appspot.com.
This is now on chromium-cpp.appspot.com.
Cool!Do we really want to prefer this over typedef generally though? typedef has been around since K&R C, is widely used and understood, and is not particularly confusing unless you try really hard (e.g. `int typedef unsigned a;` is valid code, but nobody does that). But maybe I'm just having a hard time keeping up with progress :-)
On Thu, Oct 9, 2014 at 5:31 PM, David Benjamin <davi...@chromium.org> wrote:This is now on chromium-cpp.appspot.com.
A type alias or a typedef are more like a definition than they are like a declaration. For definitions it typically goes something like <type/keyword> <id> <value>.Examples:int a = 1;class Foo {...};Foo::Foo() {...};Foo foo(val);#define LOG(...) ...using int_type = int;
On Mon, Oct 13, 2014 at 12:52 PM, Chris Hopman <cjho...@chromium.org> wrote:A type alias or a typedef are more like a definition than they are like a declaration. For definitions it typically goes something like <type/keyword> <id> <value>.Examples:int a = 1;class Foo {...};Foo::Foo() {...};Foo foo(val);#define LOG(...) ...using int_type = int;I'll argue that several of these examples actually follow a pattern "type_of_thing thing" which is common in C/C++. E.g. you don't write a = int (1); or Foo = class {...}; or Foo::Foo = function() {...}; or LOG = define(...) ...
etc, etc--Bacek
[...] Another (lesser) use case is that type aliases could be templates too, you can do this:
template<typename T>using StringMapT = std::map<std::string, T>;
[...]
--
template<typename T> struct A {};
template<typename T> using AliasA = A<T>;
template<typename T> struct B {};
template<typename T> using AliasB = B<T>;
template<template<typename> class C, typename T>
void f(const C<T>&) {}
int main() {
auto p1 = &f<AliasA, int>;
auto p2 = &f<AliasB, int>;
auto p3 = &f<A, int>;
auto p4 = &f<B, int>;
f(AliasA<int>{});
f(AliasB<int>{});
f(A<int>{});
f(B<int>{});
}
; auto p1 = &f<AliasA, int>;
mov DWORD PTR _p1$[ebp], OFFSET ??$f@$H@@YAXABU?$A@H@@@Z ; ??$f@$H@@YAXABU?$A@H@@@Z
; auto p2 = &f<AliasB, int>;
mov DWORD PTR _p2$[ebp], OFFSET ??$f@$H@@YAXABU?$A@H@@@Z ; ??$f@$H@@YAXABU?$A@H@@@Z
; auto p3 = &f<A, int>;
mov DWORD PTR _p3$[ebp], OFFSET ??$f@UA@@H@@YAXABU?$A@H@@@Z ; f<A,int>
; auto p4 = &f<B, int>;
mov DWORD PTR _p4$[ebp], OFFSET ??$f@UB@@H@@YAXABU?$B@H@@@Z ; f<B,int>
; f(AliasA<int>{});
xor eax, eax
mov BYTE PTR $T1[ebp], al
lea ecx, DWORD PTR $T1[ebp]
push ecx
call ??$f@UA@@H@@YAXABU?$A@H@@@Z ; f<A,int>
add esp, 4
; f(AliasB<int>{});
xor eax, eax
mov BYTE PTR $T2[ebp], al
lea ecx, DWORD PTR $T2[ebp]
push ecx
call ??$f@UB@@H@@YAXABU?$B@H@@@Z ; f<B,int>
add esp, 4
; f(A<int>{});
xor eax, eax
mov BYTE PTR $T3[ebp], al
lea ecx, DWORD PTR $T3[ebp]
push ecx
call ??$f@UA@@H@@YAXABU?$A@H@@@Z ; f<A,int>
add esp, 4
; f(B<int>{});
xor eax, eax
mov BYTE PTR $T4[ebp], al
lea ecx, DWORD PTR $T4[ebp]
push ecx
call ??$f@UB@@H@@YAXABU?$B@H@@@Z ; f<B,int>
add esp, 4