Skip to content

Commit a77840a

Browse files
Learn Build Service GitHub AppLearn Build Service GitHub App
authored andcommitted
Merging changes synced from https://github.com/MicrosoftDocs/cpp-docs-pr (branch live)
2 parents 9b9329f + 13411e1 commit a77840a

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

docs/cpp/static-function-call-operator.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
22
description: "Learn how to declare and use the static function call operator in C++."
3-
title: "Static function call operator (C++)"
4-
ms.date: 08/19/2026
3+
title: "Static function call operator (C++23)"
4+
ms.date: 08/26/2026
55
ai-usage: ai-assisted
66
helpviewer_keywords: ["static function call operator [C++]", "static operator() [C++]", "operator overloading [C++]"]
77
---
88

99
# Static function call operator (C++)
1010

11-
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.
11+
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.
1212

13-
Support for this feature was introduced in Visual Studio 2022 version 17.14 (MSVC 14.44). Use the `/std:c++latest` compiler option.
13+
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.
1414

1515
## Syntax
1616

@@ -22,6 +22,7 @@ You can also declare the function call operator generated for a lambda expressio
2222
2323
```cpp
2424
[](parameter-list) static { function-body }
25+
[] static { function-body }
2526
```
2627

2728
## Remarks
@@ -30,13 +31,13 @@ A static function call operator doesn't have a `this` pointer. It can't be `virt
3031

3132
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.
3233

33-
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.
34+
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.
3435

3536
The feature-test macro `__cpp_static_call_operator` is defined when the static function call operator is available.
3637

37-
## Example
38+
## Static function call operator example
3839

39-
The following example defines a stateless function object and calls its static function call operator in three ways:
40+
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:
4041

4142
```cpp
4243
// Compile with: /std:c++latest
@@ -63,6 +64,7 @@ int main()
6364
std::cout << "multiply_function(5, 5) = "
6465
<< multiply_function(5, 5) << std::endl;
6566

67+
// A static lambda expression that doubles its argument
6668
auto twice = [](int value) static noexcept
6769
{
6870
return value * 2;

docs/cpp/static-subscript-operator.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
description: "Learn how to declare and use the static subscript operator in C++."
33
title: "Static subscript operator (C++)"
4-
ms.date: 08/19/2026
4+
ms.date: 08/26/2026
55
ai-usage: ai-assisted
66
helpviewer_keywords: ["static subscript operator [C++]", "static operator[] [C++]", "operator overloading [C++]"]
77
---
88

99
# Static subscript operator (C++)
1010

11-
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.
11+
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.
1212

1313
Support for this feature was introduced in Visual Studio 2022 version 17.14 (MSVC 14.44). Use the `/std:c++latest` compiler option.
1414

@@ -22,11 +22,17 @@ static return-type operator[](parameter-list);
2222

2323
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 (`&`, `&&`).
2424

25-
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.
25+
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.
2626

27-
The feature-test macro `__cpp_static_call_operator` is defined when the static subscript operator is available.
27+
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[]`:
2828

29-
## Example
29+
```cpp
30+
#if defined(__cpp_multidimensional_subscript) && __cpp_multidimensional_subscript >= 202211L
31+
// static subscript operator is available
32+
#endif
33+
```
34+
35+
## Static subscript operator example
3036

3137
The following example defines a stateless type that calculates powers of two and calls its static subscript operator in three ways:
3238

docs/cpp/subscripting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.assetid: eb151281-6733-401d-9787-39ab6754c62c
77
---
88
# Subscripting
99

10-
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).
10+
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).
1111

1212
The argument can be any type and designates the desired array subscript.
1313

0 commit comments

Comments
 (0)