If a class has only one member function enabled with require, can it be ambiguously overloaded?

For example, is this code really?

template <class T>
struct A {
  void f() 
    requires std::is_same_v<T, int>
  {
  }

  void f(int) 
    requires !std::is_same_v<T, int>
  {
  }
};

int main() {
  auto fptr = &A<int>::f;
  return 0;
}

This will not compile with gcc, but it looks like it should work with me.

+4
source share
2 answers

If a class has only one member function enabled through requires, is it still considered overloaded?

Yes.

[C++ Concepts TS: 13/1]: , . , , , (14.10.2), . ; .

:

[C++ Concepts TS: 13.3.2/1]: -, (13.3.1), , (13.3.3). , (14.10.2), , .


, ?

, , f:

[C++ Concepts TS: 13.4/4]: , [..]

, .

: N4377 2015-02-09

+5

, :

prog.cc: In function 'int main()':
prog.cc:18:40: error: conversion from '<unresolved overloaded function 
 type>' to non-scalar type 'std::function<void()>' requested
   std::function<void()> fptr = A<int>::f;

A::f : , .

-1

Source: https://habr.com/ru/post/1676418/


All Articles