[Patch] [add changelog] reduce template instantiation depth in <variant>

Tim Shen timshen@google.com
Mon Nov 14 18:06:00 GMT 2016


On Sun, Nov 13, 2016 at 10:53 AM, Barrett Adair wrote:
> My last benchmark didn't have any short-circuiting. Here's a benchmark where
> the first type is not default-constructible, copy-constructible, or
> move-constructible:
>
> http://output.jsbin.com/himusodozu
>

This is interesting result!

I saw a slight slow-down after the change, even for 20 alternatives.
So I'm not sure which way to go.

Do you have a concrete use case of creating a variant with 400 alternatives?

> Ruby template for the benchmark:
>
> #include <variant>
> #include <memory>
>
> int main(int argc, char**) {
>
> #if defined METABENCH
>
>     struct T {
>         int i;
>         std::unique_ptr<int> x;
>         T(int i) : i(i), x(nullptr) {}
>     };
>
>     <% (0..n).each do |i| %>
>     struct T<%= i %> { int i; std::string x; };
>     <% end %>
>
>     using var = std::variant< T, T<%= (0..n).to_a.join(', T') %> >;
>
>     var x(T{0});
>     std::visit([](auto&& v){}, x);
>
> #endif
> }



-- 
Regards,
Tim Shen



More information about the Libstdc++ mailing list