On 24.03.2021 00:22, James Lothian wrote:
> template <int L, int M>
> class Unit
> {};
>
> template <class U1, class U2>
> struct Mul
> {};
>
> template <int... L, int... R>
> struct Mul<Unit<L...>, Unit<R...> >
> {
> typedef Unit<L + R...> Result;
> };
>
> typedef Unit<1, 0> Length;
> typedef Unit<0, 1> Mass;
>
> // Error here
> typedef typename Mul<Length, Mass>::Result LM;
>
> int main()
> {
> LM lm;
> return 0;
> }
Looks like a Visual C++ bug. And it looks like a bug related to
parameter pack handling, and not related to (lack of) two-phase template
compilation. I think you should report it.
Workaround:
---------------------------------------------
template< int L, int M >
class Unit {};
template< class U1, class U2 >
struct Mul;
template< int L1, int L2, int R1, int R2 >
struct Mul<Unit<L1, L2>, Unit<R1, R2> >
{
using Result = Unit<L1 + R1, L2 + R2>;
};
using Length = Unit<1, 0>;
using Mass = Unit<0, 1>;
using LM = typename Mul<Length, Mass>::Result;
auto main() -> int
{
LM lm;
(void) lm;
}
---------------------------------------------
However, to my eyes the units computation doesn't seem correct. I don't
know if Boost Units does this correctly, but I think it must. So I
recommend using Boost Units instead.
<url:
https://www.boost.org/doc/libs/1_65_0/doc/html/boost_units.html>
- Alf