Cover fe ature 47 january 2012 Published by the ieee computer Society 0018-9162/12/$31. 00 2012 ieee



Download 1,78 Mb.
Pdf ko'rish
bet7/32
Sana13.01.2022
Hajmi1,78 Mb.
#355100
1   2   3   4   5   6   7   8   9   10   ...   32
Bog'liq
Software-for-infrastructure

template

struct Unit { 

// a unit in the MKS system

    enum { m=M, kg=K, s=S };  

};

template 

// magnitude with unit

struct Value {

    double val;     

// the magnitude

    explicit Value(double d)

         : val(d) {} 

// construct a Value from a double

};

using Speed = Value>;        

// m/s

using Acceleration = Value>; 

// m/s/s

using Second = Unit<0,0,1>;  

// s

using Second2 = Unit<0,0,2>; 

// s*s

constexpr

Value operator”” s(long double d)

  

// a f-p literal suffixed by 's'

{

   return Value (d); 

}

constexpr

Value operator”” s2(long double d) 

     

 // a f-p literal  suffixed by 's2'

{

  return Value (d);

}

If you aren’t familiar with modern C++, much of this 

code is cryptic. However, it’s fundamentally simple and 

performs all checking and conversions at compile time. 

Obviously, handling the complete SI unit system takes 

more code—about  three pages in all.

Why bother with the user-defined literals, such as 

9.8s

and 



100m

? Many developers dismiss this as redundant and 

distracting “syntactic sugar.” Although a library support-

ing the SI system has been available in C++ for a decade, 

very few people have used it. Most engineers and physi-

cists simply refuse to write code using variants like this:



// a very explicit notation (quite verbose):


Download 1,78 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10   ...   32




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish