xref: /llvm-project/libcxx/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp (revision 31cbe0f240f660f15602c96b787c58a26f17e179)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11
10 // <experimental/type_traits>
11 
12 #include <experimental/type_traits>
13 #include <string>
14 
15 #include "test_macros.h"
16 
17 namespace ex = std::experimental;
18 
19 template <typename T>
20   using callFoo = decltype(std::declval<T&>().Foo());
21 
22 struct yesFoo {
FooyesFoo23     int Foo() { return 0; }
24 };
25 
26 struct noFoo {
27 };
28 
29 struct wrongFoo {
FoowrongFoo30     std::string Foo() { return ""; }
31 };
32 
33 struct convertibleFoo {
FooconvertibleFoo34     long Foo() { return 0; }
35 };
36 
37 template <typename T, bool b>
test()38 void test() {
39     static_assert( b == ex::is_detected_exact  <int, callFoo, T>::value, "" );
40     static_assert( b == ex::is_detected_exact_v<int, callFoo, T>, "" );
41 }
42 
main(int,char **)43 int main(int, char**) {
44     test<yesFoo, true>();
45     test<noFoo, false>();
46     test<wrongFoo, false>();
47     test<convertibleFoo, false>();
48 
49   return 0;
50 }
51