Skip to content

Commit

Permalink
関数引数や戻り値型として非const参照が使えるようになったことを明示
Browse files Browse the repository at this point in the history
  • Loading branch information
wx257osn2 committed Jan 4, 2023
1 parent 384970b commit 79d9ed9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lang/cpp14/relaxing_constraints_on_constexpr.md
Expand Up @@ -10,7 +10,7 @@ C++11で、汎用定数式の機能である[`constexpr`](/lang/cpp11/constexpr.
- `if`文と`switch`文を許可
- 全てのループ文を許可(`for`文、範囲`for`文、`while`文、`do-while`文)
- 変数の書き換えを許可
- 戻り値型(リテラル型)として、`void`を許可
- 戻り値型(リテラル型)として、`void`を許可 / 戻り値型や関数引数で非`const`参照を許可
- `constexpr`非静的メンバ関数の、暗黙の`const`修飾を削除


Expand Down Expand Up @@ -137,11 +137,13 @@ constexpr int square(int n)
```


### `constexpr`関数の戻り値型として、`void`を許可
### `constexpr`関数の戻り値型として、`void`を許可 / 戻り値型や関数引数で非`const`参照を許可
`constexpr`関数での、パラメータの型、および戻り値の型は、[リテラル型](/reference/type_traits/is_literal_type.md)に分類される型に限定される。

C++14では、[リテラル型](/reference/type_traits/is_literal_type.md)に分類される型に、`void`が追加された。

また、戻り値型や関数引数で非`const`参照を使うことが許可された。

これにより、`constexpr`関数の戻り値型を`void`とし、非`const`参照のパラメータを書き換えて結果を返す、という操作が許可された。

```cpp
Expand Down

0 comments on commit 79d9ed9

Please sign in to comment.