C++11 user-defined literals

Source: Internet
Author: User

C++11 user-defined literals

#define_crt_secure_no_warnings#include<iostream>#include<string>#include<vector>#include<map>//user-defined literals, or "custom suffixes", are more intuitive, and the main purpose is to simplify the reading and writing of code. Long Double operator""_MM (Long Doublex) {returnX/ +; }Long Double operator""_m (Long Doublex) {returnx;}Long Double operator""_KM (Long Doublex) {returnX * +; }/*according to the C + + 11 standard, only the following parameter list is valid char const *unsigned LONG longlong Doublechar const *, size_twchar_t const *, size_tchar16 _t Const *, size_tchar32_t const *, size_t the last four are quite useful for strings, because the second argument is automatically inferred as the length of the string*/size_toperator""_len (Char Const*str, size_t size) {    returnsize;}//for the parameter Char const *, it should be called the original literal raw literal operator.Char Const*operator""_r (Char Const*str) {    returnstr;}voidmytest () {std::cout<<1.0_mm << Std::endl;//0.001Std::cout <<1.0_m << Std::endl;//1Std::cout <<1.0_km << Std::endl;// +Std::cout<<"XYZ"_len << Std::endl;//result is 3Std::cout<< 250_r << Std::endl;//The result is    return;}intMain () {mytest (); System ("Pause"); return 0;}

C++11 user-defined literals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.