1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 #include "support/timer.h"
15 template <std::size_t Indx
, std::size_t Depth
>
17 : public virtual C
<Indx
, Depth
-1>,
18 public virtual C
<Indx
+1, Depth
-1>
23 template <std::size_t Indx
>
29 template <std::size_t Indx
, std::size_t Depth
>
31 : public virtual C
<Indx
, Depth
-1>,
32 public virtual C
<Indx
+1, Depth
-1>
36 template <class Indx
, std::size_t Depth
>
39 template <std::size_t ...Indx
, std::size_t Depth
>
40 struct makeB
<std::__tuple_indices
<Indx
...>, Depth
>
41 : public B
<Indx
, Depth
>...
45 template <std::size_t Width
, std::size_t Depth
>
47 : public makeB
<typename
std::__make_tuple_indices
<Width
>::type
, Depth
>
53 const std::size_t Width
= 10;
54 const std::size_t Depth
= 5;
56 typedef B
<Width
/2, Depth
> Destination
;
57 // typedef A<Width, Depth> Destination;
58 Destination
*b
= nullptr;
61 b
= dynamic_cast<Destination
*>((C
<Width
/2, 0>*)&a
);
74 Timing results I'm seeing (median of 3 microseconds):
76 libc++abi gcc's dynamic_cast
77 B<Width/2, Depth> -O3 48.334 93.190 libc++abi 93% faster
78 B<Width/2, Depth> -Os 58.535 94.103 libc++abi 61% faster
79 A<Width, Depth> -O3 11.515 33.134 libc++abi 188% faster
80 A<Width, Depth> -Os 12.631 31.553 libc++abi 150% faster