view gcc/testsuite/g++.dg/concepts/fn9.C @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
line wrap: on
line source

// { dg-do run }
// { dg-options "-std=c++17 -fconcepts" }

#include <cassert>

template<typename T>
  concept bool Class() { return __is_class(T); }

template<typename T>
  concept bool Empty() { return Class<T>() and __is_empty(T); }

template<Class T> int f(T) { return 1; }
template<Empty T> int f(T) { return 2; }

struct S {
  template<Class T> int f(T) { return 1; }
  template<Empty T> int f(T) { return 2; }
} s;

struct X { } x;
struct Y { X x; } y;

int main () {
  auto p1 = &f<X>; // Empty f
  assert(p1(x) == 2);

  auto p2 = &f<Y>; // Class f
  assert(p2(y) == 1);

  auto p3 = &S::template f<X>; // Empty f
  assert((s.*p3)(x) == 2);

  auto p4 = &S::template f<Y>; // Empty f
  assert((s.*p4)(y) == 1);
}