Tuesday, March 23, 2021

Digest for comp.lang.c++@googlegroups.com - 2 updates in 2 topics

James Lothian <jameslothian1@gmail.com>: Mar 23 11:22PM

Given the following code:
 
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;
}
 
Visual Studio 2019 and 2015 both say:
C:\Users\James\Documents\SpecTest\SpecTest.cpp(21,37): error C2039:
'Result': is not a member of 'Mul<Length,Mass>'
C:\Users\James\Documents\SpecTest\SpecTest.cpp(21): message : see
declaration of 'Mul<Length,Mass>'
 
Apparently, VC++ picks the base case of the template rather than the
specialisation.
Every online c++ compiler I've managed to find (presumably using gcc)
accepts this code. So, who's right? Am I doing something stupid here?
 
Thanks,
James
Juha Nieminen <nospam@thanks.invalid>: Mar 23 06:44AM

>> Sure, it's longer, but a lot easier to read and understand at a
>> quick glance.
 
> I always select the std::/chrono::-namespaces in my .cpp-file globally.
 
I don't see any advantage in writing "seconds(123)" instead of
"std::chrono::seconds(123)". The latter makes it absolutely clear and
unambiguous what it is. The former is confusing, especially for someone
who is just casually reading the code for the first time.
 
I am not the kind of coder who has this strange obsession with making
everything as short as possible. I prefer clarity over brevity.
Overt brevity only introduces obfuscation.
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: