包茎是什么| 老是打饱嗝是什么原因| 诺如病毒吃什么食物| 痉挛什么意思| 相见不如怀念是什么意思| 桃子不能和什么食物一起吃| 英纳格手表什么档次| 霏字五行属什么| 牙疼吃什么药效果最好| 金利来皮带属于什么档次| 为什么会得手足口病| 为什么正骨后几天越来越疼| 补牙属于口腔什么科| 血红蛋白低吃什么可以补起来| 蔬菜沙拉都放什么菜| 如何知道自己是什么星座| 什么是值机| 支原体抗体阳性是什么意思| 什么水果降血压| 无与伦比是什么意思| 撅眼是什么原因造成的| 左室舒张功能减低是什么意思| 多囊有什么危害| 湛蓝湛蓝的什么| 至死不渝什么意思| 一生一世是什么意思| 爱而不得是什么意思| 45年属什么生肖| 紫得什么| 多喝水有什么好处坏处| 7月7号是什么星座| 什么是骨质增生| 天秤座什么象| 91是什么意思| 17度穿什么衣服合适| 曼月乐是什么| 红苕是什么| 鼻子肿了又硬又疼是什么原因| 靖国神社是什么地方| 法西斯是什么意思| 秘辛是什么意思| 教头菜有什么功效| 胡萝卜是什么科| 叶酸什么时间吃最好| 巡警是做什么的| 一字马是什么意思| 梦见自己的手镯断了什么意思| 田加比念什么| 3月7日什么星座| 头疼恶心想吐吃什么药| 眷顾是什么意思| 拉肚子拉出血是什么原因| 人被老鼠咬了什么预兆| 什么家庭不宜挂八骏图| 咩是什么意思| 展望未来什么意思| 性行为是什么意思| 5月17日是什么星座| 蚊子喜欢什么颜色| 百合是什么| 长期胃胀是什么原因| 石斛是什么东西| 五月二十一号是什么星座| 什么是畸胎瘤| 知了代表什么生肖| 甲状腺结节3类什么意思| 110斤穿什么码衣服| 男方派去接亲要说什么| 直肠癌是什么原因引起的| 长春有什么大学| 做梦丢钱了什么征兆| 1901年是什么年| 滑膜炎什么症状| 如是什么意思| 看见蛇过马路什么征兆| 买盘和卖盘是什么意思| b型血的人是什么性格| 反射弧太长是什么意思| 神经病吃什么药效果好| 啪啪啪什么意思| 女人右眼跳是什么意思| 蚊子喜欢咬什么血型| 牛尾炖什么最好| 面粉可以做什么好吃的| 惯犯是什么意思| 素手是什么意思| 膀胱钙化是什么意思| 什么叫双飞| 教师编制是什么意思| 湿疹为什么要查肝功能| 精忠报国是什么生肖| apc药片是什么药| 什么叫因果| 耳朵烫是什么预兆| 屁股痛是什么引起的| 麻薯是什么做的| 艾滋病是什么病毒| 内分泌失调吃什么食物好| 双氧奶是什么| 待见是什么意思| 尿蛋白是什么意思| 什么水果消炎| 梦寐以求是什么意思| 抗核抗体是检查什么的| 小孩长白头发是什么原因| 牙齿出血是什么病| 众矢之的是什么意思| 呸是什么意思| 回民是什么意思| 赵构为什么杀岳飞| 秋刀鱼在中国叫什么鱼| 歌帝梵巧克力什么档次| 甲状腺3类是什么意思| 汕头有什么好玩的景点| 黑匣子什么颜色| 智齿长什么样子| 象是什么结构的字| 尿毒症可以吃什么水果| 探囊取物是什么意思| 月经每个月都推迟是什么原因| 肝左叶囊肿是什么意思| 吃饭容易出汗是什么原因| 手抖是什么原因造成的| 6月24日是什么日子| hla是什么意思| 怀孕吸烟对胎儿有什么影响| hpv吃什么提高免疫力| 色弱是什么| 狗喜欢吃什么食物| 梦见穿破鞋是什么意思| 临终关怀的目的是什么| 治疗白斑最有效的方法是什么| 夜间咳嗽是什么原因| 早早孕试纸什么时候测最准| 驻马店古代叫什么| 子宫脱落是什么原因引起的| 杨柳是什么生肖| 别人梦见我死了是什么意思| 鼻子下面长痘什么原因| 鹦鹉可以吃什么| 鹦鹉叫什么名字好听| 后背发冷发凉属于什么症状| 实蛋是什么| 人流后吃什么恢复快| 手脚软无力是什么原因引起的| 右耳朵热代表什么意思| 处女座是什么象| 圣旨是什么意思| 有龙则灵的灵是什么意思| AFP医学上是什么意思| 惴惴不安什么意思| 乳晕是什么| 3.8什么星座| 高密度脂蛋白是什么意思| 7月8号是什么日子| 为什么胸部会胀痛| 有胆结石的人不能吃什么东西| 马齿苋是什么菜| 口臭吃什么好| 沧州有什么好玩的地方| 拔完智齿吃什么食物好| 什么是桃花劫| ab型和o型生的孩子是什么血型| 据悉是什么意思| 惊恐症是什么病| 十二月二十三是什么星座| 莲雾是什么| 右眉毛跳是什么预兆| 叫人挪车打什么电话| 强直性脊柱炎是什么| 总胆红素偏高有什么危害| 梦见墙倒了有什么预兆| 中位生存期什么意思| 免疫比浊法是什么意思| 玉米吃多了有什么坏处| 穿山甲是什么动物| 人为什么会长智齿| 鸟加衣念什么| 手麻脚麻是什么病| soho是什么意思| 鼻涕倒流到咽喉老吐痰吃什么药能根治| 吃什么东西涨奶最快| 膝关节退行性改变是什么意思| 菜籽油是什么油| py什么意思| 三七主要治什么病| 情人什么意思| 补牙属于口腔什么科| 如火如荼什么意思| 高高的什么| 仲夏夜是什么时候| 中午适合吃什么| 脂肪是什么颜色| 霉菌性阴道炎是什么引起的| 怀孕孕酮低有什么影响| 直率是什么意思| 晚上七点多是什么时辰| 夫妻肺片是什么肉| 斐乐手表属于什么档次| 微量泵是干什么用的| 阿尔茨海默症吃什么药| 感冒咳嗽吃什么食物好| 身上痒是什么原因| 畸胎瘤是什么病严重吗| 衬衫什么面料好| 在什么前面用英语怎么说| 每天坚持跑步有什么好处| 衿字五行属什么| 胃热吃什么药效果好| 肋骨外翻是什么原因| 子宫内膜不均匀是什么意思| 安全监察是一种带有什么的监督| 什么克水| 吃完桃子不能吃什么| 查高血压挂什么科| 彪马属于什么档次| ost什么意思| 鸡黍是什么意思| 阴虚湿热吃什么中成药| 烧头七有什么讲究| 梦见自己洗头发是什么意思| 春回大地是什么生肖| 太阳黑子是什么东西| 早餐吃什么比较好| 心绪是什么意思| 白月光是什么意思| 牙槽骨吸收是什么意思| 越描越黑是什么意思| 肝脏检查挂什么科| 嫩模是什么意思| 脏器灰阶立体成像是检查什么的| 日语牙白什么意思| 脚底痛什么原因| 脚底板脱皮是什么原因| 佝偻是什么意思| 木指什么生肖| 紫色适合什么肤色的人| 酵素是什么| 高考什么时候恢复的| 林彪为什么叛变| 女人梦到蛇预示着什么| 肺部占位性的病变指什么| 伊始是什么意思| 佳人是什么生肖| 为什么会长子宫肌瘤| 小水滴会变成什么| 右边小腹疼是什么原因| 苦不堪言是什么意思| 尿细菌高是什么原因| 总lge是什么| ad什么时候吃最好| 猪蛋是什么| 澄字五行属什么| 做梦梦到蟒蛇是什么征兆| 红豆杉是什么植物| 喉咙吞口水痛吃什么药| 男性硬不起来什么原因| 副乳有什么危害吗| 观音婢是什么意思| cpi指数是什么意思| 头昏脑胀吃什么药| 双子座男和什么座最配对| 内衣为什么会发霉| 太燃了是什么意思| 百度
百度 安徽宿州埇桥马戏协会会长杨志远称,其实双方的矛盾冲突由来已久,“我们都是合法经营,动物是国家林业局发给我们动物繁殖许可证演出的,演出证经过国家文化部批准,各方手续我们都按国家法律走的。

C++14 is a version of the ISO/IEC 14882 standard for the C++ programming language. It is intended to be a small extension over C++11, featuring mainly bug fixes and small improvements, and was replaced by C++17. Its approval was announced on August 18, 2014.[1] C++14 was published as ISO/IEC 14882:2014 in December 2014.[2]

Because earlier C++ standard revisions were noticeably late, the name "C++1y" was sometimes used instead until its approval, similarly to how the C++11 standard used to be termed "C++0x" with the expectation of its release before 2010 (although in fact it slipped into 2010 and finally 2011).

New language features

edit

These are the features added to the core language of C++14.

Function return type deduction

edit

C++11 allowed lambda functions to deduce the return type based on the type of the expression given to the return statement. C++14 provides this ability to all functions. It also extends these facilities to lambda functions, allowing return type deduction for functions that are not of the form return expression;.[3]

In order to induce return type deduction, the function must be declared with auto as the return type, but without the trailing return type specifier in C++11:

auto DeduceReturnType();   // Return type to be determined.

If multiple return expressions are used in the function's implementation, then they must all deduce the same type.[4]

Functions that deduce their return types can be forward declared, but they cannot be used until they have been defined. Their definitions must be available to the translation unit that uses them.

Recursion can be used with a function of this type, but the recursive call must happen after at least one return statement in the definition of the function:[4]

auto Correct(int i)
{
  if (i == 1)
    return i;             // return type deduced as int

  return Correct(i-1)+i;  // ok to call it now
}

auto Wrong(int i)
{
  if (i != 1)
    return Wrong(i-1)+i;  // Too soon to call this. No prior return statement.

  return i;               // return type deduced as int
}

Alternate type deduction on declaration

edit

In C++11, two methods of type deduction were added. auto was a way to create a variable of the appropriate type, based on a given expression. decltype was a way to compute the type of a given expression. However, decltype and auto deduce types in different ways. In particular, auto always deduces a non-reference type, as though by using std::decay, while auto&& always deduces a reference type. However, decltype can be prodded into deducing a reference or non-reference type, based on the value category of the expression and the nature of the expression it is deducing:[5][3]

int   i;
int&& f();
auto          x3a = i;     // decltype(x3a) is int
decltype(i)   x3d = i;     // decltype(x3d) is int
auto          x4a = (i);   // decltype(x4a) is int
decltype((i)) x4d = (i);   // decltype(x4d) is int&
auto          x5a = f();   // decltype(x5a) is int
decltype(f()) x5d = f();   // decltype(x5d) is int&&

C++14 adds the decltype(auto) syntax. This allows auto declarations to use the decltype rules on the given expression.

The decltype(auto) syntax can also be used with return type deduction, by using decltype(auto) syntax instead of auto for the function's return type deduction.[4]

Relaxed constexpr restrictions

edit

C++11 introduced the concept of a constexpr-declared function; a function which could be executed at compile time. Their return values could be consumed by operations that require constant expressions, such as an integer template argument. However, C++11 constexpr functions could only contain a single expression that is returned (as well as static_asserts and a small number of other declarations).

C++14 relaxes these restrictions. Constexpr-declared functions may now contain the following:[3]

  • Any declarations except:
    • static or thread_local variables.
    • Variable declarations without initializers.
  • The conditional branching statements if and switch.
  • Any looping statement, including range-based for.
  • Expressions which change the value of an object if the lifetime of that object began within the constant expression function. This includes calls to any non-const constexpr-declared non-static member functions.

goto statements are forbidden in C++14 relaxed constexpr-declared functions.

Also, C++11 stated that all non-static member functions that were declared constexpr were also implicitly declared const, with respect to this. That has since been removed; non-static member functions may be non-const.[6] However, per the restrictions above, a non-const constexpr member function can only modify a class member if that object's lifetime began within the constant expression evaluation.

Variable templates

edit

In prior versions of C++, only functions, classes or type aliases could be templated. C++14 allows the creation of variables that are templated. An example given in the proposal is a variable pi that can be read to get the value of pi for various types (e.g., 3 when read as an integral type; the closest value possible with float, double or long double precision when read as float, double or long double, respectively; etc.).

The usual rules of templates apply to such declarations and definitions, including specialization.[7][8]

template<typename T>
constexpr T pi = T(3.141592653589793238462643383);

// Usual specialization rules apply:
template<>
constexpr const char* pi<const char*> = "pi";

Aggregate member initialization

edit

C++11 added default member initializers, expressions to be applied to members at class scope if a constructor did not initialize the member itself. The definition of aggregates was changed to explicitly exclude any class with member initializers; therefore, they are not allowed to use aggregate initialization.

C++14 relaxes this restriction,[3] allowing aggregate initialization on such types. If the braced init list does not provide a value for that argument, the member initializer takes care of it.[9]

Binary literals

edit

Numeric literals in C++14 can be specified in binary form.[3] The syntax uses the prefixes 0b or 0B. The syntax is also used in other languages e.g. Java, C#, Swift, Go, Scala, Ruby, Python, OCaml, and as an unofficial extension in some C compilers since at least 2007.[10]

Digit separators

edit

In C++14, the single-quote character may be used arbitrarily as a digit separator in numeric literals, both integer literals and floating point literals.[11] This can make it easier for human readers to parse large numbers through subitizing.

auto integer_literal = 1'000'000;
auto floating_point_literal = 0.000'015'3;
auto binary_literal = 0b0100'1100'0110;
auto a_dozen_crores = 12'00'00'000;

Generic lambdas

edit

In C++11, lambda function parameters need to be declared with concrete types. C++14 relaxes this requirement, allowing lambda function parameters to be declared with the auto type specifier.[7]

auto lambda = [](auto x, auto y) {return x + y;};

Concerning auto type deduction, generic lambdas follow the rules of template argument deduction (which are similar, but not identical in all respects[clarification needed]). The code above is equivalent to this:[12]

struct
{
  template<typename T, typename U>
    auto operator()(T x, U y) const {return x + y;}
} lambda{};

Generic lambdas are essentially templated functor lambdas.

Lambda capture expressions

edit

C++11 lambda functions capture variables declared in their outer scope by value-copy or by reference. This means that value members of a lambda cannot be move-only types.[13] C++14 allows captured members to be initialized with arbitrary expressions. This allows both capture by value-move and declaring arbitrary members of the lambda, without having a correspondingly named variable in an outer scope.[7]

This is done via the use of an initializer expression:

auto lambda = [value = 1] {return value;};

The lambda function lambda returns 1, which is what value was initialized with. The declared capture deduces the type from the initializer expression as if by auto.

This can be used to capture by move, via the use of the standard std::move function:

std::unique_ptr<int> ptr(new int(10));
auto lambda = [value = std::move(ptr)] {return *value;};

The attribute [[deprecated]]

edit

The deprecated attribute allows marking an entity deprecated, which makes it still legal to use but puts users on notice that use is discouraged and may cause a warning message to be printed during compilation. An optional string literal can appear as the argument of deprecated, to explain the rationale for deprecation and suggest a replacement.

[[deprecated]] int f();

[[deprecated("g() is thread-unsafe. Use h() instead")]]
void g( int& x );

void h( int& x );

void test()
{
  int a = f(); // warning: 'f' is deprecated
  g(a); // warning: 'g' is deprecated: g() is thread-unsafe. Use h() instead
}

New standard library features

edit

Shared mutexes and locking

edit

C++14 adds a shared timed mutex and a companion shared lock type.[14][15]

Heterogeneous lookup in associative containers

edit

The C++ Standard Library defines four associative container classes. These classes allow the user to look up a value based on a value of that type. The map containers allow the user to specify a key and a value, where lookup is done by key and returns a value. However, the lookup is always done by the specific key type, whether it is the key as in maps or the value itself as in sets.

C++14 allows the lookup to be done via an arbitrary type, so long as the comparison operator can compare that type with the actual key type.[16] This would allow a map from std::string to some value to compare against a const char* or any other type for which an operator< overload is available. It is also useful for indexing composite objects in a std::set by the value of a single member without forcing the user of find to create a dummy object (for example creating an entire struct Person to find a person by name).

To preserve backwards compatibility, heterogeneous lookup is only allowed when the comparator given to the associative container allows it. The standard library classes std::less<> and std::greater<> are augmented to allow heterogeneous lookup.[17]

Standard user-defined literals

edit

C++11 defined the syntax for user-defined literal suffixes, but the standard library did not use any of them. C++14 adds the following standard literals:[16]

  • "s", for creating the various std::basic_string types.
  • "h", "min", "s", "ms", "us", "ns", for creating the corresponding std::chrono::duration time intervals.
  • "if", "i", "il", for creating the corresponding std::complex<float>, std::complex<double> and std::complex<long double> imaginary numbers.
auto str = "hello world"s; // auto deduces string
auto dur = 60s;            // auto deduces chrono::seconds
auto z   = 1i;             // auto deduces complex<double>

The two "s" literals do not clash, as the string one only operates on string literals, and the one for seconds operates only on numbers.[18]

Tuple addressing via type

edit

The std::tuple type introduced in C++11 allows an aggregate of typed values to be indexed by a compile-time constant integer. C++14 extends this to allow fetching from a tuple by type instead of by index.[16] If the tuple has more than one element of the type, a compile-time error results:[19]

tuple<string, string, int> t("foo", "bar", 7);
int i = get<int>(t);        // i == 7
int j = get<2>(t);          // Same as before: j == 7
string s = get<string>(t);  // Compile-time error due to ambiguity

Smaller library features

edit

std::make_unique can be used like std::make_shared for std::unique_ptr objects.[7]

std::integral_constant gained an operator() overload to return the constant value.[16]

The class template std::integer_sequence and related alias templates were added for representing compile-time integer sequences, such as the indices of elements in a parameter pack.[20]

The global std::begin/std::end functions were augmented with std::cbegin/std::cend functions, which return constant iterators, and std::rbegin/std::rend and std::crbegin/std::crend which return reverse iterators.

The std::exchange function template assigns a new value to a variable and returns the old value.[21]

New overloads of std::equal, std::mismatch, and std::is_permutation take a pair of iterators for the second range, so that the caller does not need to separately check that the two ranges are of the same length.[22]

The std::is_final type trait detects if a class is marked final.

The std::quoted stream I/O manipulator allows inserting and extracting strings with embedded spaces, by placing delimiters (defaulting to double-quotes) on output and stripping them on input, and escaping any embedded delimiters.[23]

Compiler support

edit

Clang finished support for C++14 in 3.4 though under the standard name c++1y, and made C++14 the default C++ standard in Clang 6.[24] GCC finished support for C++14 in GCC 5, and made C++14 the default C++ standard in GCC 6.[25] Microsoft Visual Studio 2017 has implemented "almost all" C++14 features.[26]

References

edit
  1. ^ Sutter, Herb (August 18, 2014), We have C++14!, retrieved 2025-08-14
  2. ^ "ISO/IEC 14882:2014". ISO.
  3. ^ a b c d e Wong, Michael (30 April 2013). "The View from the C++ Standard meeting April 2013 Part 1". C/C++ Cafe. Retrieved 27 January 2016.
  4. ^ a b c Merrill, Jason (17 April 2013). "N3638 Return type deduction for normal functions (Revision 5)". Retrieved 14 June 2013.
  5. ^ "Page 10 of: C++ auto and decltype Explained".
  6. ^ Smith, Richard (18 April 2013). "N3652 Relaxing constraints on constexpr functions".
  7. ^ a b c d Sutter, Herb (20 April 2013). "Trip Report: ISO C++ Spring 2013 Meeting". isocpp.org. Retrieved 14 June 2013.
  8. ^ Dos Reis, Gabriel (19 April 2013). "N3651 Variable Templates (Revision 1)" (PDF).
  9. ^ Vandevoorde, Daveed; Voutilainen, Ville (17 April 2013). "N3653 Member initializers and aggregates".
  10. ^ "23479 – Implement binary constants with a "0b" prefix".
  11. ^ Crowl, Lawrence; Smith, Richard; Snyder, Jeff; Vandevoorde, Daveed (25 September 2013). "N3781 Single-Quotation-Mark as a Digit Separator" (PDF).
  12. ^ Vali, Faisal; Sutter, Herb; Abrahams, Dave (19 April 2013). "N3649 Generic (Polymorphic) Lambda Expressions (Revision 3)".
  13. ^ "Move capture in Lambda". Stack Overflow.
  14. ^ Wong, Michael (30 April 2013). "The View from the C++ Standard meeting April 2013 Part 3". C/C++ Cafe. Retrieved 14 June 2013.
  15. ^ Hinnant, Howard; Vollmann, Detlef; Boehm, Hans (19 April 2013). "N3659 Shared locking in C++ (Revision 2)".
  16. ^ a b c d Wong, Michael (26 April 2013). "The View from the C++ Standard meeting April 2013 Part 2". C/C++ Cafe. Retrieved 14 June 2013.
  17. ^ "N3657 Adding heterogeneous comparison lookup to associative containers (rev 4)". 19 March 2013.
  18. ^ Sommerlad, Peter (18 April 2013). "N3642 User-defined Literals for Standard Library Types (part 1 - version 4)" (PDF).
  19. ^ Spertus, Mike (19 April 2013). "N3670 Wording for Addressing Tuples by Type: Revision 2".
  20. ^ Wakely, Jonathan (18 April 2013). "N3658 Compile-time integer sequences". Retrieved 5 January 2016.
  21. ^ Yasskin, Jeffrey (19 April 2013). "N3668 exchange() utility function, revision 3". Retrieved 5 January 2016.
  22. ^ Spertus, Mike; Pall, Attila (19 April 2013). "N3671 Making non-modifying sequence operations more robust: Revision 2". Retrieved 5 January 2016.
  23. ^ Dawes, Beman (19 April 2013). "N3654 Quoted Strings Library Proposal (Revision 2)". Retrieved 5 January 2016.
  24. ^ "C++ Support in Clang". Retrieved 28 May 2016.
  25. ^ "C++ Standards Support in GCC". Retrieved 28 May 2016.
  26. ^ "C++ Standards Conformance from Microsoft". 7 March 2017. Retrieved 7 March 2017.
edit
康乃馨的花语是什么 一个合一个页读什么 儿童鸡胸挂什么科 儿童水痘吃什么药 智字五行属什么
处女座的幸运数字是什么 地高辛是什么药 阿戈美拉汀片是什么药 油嘴滑舌是什么意思 非亲非故是什么意思
两个菱形是什么牌子 红馆是什么地方 口腔溃疡反反复复是什么原因 餐中服用是什么意思 过敏性咳嗽用什么药效果好
中医师承是什么意思 肩周炎有什么症状 三个子字念什么 蟹爪兰什么时候开花 尿酸高会引起什么病
尾巴骨疼挂什么科hcv7jop9ns1r.cn 嘴唇干燥是什么原因hcv8jop0ns9r.cn 宝批龙是什么意思hcv8jop0ns3r.cn 苔菜是什么菜图片hcv8jop1ns8r.cn 胸腰椎退行性变是什么意思hcv8jop0ns1r.cn
吾日三省吾身是什么意思hcv8jop0ns1r.cn 梦见自己大笑是什么意思xianpinbao.com 吃三七粉不能吃什么hcv8jop8ns1r.cn 李嘉诚是什么国籍hcv7jop5ns1r.cn 96年是什么年hcv9jop0ns7r.cn
90年属于什么生肖wzqsfys.com 螃蟹不能和什么食物一起吃hcv9jop5ns0r.cn 屁股疼挂什么科室hcv9jop4ns1r.cn 人造革是什么材质hcv7jop6ns2r.cn 首发是什么意思hcv8jop1ns3r.cn
勺子是什么意思hcv9jop5ns1r.cn 乳头瘤是什么病hcv8jop6ns1r.cn 电解液是什么hcv9jop1ns5r.cn 西夏国是现在什么地方hcv9jop1ns5r.cn 什么是正装hcv8jop5ns1r.cn
百度