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 { |
23 | int Foo() { return 0; } |
24 | }; |
25 | |
26 | struct noFoo { |
27 | }; |
28 | |
29 | struct wrongFoo { |
30 | std::string Foo() { return "" ; } |
31 | }; |
32 | |
33 | struct convertibleFoo { |
34 | long Foo() { return 0; } |
35 | }; |
36 | |
37 | |
38 | template <typename T, typename Res> |
39 | void test() { |
40 | static_assert( std::is_same<Res, typename ex::detected_t<callFoo, T>>::value, "" ); |
41 | } |
42 | |
43 | int main(int, char**) { |
44 | test<yesFoo, int>(); |
45 | test<noFoo, ex::nonesuch>(); // lookup failure returns nonesuch |
46 | test<wrongFoo, std::string>(); |
47 | |
48 | return 0; |
49 | } |
50 | |