- VS2019 and template specialisation - 2 Updates
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 24 03:21PM +0100 On 24.03.2021 00:22, James Lothian wrote: > 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 |
James Lothian <jameslothian1@gmail.com>: Mar 24 07:25PM Alf P. Steinbach wrote: > 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. Thank you, that's pretty much what I thought. > Workaround: This is a much distilled-down version of something a good bit bigger. I know I can work round this by avoiding the parameter pack and fixing the number of dimensions in a Unit, but this means that when I add another dimension to my units, I have to modify Mul (and Div, and Exp, and so on). I've found that the following creeping horror works: template <class U1, class U2> struct Mul { private: template <int... L, int... R> static auto mulGuts(Unit<L...>, Unit<R...>) { return Unit<L + R...>(); } public: typedef decltype(mulGuts(U1(), U2())) Result; }; but it does creep and it is horrible. > 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> But where's the fun in that :-) Thanks, James |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment