From 6a9d133052b3600c905b5afaa152aea5a87c81c1 Mon Sep 17 00:00:00 2001 From: TylerMSFT <12305055+TylerMSFT@users.noreply.github.com> Date: Tue, 25 Aug 2026 10:54:34 -0700 Subject: [PATCH 1/7] tech review --- docs/cpp/static-function-call-operator.md | 3 ++- docs/cpp/subscripting.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/cpp/static-function-call-operator.md b/docs/cpp/static-function-call-operator.md index b1fbb12d62..e17160d142 100644 --- a/docs/cpp/static-function-call-operator.md +++ b/docs/cpp/static-function-call-operator.md @@ -22,6 +22,7 @@ You can also declare the function call operator generated for a lambda expressio ```cpp [](parameter-list) static { function-body } +[] static { function-body } ``` ## Remarks @@ -30,7 +31,7 @@ A static function call operator doesn't have a `this` pointer. It can't be `virt You can call a static function call operator by using an object of its class, which allows the object to work as a function object. You can also call it by using its qualified name. Taking its address produces a regular function pointer instead of a pointer-to-member function. -A lambda expression can specify `static` after its parameter list. A static lambda can't have captures or be declared `mutable`. Declaring a captureless lambda doesn't make it static automatically; you must specify `static` to opt in to this behavior. +A lambda expression can specify `static` after its parameter list. When the lambda has no parameters, you can omit the empty parameter list and specify `static` after the lambda introducer (`[]`). A static lambda can't have captures or be declared `mutable`. Declaring a captureless lambda doesn't make it static automatically; you must specify `static` to opt in to this behavior. The feature-test macro `__cpp_static_call_operator` is defined when the static function call operator is available. diff --git a/docs/cpp/subscripting.md b/docs/cpp/subscripting.md index fca0cb6b2a..ddf1ecd071 100644 --- a/docs/cpp/subscripting.md +++ b/docs/cpp/subscripting.md @@ -7,7 +7,7 @@ ms.assetid: eb151281-6733-401d-9787-39ab6754c62c --- # Subscripting -The subscript operator (**[ ]**), like the function-call operator, is a binary operator. Before C++23, the subscript operator must be a nonstatic member function. In C++23 and later, it can be a static member function. For more information, see [Static subscript operator](static-subscript-operator.md). +The built-in subscript operator (**[ ]**) is a binary operator. Before C++23, an overloaded subscript operator (`operator[]`) had to be a nonstatic member function. In C++23 and later, it can also be a static member function. For more information, see [Static subscript operator](static-subscript-operator.md). The argument can be any type and designates the desired array subscript. From 3eb970a74002a8eca32ebf30a98e51de1c80986e Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Tue, 25 Aug 2026 11:03:03 -0700 Subject: [PATCH 2/7] Update subscripting.md for C++23 clarification Clarified the explanation of the subscript operator in C++23. --- docs/cpp/subscripting.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/cpp/subscripting.md b/docs/cpp/subscripting.md index ddf1ecd071..a84540e837 100644 --- a/docs/cpp/subscripting.md +++ b/docs/cpp/subscripting.md @@ -9,6 +9,8 @@ ms.assetid: eb151281-6733-401d-9787-39ab6754c62c The built-in subscript operator (**[ ]**) is a binary operator. Before C++23, an overloaded subscript operator (`operator[]`) had to be a nonstatic member function. In C++23 and later, it can also be a static member function. For more information, see [Static subscript operator](static-subscript-operator.md). +The built-in subscript operator (**[ ]**) is a binary operator. Before C++23, subscript operator (`operator[]`) overloads had to be nonstatic member functions. In C++23 and later, you can also overload using a static member function. For more information, see [Static subscript operator](static-subscript-operator.md). + The argument can be any type and designates the desired array subscript. ## Example From 3e06ef8f6952899620f70c610758cd7b42c0cbd1 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Tue, 25 Aug 2026 11:09:58 -0700 Subject: [PATCH 3/7] Update subscripting.md --- docs/cpp/subscripting.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/cpp/subscripting.md b/docs/cpp/subscripting.md index a84540e837..07f12b7bc6 100644 --- a/docs/cpp/subscripting.md +++ b/docs/cpp/subscripting.md @@ -7,9 +7,7 @@ ms.assetid: eb151281-6733-401d-9787-39ab6754c62c --- # Subscripting -The built-in subscript operator (**[ ]**) is a binary operator. Before C++23, an overloaded subscript operator (`operator[]`) had to be a nonstatic member function. In C++23 and later, it can also be a static member function. For more information, see [Static subscript operator](static-subscript-operator.md). - -The built-in subscript operator (**[ ]**) is a binary operator. Before C++23, subscript operator (`operator[]`) overloads had to be nonstatic member functions. In C++23 and later, you can also overload using a static member function. For more information, see [Static subscript operator](static-subscript-operator.md). +The built-in subscript operator (**[ ]**) is a binary operator. Before C++23, you had to overload the subscript operator (`operator[]`) with a nonstatic subscript operator member function. In C++23 and later, you can also overload it with a static subscript operator member function. For more information, see [Static subscript operator](static-subscript-operator.md). The argument can be any type and designates the desired array subscript. From 09b01e696021e4b46b2bac463a6b5eaedd22cf54 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Tue, 25 Aug 2026 13:31:40 -0700 Subject: [PATCH 4/7] Apply suggestion from @learn-build-service-prod-03[bot] Co-authored-by: learn-build-service-prod-03[bot] <274428581+learn-build-service-prod-03[bot]@users.noreply.github.com> --- docs/cpp/subscripting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cpp/subscripting.md b/docs/cpp/subscripting.md index 07f12b7bc6..bb36ccb61a 100644 --- a/docs/cpp/subscripting.md +++ b/docs/cpp/subscripting.md @@ -7,7 +7,7 @@ ms.assetid: eb151281-6733-401d-9787-39ab6754c62c --- # Subscripting -The built-in subscript operator (**[ ]**) is a binary operator. Before C++23, you had to overload the subscript operator (`operator[]`) with a nonstatic subscript operator member function. In C++23 and later, you can also overload it with a static subscript operator member function. For more information, see [Static subscript operator](static-subscript-operator.md). +The built-in subscript operator (**[ ]**) is a binary operator. Before C++23, you had to overload the subscript operator (`operator[]`) by using a nonstatic subscript operator member function. In C++23 and later, you can also overload it by using a static subscript operator member function. For more information, see [Static subscript operator](static-subscript-operator.md). The argument can be any type and designates the desired array subscript. From aff91061551e6a741cfe354c514646b0dcd8c5b0 Mon Sep 17 00:00:00 2001 From: TylerMSFT <12305055+TylerMSFT@users.noreply.github.com> Date: Wed, 26 Aug 2026 14:20:38 -0700 Subject: [PATCH 5/7] last edits --- docs/cpp/static-function-call-operator.md | 9 +++++---- docs/cpp/static-subscript-operator.md | 12 +++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/cpp/static-function-call-operator.md b/docs/cpp/static-function-call-operator.md index e17160d142..e8ad181f34 100644 --- a/docs/cpp/static-function-call-operator.md +++ b/docs/cpp/static-function-call-operator.md @@ -1,7 +1,7 @@ --- description: "Learn how to declare and use the static function call operator in C++." -title: "Static function call operator (C++)" -ms.date: 08/19/2026 +title: "Static function call operator (C++23)" +ms.date: 08/26/2026 ai-usage: ai-assisted helpviewer_keywords: ["static function call operator [C++]", "static operator() [C++]", "operator overloading [C++]"] --- @@ -10,7 +10,7 @@ helpviewer_keywords: ["static function call operator [C++]", "static operator() In C++23, you can declare the function call operator (`operator()`) as a static member function. A static function call operator doesn't have an implicit object parameter. Use it when a callable type doesn't need to access instance data. -Support for this feature was introduced in Visual Studio 2022 version 17.14 (MSVC 14.44). Use the `/std:c++latest` compiler option. +Support for this feature was introduced in Visual Studio 2022 version 17.14 (MSVC 14.44). Use the `/std:c++latest` or `/std:c++23preview` compiler option. ## Syntax @@ -37,7 +37,7 @@ The feature-test macro `__cpp_static_call_operator` is defined when the static f ## Example -The following example defines a stateless function object and calls its static function call operator in three ways: +The following example defines a stateless function object and calls its static function call operator in three ways. It also defines a static lambda expression and calls it: ```cpp // Compile with: /std:c++latest @@ -64,6 +64,7 @@ int main() std::cout << "multiply_function(5, 5) = " << multiply_function(5, 5) << std::endl; + // A static lambda expression that doubles its argument auto twice = [](int value) static noexcept { return value * 2; diff --git a/docs/cpp/static-subscript-operator.md b/docs/cpp/static-subscript-operator.md index fd0498a3bf..478e97bdb5 100644 --- a/docs/cpp/static-subscript-operator.md +++ b/docs/cpp/static-subscript-operator.md @@ -1,7 +1,7 @@ --- description: "Learn how to declare and use the static subscript operator in C++." title: "Static subscript operator (C++)" -ms.date: 08/19/2026 +ms.date: 08/26/2026 ai-usage: ai-assisted helpviewer_keywords: ["static subscript operator [C++]", "static operator[] [C++]", "operator overloading [C++]"] --- @@ -22,9 +22,15 @@ static return-type operator[](parameter-list); A static subscript operator doesn't have a `this` pointer. It can't be `virtual` or have a cv-qualifier (`const` or `volatile`) or ref-qualifier (`&`, `&&`). -You can call a static subscript operator by using an object of its class, which allows the object to use subscript syntax. You can also call it by using its qualified name. Taking its address produces a regular function pointer instead of a pointer-to-member function. +You can call a static subscript operator through an object or by using its qualified name. Taking its address produces a regular function pointer instead of a pointer-to-member function. -The feature-test macro `__cpp_static_call_operator` is defined when the static subscript operator is available. +The feature-test macro `__cpp_multidimensional_subscript` has a value of at least `202211L` when the static subscript operator is available. Simply checking whether the macro is defined is insufficient because its earlier value of `202110L` covers multidimensional subscripting but not `static operator[]`: + +```cpp +#if defined(__cpp_multidimensional_subscript) && __cpp_multidimensional_subscript >= 202211L +// static subscript operator is available +#endif +``` ## Example From 3f167b95f4905b1a3b3a0291406f0ef566e09838 Mon Sep 17 00:00:00 2001 From: TylerMSFT <12305055+TylerMSFT@users.noreply.github.com> Date: Wed, 26 Aug 2026 14:32:33 -0700 Subject: [PATCH 6/7] aesethic edits --- docs/cpp/static-function-call-operator.md | 2 +- docs/cpp/static-subscript-operator.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/cpp/static-function-call-operator.md b/docs/cpp/static-function-call-operator.md index e8ad181f34..31e75adc80 100644 --- a/docs/cpp/static-function-call-operator.md +++ b/docs/cpp/static-function-call-operator.md @@ -8,7 +8,7 @@ helpviewer_keywords: ["static function call operator [C++]", "static operator() # Static function call operator (C++) -In C++23, you can declare the function call operator (`operator()`) as a static member function. A static function call operator doesn't have an implicit object parameter. Use it when a callable type doesn't need to access instance data. +In C++23, you can declare the function call operator, `operator()`, as a static member function. A static function call operator doesn't have an implicit object parameter. Use it when a callable type doesn't need to access instance data. Support for this feature was introduced in Visual Studio 2022 version 17.14 (MSVC 14.44). Use the `/std:c++latest` or `/std:c++23preview` compiler option. diff --git a/docs/cpp/static-subscript-operator.md b/docs/cpp/static-subscript-operator.md index 478e97bdb5..3ff8762037 100644 --- a/docs/cpp/static-subscript-operator.md +++ b/docs/cpp/static-subscript-operator.md @@ -8,7 +8,7 @@ helpviewer_keywords: ["static subscript operator [C++]", "static operator[] [C++ # Static subscript operator (C++) -In C++23, you can declare the subscript operator (`operator[]`) as a static member function. A static subscript operator doesn't have an implicit object parameter. Use it when a subscript operation doesn't need to access instance data. +In C++23, you can declare the subscript operator, `operator[]`, as a static member function. A static subscript operator doesn't have an implicit object parameter. Use it when a subscript operation doesn't need to access instance data. Support for this feature was introduced in Visual Studio 2022 version 17.14 (MSVC 14.44). Use the `/std:c++latest` compiler option. From 34b40a4d08e3ee3071b5110f7bd054ac43985813 Mon Sep 17 00:00:00 2001 From: TylerMSFT <12305055+TylerMSFT@users.noreply.github.com> Date: Wed, 26 Aug 2026 14:40:28 -0700 Subject: [PATCH 7/7] clarify example title to hopefully make it easier for search/AI to find it --- docs/cpp/static-function-call-operator.md | 2 +- docs/cpp/static-subscript-operator.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/cpp/static-function-call-operator.md b/docs/cpp/static-function-call-operator.md index 31e75adc80..2d81842a94 100644 --- a/docs/cpp/static-function-call-operator.md +++ b/docs/cpp/static-function-call-operator.md @@ -35,7 +35,7 @@ A lambda expression can specify `static` after its parameter list. When the lamb The feature-test macro `__cpp_static_call_operator` is defined when the static function call operator is available. -## Example +## Static function call operator example The following example defines a stateless function object and calls its static function call operator in three ways. It also defines a static lambda expression and calls it: diff --git a/docs/cpp/static-subscript-operator.md b/docs/cpp/static-subscript-operator.md index 3ff8762037..2498d9490b 100644 --- a/docs/cpp/static-subscript-operator.md +++ b/docs/cpp/static-subscript-operator.md @@ -32,7 +32,7 @@ The feature-test macro `__cpp_multidimensional_subscript` has a value of at leas #endif ``` -## Example +## Static subscript operator example The following example defines a stateless type that calculates powers of two and calls its static subscript operator in three ways: