40 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 copy_assign_t = decltype(std::declval<T&>() = std::declval<T const &>());22 23struct not_assignable {24 not_assignable & operator=(const not_assignable&) = delete;25};26 27template <typename T, bool b>28void test() {29 static_assert( b == ex::is_detected <copy_assign_t, T>::value, "" );30 static_assert( b == ex::is_detected_v<copy_assign_t, T>, "" );31}32 33int main(int, char**) {34 test<int, true>();35 test<std::string, true>();36 test<not_assignable, false>();37 38 return 0;39}40