There's more...

Though user-defined literals are available from C++11, standard literal operators have been available only from C++14. The following is a list of these standard literal operators:

  • operator""s for defining std::basic_string literals:
        using namespace std::string_literals; 

auto s1{ "text"s }; // std::string
auto s2{ L"text"s }; // std::wstring
auto s3{ u"text"s }; // std::u16string
auto s4{ U"text"s }; // std::u32string
  • operator""h, operator""min, operator""s, operator""ms, operator""us, and operator""ns for creating a std::chrono::duration value:
        using namespace std::literals::chrono_literals; 

// std::chrono::duration<long long>
auto timer {2h + 42min + 15s};
  • operator""if, operator""i, and operator""il for creating a std::complex value:
        using namespace std::literals::complex_literals; 

auto c{ 12.0 + 4.5i }; // std::complex<double>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset