<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><span class="vcard"><a class="email" href="mailto:richard-llvm@metafoo.co.uk" title="Richard Smith <richard-llvm@metafoo.co.uk>"> <span class="fn">Richard Smith</span></a>
</span> changed
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Increase limit of number of parameters in variadic template packs?"
href="http://llvm.org/bugs/show_bug.cgi?id=21628">bug 21628</a>
<br>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>What</th>
<th>Removed</th>
<th>Added</th>
</tr>
<tr>
<td style="text-align:right;">Status</td>
<td>NEW
</td>
<td>RESOLVED
</td>
</tr>
<tr>
<td style="text-align:right;">CC</td>
<td>
</td>
<td>richard-llvm@metafoo.co.uk
</td>
</tr>
<tr>
<td style="text-align:right;">Resolution</td>
<td>---
</td>
<td>INVALID
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Increase limit of number of parameters in variadic template packs?"
href="http://llvm.org/bugs/show_bug.cgi?id=21628#c3">Comment # 3</a>
on <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - Increase limit of number of parameters in variadic template packs?"
href="http://llvm.org/bugs/show_bug.cgi?id=21628">bug 21628</a>
from <span class="vcard"><a class="email" href="mailto:richard-llvm@metafoo.co.uk" title="Richard Smith <richard-llvm@metafoo.co.uk>"> <span class="fn">Richard Smith</span></a>
</span></b>
<pre>Your code is slow because your algorithm is bad:
template <class TUndInt, class TV, class ...TVs>
constexpr TUndInt CalcMax(TV V, TVs... Vs) noexcept {
return static_cast<TUndInt>(V) > CalcMax<TUndInt>(Vs...) ?
static_cast<TUndInt>(V) : CalcMax<TUndInt>(Vs...);
}
For a list of N elements, this calls CalcMax on a list of N-1 elements twice.
Thus your function's runtime is O(2^N). When your list has 25 elements, this
hits Clang's limit for complexity of constexpr evaluation.
g++ happens to memoize constexpr evaluations, which hides performance problems
in code like this, but Clang does not.
If you switch to a better algorithm, your problem will go away. For instance:
template <class TUndInt, class TV1, class TV2, class ...TVs>
constexpr TUndInt CalcMax(TV1 V1, TV2 V2, TVs... Vs) noexcept {
return static_cast<TUndInt>(V1) > static_cast<TUndInt>(V2)
? CalcMax<TUndInt>(V1, Vs...)
: CalcMax<TUndInt>(V2, Vs...);
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>