C++14 user-defined literal

C++14 added some suffixes to specify the type of some user-define literals.Some of them are shown below.

The suffix ‘s‘ is added in string literal to signify it as a string type.Consider the code below.

auto s=”Happy new year!” ; ///s is ‘const char*’ type

auto st=”Happy”s ;///st is ‘string’ type

auto str=”new” , str1= “addition”s ;///error

The third line will give you an error since str will be deduce as ‘const char*’ type but str1 will be deduce as ‘string’ type.Note the difference here.

The suffixes ‘h‘, ‘min‘, ‘s‘, ‘ms‘, ‘us‘, ‘ns‘ is used to denote various chrono::duration time intervals.

Link : C++11 auto

auto sec=60s ;///s is chrono::seconds type

auto hr=2h ;///hr is chrono::hours type

auto mls=56ms ;///mls is chrono:milli-seconds

For complex class there are some suffixes which specify the literals as complex<float> ,complex<double> and complex<long double>.The suffixes are given below.

if‘, ‘i‘, ‘il‘.

auto comd=345i ;  ///comd is complex<double> type

auto comld=234il ;  ///comld is complex<long double> type