Skip to content

CWG 2518の影響調査 #1257

Closed
Closed
@yumetodo

Description

@yumetodo

static_assert(false, "was wrong"); - yohhoyの日記

#include <type_traits>

template <typename T>
T doubling(T x)
{
  if constexpr (std::is_integral_v<T> || std::is_floating_point_v<T>) {
    // 算術型の場合は2倍した値を返す
    return x * T{2};
  } else {
    // それ以外の型はコンパイルエラー
    static_assert(false);  // NG(CWG 2518適用前)
    // CWG 2518適用後は上記記述でOK
  }
}

constexpr if文に影響ありそう

https://twitter.com/yohhoy/status/1759832908834238510
en.cppreference.com/w/cpp/language… ではC++11まで遡及適用していますね。issueくらい作っておいた方がよさげ。

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions