C++中如下的變數聲明見過嗎? auto recommended = 200"000U;
void functionName() {
auto recommended = 200"000U; auto min = 10"000U;}
整型字面量中間可以加一個單個的單引號!有知道這個C++語法的說明說明,謝謝~這段代碼在ScyllaDB代碼中看到,心中惶恐。因為我多年未曾見過一次;
這種寫法,以至於Source Insight無法真確的進行語法高亮。如圖:
C++14新語法integer literal
單引號會被忽略,不要想太多。
C++14新特性,數字千位分割符,數學上雖然是逗號,不過C系語言逗號已經有其他用了,再用逗號歧義不好處理,就用單引號了。
順便說一下Source Insight這種老不更新的古董就拋棄了吧
C++ 14 : Digit separators可以在數字字面量中任意插入[N3781] Lawrence Crowl, Richard Smith, Jeff Snyder, Daveed Vandevoorde: Single-Quotation-Mark as a Digit Separator.
感謝評論指出,回去看了下,果然有問題。
An integer literal is a sequence of digits that has no period or exponent part. An integer literal may have a pre?x that speci?es its base and a su?x that speci?es its type. The lexically ?rst digit of the sequence of digits is the most signi?cant. A decimal integer literal (base ten) begins with a digit other than 0 and consists of a sequence of decimal digits. An octal integer literal (base eight) begins with the digit 0 and consists of a sequence of octal digits.22 A hexadecimal integer literal (base sixteen) begins with 0x or 0X and consists of a sequence of hexadecimal digits, which include the decimal digits and the letters a through f and A through F with decimal values ten through ?fteen. [Example: the number twelve can be written 12, 014, or 0XC. —end example]
來自N3337
An integer literal is a sequence of digits that has no period or exponent part, with optional separating single quotes that are ignored when determining its value.
來自N4140
所以這是C++14的新特性,可以在數字中任意位置添加。===========原答案===========我要是沒記錯的話是c++11的特性,用來分隔數字,每三位一個。推薦閱讀:
※C++的class與struct到底有什麼不同?
※Google C++ Style Guide 中為什麼禁止使用預設函數參數?
※關於C++中的下劃線?
※C++ 如何自動推導遞歸 lambda 函數的類型?
※關於c++ default constructor的問題,這個說法對嗎?