51 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++1110// <experimental/type_traits>11 12#include <experimental/type_traits>13#include <string>14#include <utility>15 16#include "test_macros.h"17 18namespace ex = std::experimental;19 20template <typename T>21 using callFoo = decltype(std::declval<T&>().Foo());22 23struct yesFoo {24 int Foo() { return 0; }25};26 27struct noFoo {28};29 30struct wrongFoo {31 std::string Foo() { return ""; }32};33 34struct convertibleFoo {35 long Foo() { return 0; }36};37 38 39template <typename T, typename Res>40void test() {41 static_assert( std::is_same<Res, typename ex::detected_t<callFoo, T>>::value, "" );42}43 44int main(int, char**) {45 test<yesFoo, int>();46 test<noFoo, ex::nonesuch>(); // lookup failure returns nonesuch47 test<wrongFoo, std::string>();48 49 return 0;50}51