[libcxx-commits] [PATCH] D107772: [libc++][NFC] Remove workaround for variadic templates in C++03

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 9 16:42:57 PDT 2021


Quuxplusone added inline comments.


================
Comment at: libcxx/src/locale.cpp:84-85
 
-template <class T, class A0>
-inline
-T&
-make(A0 a0)
-{
-    static typename aligned_storage<sizeof(T)>::type buf;
-    auto *obj = ::new (&buf) T(a0);
-    return *obj;
-}
-
-template <class T, class A0, class A1>
-inline
-T&
-make(A0 a0, A1 a1)
-{
-    static typename aligned_storage<sizeof(T)>::type buf;
-    ::new (&buf) T(a0, a1);
-    return *reinterpret_cast<T*>(&buf);
-}
-
-template <class T, class A0, class A1, class A2>
-inline
-T&
-make(A0 a0, A1 a1, A2 a2)
+template <class T, class ...Args>
+T& make(Args ...args)
 {
----------------
ldionne wrote:
> Quuxplusone wrote:
> > As in that other recent review, please prefer libc++ style: `class... Args` and `Args... args`.
> There's no "libc++" style in this case. I get 652 hits for `class ...`, and 940 hits for `class...`, so there's no clearly consistent approach here. If you can explain to me why `class...` is better, I'll change it.
> If you can explain to me why `class...` is better, I'll change it.

Only the stylistic argument that it's "what we've always done" (and what you've done as recently as D101277, although I guess that started out as Chris's patch). I do see now that we've got a mix in libc++; `class...` predominates but not overwhelmingly. Likewise `Ts&&... ts` mildly predominates over `Ts&& ...ts` (and overwhelmingly over `Ts &&...ts`, of course; we also have 8 instances of `Ts &&... ts`).

The Standard draft itself does use `class... Ts` (and `T& t`, and west const) as //its// house style:
```
$ git grep 'class[.][.][.] [A-Z]' | wc -l
     424
$ git grep 'class [.][.][.][A-Z]' | wc -l
       1
$ git grep 'typename[.][.][.] [A-Z]' | wc -l
      10
$ git grep 'typename [.][.][.][A-Z]' | wc -l
       5
```

Arguably, `<class... Ts>` has the minor benefit that when you textually delete the trailing parameter name, you get `<class...>`, which we do overwhelmingly prefer over `<class ...>`:
```
$ git grep '[^ ][.][.][.]>' libcxx/include/ | wc -l
     778
$ git grep '[ ][.][.][.]>' libcxx/include/ | wc -l
       9
```
Anyway, I'll try to stop commenting on this. I really just noticed you doing it on the patch the other day; I'd never noticed it before this week.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107772/new/

https://reviews.llvm.org/D107772



More information about the libcxx-commits mailing list