• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++98, c++03, c++11
11 // <experimental/type_traits>
12 
13 #include <experimental/type_traits>
14 #include <string>
15 
16 #include "test_macros.h"
17 
18 namespace ex = std::experimental;
19 
20 template <typename T>
21   using callFoo = decltype(std::declval<T&>().Foo());
22 
23 struct yesFoo {
FooyesFoo24     int Foo() { return 0; }
25 };
26 
27 struct noFoo {
28 };
29 
30 struct wrongFoo {
FoowrongFoo31     std::string Foo() { return ""; }
32 };
33 
34 struct convertibleFoo {
FooconvertibleFoo35     long Foo() { return 0; }
36 };
37 
38 
39 template <typename T, typename Res>
test()40 void test() {
41     static_assert( std::is_same<Res, typename ex::detected_t<callFoo, T>>::value, "" );
42 }
43 
main()44 int main () {
45     test<yesFoo, int>();
46     test<noFoo, ex::nonesuch>();  // lookup failure returns nonesuch
47     test<wrongFoo, std::string>();
48 }
49