diff --git a/migrate/PROMPT.md b/migrate/PROMPT.md index bd7747a1..048c4c89 100644 --- a/migrate/PROMPT.md +++ b/migrate/PROMPT.md @@ -4,7 +4,7 @@ You are a professional C++ documentation writer. You are now migrating cpprefere 3. For links, take the URL part, remove `/w/` and the latter part `.html`, and then wrap it with `DocLink`. For example: If the current path is: `/w/cpp/language/basics.html` Link: `declarations` -You should, based on the current link, change it to: `declarations` +You should, based on the current link, change it to: `declarations` 4. Currently available components: ```mdx {{LLM_DOCS}} diff --git a/src/content/docs/cpp/language/exceptions.mdx b/src/content/docs/cpp/language/exceptions.mdx index cbd54d9d..8a4e6ad6 100644 --- a/src/content/docs/cpp/language/exceptions.mdx +++ b/src/content/docs/cpp/language/exceptions.mdx @@ -13,20 +13,20 @@ import { FeatureTestMacro, FeatureTestMacroValue } from "@components/feature-tes Exception handling provides a way of transferring control and information from some point in the execution of a program to a handler associated with a point previously passed by the execution (in other words, exception handling transfers control up the call stack). -Evaluating a `throw` expression will throw an exception. Exceptions can also be thrown in other contexts. +Evaluating a `throw` expression will throw an exception. Exceptions can also be thrown in other contexts. -In order for an exception to be caught, the `throw` expression has to be inside a `try` block, and the `try` block has to contain a handler that matches the type of the exception object. +In order for an exception to be caught, the `throw` expression has to be inside a `try` block, and the `try` block has to contain a handler that matches the type of the exception object. When declaring a function, the following specification(s) may be provided to limit the types of the exceptions a function may throw: -- dynamic exception specifications -- noexcept specifications +- dynamic exception specifications +- noexcept specifications -Errors that arise during exception handling are handled by `std::terminate` and `std::unexpected`. +Errors that arise during exception handling are handled by `std::terminate` and `std::unexpected`. ## Usage -While `throw` expression can be used to transfer control to an arbitrary block of code up the execution stack, for arbitrary reasons (similar to `std::longjmp`), its intended usage is error handling. +While `throw` expression can be used to transfer control to an arbitrary block of code up the execution stack, for arbitrary reasons (similar to `std::longjmp`), its intended usage is error handling. ### Error handling @@ -36,24 +36,24 @@ Throwing an exception is used to signal errors from functions, where "errors" ar 2. Failures to meet the preconditions of another function that must be called. 3. (for non-private member functions) Failures to (re)establish a class invariant. -In particular, this implies that the failures of constructors (see also RAII) and most operators should be reported by throwing exceptions. +In particular, this implies that the failures of constructors (see also RAII) and most operators should be reported by throwing exceptions. -In addition, so-called *wide contract* functions use exceptions to indicate unacceptable inputs, for example, `std::basic_string::at` has no preconditions, but throws an exception to indicate index out of range. +In addition, so-called *wide contract* functions use exceptions to indicate unacceptable inputs, for example, `std::basic_string::at` has no preconditions, but throws an exception to indicate index out of range. ### Exception safety After the error condition is reported by a function, additional guarantees may be provided with regards to the state of the program. The following four levels of exception guarantee are generally recognized[^4] [^5] [^6], which are strict supersets of each other: -1. *Nothrow (or nofail) exception guarantee* — the function never throws exceptions. Nothrow (errors are reported by other means or concealed) is expected of destructors and other functions that may be called during stack unwinding. The destructors are `noexcept` by default. Nofail (the function always succeeds) is expected of swaps, move constructors, and other functions used by those that provide strong exception guarantee. -2. *Strong exception guarantee* — If the function throws an exception, the state of the program is rolled back to the state just before the function call (for example, `std::vector::push_back`). +1. *Nothrow (or nofail) exception guarantee* — the function never throws exceptions. Nothrow (errors are reported by other means or concealed) is expected of destructors and other functions that may be called during stack unwinding. The destructors are `noexcept` by default. Nofail (the function always succeeds) is expected of swaps, move constructors, and other functions used by those that provide strong exception guarantee. +2. *Strong exception guarantee* — If the function throws an exception, the state of the program is rolled back to the state just before the function call (for example, `std::vector::push_back`). 3. *Basic exception guarantee* — If the function throws an exception, the program is in a valid state. No resources are leaked, and all objects' invariants are intact. 4. *No exception guarantee* — If the function throws an exception, the program may not be in a valid state: resource leaks, memory corruption, or other invariant-destroying errors may have occurred. -Generic components may, in addition, offer *exception-neutral guarantee*: if an exception is thrown from a template parameter (e.g. from the `Compare` function object of `std::sort` or from the constructor of `T` in `std::make_shared`), it is propagated, unchanged, to the caller. +Generic components may, in addition, offer *exception-neutral guarantee*: if an exception is thrown from a template parameter (e.g. from the `Compare` function object of `std::sort` or from the constructor of `T` in `std::make_shared`), it is propagated, unchanged, to the caller. ## Exception objects -While objects of any complete type and cv pointers to `void` may be thrown as exception objects, all standard library functions throw unnamed objects by value, and the types of those objects are derived (directly or indirectly) from `std::exception`. User-defined exceptions usually follow this pattern.[^7] [^8] [^9] +While objects of any complete type and cv pointers to `void` may be thrown as exception objects, all standard library functions throw unnamed objects by value, and the types of those objects are derived (directly or indirectly) from `std::exception`. User-defined exceptions usually follow this pattern.[^7] [^8] [^9] To avoid unnecessary copying of the exception object and object slicing, the best practice for handlers is to catch by reference.[^10] [^11] [^12] [^13] diff --git a/src/content/docs/cpp/language/preprocessor.mdx b/src/content/docs/cpp/language/preprocessor.mdx index 5ac38ed1..44444444 100644 --- a/src/content/docs/cpp/language/preprocessor.mdx +++ b/src/content/docs/cpp/language/preprocessor.mdx @@ -8,7 +8,7 @@ import { Desc, DescList, DocLink } from '@components/index'; import { Revision, RevisionBlock } from "@components/revision"; import { DR, DRList } from "@components/defect-report"; -The preprocessor is executed at translation phase 4, before the compilation. The result of preprocessing is a single file which is then passed to the actual compiler. +The preprocessor is executed at translation phase 4, before the compilation. The result of preprocessing is a single file which is then passed to the actual compiler. ## Directives @@ -17,11 +17,11 @@ The preprocessing directives control the behavior of the preprocessor. Each dire * the `#` character. * a sequence of: * a standard-defined directive name (listed [below](#Capabilities)) followed by the corresponding arguments, or - * one or more preprocessing tokens where the beginning token is not a standard-defined directive name, in this case the directive is conditionally-supported with implementation-defined semantics (e.g. a common extension is the directive `#warning` which emits a user-defined message during compilation), or + * one or more preprocessing tokens where the beginning token is not a standard-defined directive name, in this case the directive is conditionally-supported with implementation-defined semantics (e.g. a common extension is the directive `#warning` which emits a user-defined message during compilation), or * nothing, in this case the directive has no effect. * a line break. -The module and import directives are also preprocessing directives. +The module and import directives are also preprocessing directives. Preprocessing directives must not come from macro expansion. @@ -34,15 +34,15 @@ EMPTY # include // not a preprocessing directive The preprocessor has the source file translation capabilities: -* **conditionally** compile parts of source file (controlled by directive `#if`, `#ifdef`, `#ifndef`, `#else`, `#elif`, `#elifdef`, `#elifndef`, and `#endif`). -* **replace** text macros while possibly concatenating or quoting identifiers (controlled by directives `#define` and `#undef`, and operators `#` and `##`). -* **include** other files (controlled by directive `#include` and checked with `__has_include` ). -* cause an **error** or **warning** (controlled by directive `#error` or `#warning` respectively). +* **conditionally** compile parts of source file (controlled by directive `#if`, `#ifdef`, `#ifndef`, `#else`, `#elif`, `#elifdef`, `#elifndef`, and `#endif`). +* **replace** text macros while possibly concatenating or quoting identifiers (controlled by directives `#define` and `#undef`, and operators `#` and `##`). +* **include** other files (controlled by directive `#include` and checked with `__has_include` ). +* cause an **error** or **warning** (controlled by directive `#error` or `#warning` respectively). The following aspects of the preprocessor can be controlled: -* **implementation-defined** behavior (controlled by directive `#pragma` and operator `_Pragma` ). In addition, some compilers support (to varying degrees) the operator `__pragma` as an extension. -* **file name and line information** available to the preprocessor (controlled by directive `#line`). +* **implementation-defined** behavior (controlled by directive `#pragma` and operator `_Pragma` ). In addition, some compilers support (to varying degrees) the operator `__pragma` as an extension. +* **file name and line information** available to the preprocessor (controlled by directive `#line`). ## Defect reports @@ -63,12 +63,12 @@ The following behavior-changing defect reports were applied retroactively to pre -C++ documentation for Predefined Macro Symbols +C++ documentation for Predefined Macro Symbols -C++ documentation for Macro Symbol Index +C++ documentation for Macro Symbol Index -C documentation for preprocessor +C documentation for preprocessor \ No newline at end of file diff --git a/src/content/docs/cpp/language/templates.mdx b/src/content/docs/cpp/language/templates.mdx index cc5eb202..9d0ff0b3 100644 --- a/src/content/docs/cpp/language/templates.mdx +++ b/src/content/docs/cpp/language/templates.mdx @@ -12,23 +12,23 @@ import { ParamDoc, ParamDocList } from "@components/param-doc"; A template is a C++ entity that defines one of the following: -- a family of classes (class template), which may be nested classes -- a family of functions (function template), which may be member functions +- a family of classes (class template), which may be nested classes +- a family of functions (function template), which may be member functions -- an alias to a family of types (alias template) +- an alias to a family of types (alias template) -- a family of variables (variable template) +- a family of variables (variable template) -- a concept (constraints and concepts) +- a concept (constraints and concepts) -Templates are parameterized by one or more template parameters, of three kinds: type template parameters, constant template parameters, and template template parameters. +Templates are parameterized by one or more template parameters, of three kinds: type template parameters, constant template parameters, and template template parameters. -When template arguments are provided, or, for function and class templates only, deduced, they are substituted for the template parameters to obtain a *specialization* of the template, that is, a specific type or a specific function lvalue. +When template arguments are provided, or, for function and class templates only, deduced, they are substituted for the template parameters to obtain a *specialization* of the template, that is, a specific type or a specific function lvalue. -Specializations may also be provided explicitly: full specializations are allowed for class, variable and function templates, partial specializations are only allowed for class templates and variable templates. +Specializations may also be provided explicitly: full specializations are allowed for class, variable and function templates, partial specializations are only allowed for class templates and variable templates. When a class template specialization is referenced in context that requires a complete object type, or when a function template specialization is referenced in context that requires a function definition to exist, the template is *instantiated* (the code for it is actually compiled), unless the template was already explicitly specialized or explicitly instantiated. Instantiation of a class template does not instantiate any of its member functions unless they are also used. At link time, identical instantiations generated by different translation units are merged. @@ -134,14 +134,14 @@ A template identifier that names a function template specialization names a func If all following conditions are satisfied, a template identifier is *valid*: -- There are at most as many arguments as there are parameters or a parameter is a template parameter pack +- There are at most as many arguments as there are parameters or a parameter is a template parameter pack - There is an argument for each non-deducible non-pack parameter that does not have a default template argument - Each template argument matches the corresponding template parameter - Substitution of each template argument into the following template parameters (if any) succeeds -- If the template identifier is non-dependent, the associated constraints are satisfied as specified below +- If the template identifier is non-dependent, the associated constraints are satisfied as specified below -An invalid simple template id is a compile-time error, unless it names a function template specialization (in which case SFINAE may apply). +An invalid simple template id is a compile-time error, unless it names a function template specialization (in which case SFINAE may apply). ```cpp template @@ -203,25 +203,25 @@ If all following conditions are satisfied, two template identifiers are *same*: - Their `template-name`s or operators refer to the same template - Their corresponding type template arguments are the same type -- The template parameter values determined by their corresponding constant template arguments are template-argument-equivalent +- The template parameter values determined by their corresponding constant template arguments are template-argument-equivalent - Their corresponding template template arguments refer to the same template Two template identifier that are the same refer to the same variable, class, or function. ## Templated entity -A *templated entity* (or, in some sources, "temploid") is any entity that is defined (or, for a lambda expression, created) within a template definition. All of the following are templated entities: +A *templated entity* (or, in some sources, "temploid") is any entity that is defined (or, for a lambda expression, created) within a template definition. All of the following are templated entities: - a class/function/variable template -- a concept +- a concept - a member of a templated entity (such as a non-template member function of a class template) - an enumerator of an enumeration that is a templated entity - any entity defined or created within a templated entity: a local class, a local variable, a friend function, etc -- the closure type of a lambda expression that appears in the declaration of a templated entity +- the closure type of a lambda expression that appears in the declaration of a templated entity For example, in @@ -243,8 +243,8 @@ A *templated class* is a class template or a class that is templated. ## Keywords -template, -export +template, +export ## Defect reports @@ -279,4 +279,4 @@ The following behavior-changing defect reports were applied retroactively to pre ## See also -C documentation for __Generic selection__ \ No newline at end of file +C documentation for __Generic selection__ \ No newline at end of file