GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::equivalence_relation - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. concepts
  3. equivalence_relation

最終更新日時: 2026年09月19日 21時31分51秒 (JST)
rotarymars が更新

履歴 編集

concept
<concepts>

std::equivalence_relation(C++20)

namespace std {
  template<class R, class T, class U>
  concept equivalence_relation = relation<R, T, U>;
}

概要

equivalence_relationは、型T, Uの間の二項関係Rが同値関係であることを表すコンセプトである。

モデル

relationのモデルである二項関係Rは、その引数型T, Uの間の同値関係を示す場合に限って、equivalence_relationのモデルである。

例

#include <iostream>
#include <concepts>

template<typename R, typename T, typename U>
requires std::equivalence_relation<R, T, U>
void f(const char* name, const char* tname, const char* uname) {
  std::cout << name << " is equivalence relation between " << tname << " and " << uname << std::endl;
}

template<typename R, typename T, typename U>
void f(const char* name, const char* tname, const char* uname) {
  std::cout << name << " is not equivalence relation between " << tname << " and " << uname << std::endl;
}


struct S1 {
  int n = 0;
};

struct S2 {
  short m = 0;
};

// S1とS2の間の同値関係
struct equivalence_relation_s1s2 {

  bool operator()(S1 lhs, S1 rhs) const {
    return lhs.n == rhs.n;
  }

  bool operator()(S2 lhs, S2 rhs ) const {
    return lhs.m == rhs.m;
  }

  bool operator()(S1 lhs, S2 rhs) const {
    return lhs.n == rhs.m;
  }

  bool operator()(S2 lhs, S1 rhs) const {
    return lhs.m == rhs.n;
  }
};

int main() {
  f<equivalence_relation_s1s2, S1, S2>("equivalence_relation_s1s2", "S1", "S2");
  f<equivalence_relation_s1s2, S2, S1>("equivalence_relation_s1s2", "S2", "S1");
}

出力

equivalence_relation_s1s2 is equivalence relation between S1 and S2
equivalence_relation_s1s2 is equivalence relation between S2 and S1

バージョン

言語

  • C++20

処理系

  • Clang: 13.0.1 ✅
  • GCC: 10.1 ✅
  • Visual C++: 2019 Update 3 ✅

関連項目

  • C++20 コンセプト

参照

  • P0898R3 Standard Library Concepts
  • P1754R1 Rename concepts to standard_case for C++20, while we still can
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.