85 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// type_traits10 11// is_assignable12 13#include <type_traits>14#include "test_macros.h"15 16struct A17{18};19 20struct B21{22 void operator=(A);23};24 25template <class T, class U>26void test_is_assignable()27{28 static_assert(( std::is_assignable<T, U>::value), "");29#if TEST_STD_VER > 1430 static_assert( std::is_assignable_v<T, U>, "");31#endif32}33 34template <class T, class U>35void test_is_not_assignable()36{37 static_assert((!std::is_assignable<T, U>::value), "");38#if TEST_STD_VER > 1439 static_assert( !std::is_assignable_v<T, U>, "");40#endif41}42 43struct D;44 45#if TEST_STD_VER >= 1146struct C47{48 template <class U>49 D operator,(U&&);50};51 52struct E53{54 C operator=(int);55};56#endif57 58template <typename T>59struct X { T t; };60 61int main(int, char**)62{63 test_is_assignable<int&, int&> ();64 test_is_assignable<int&, int> ();65 test_is_assignable<int&, double> ();66 test_is_assignable<B, A> ();67 test_is_assignable<void*&, void*> ();68 69#if TEST_STD_VER >= 1170 test_is_assignable<E, int> ();71 72 test_is_not_assignable<int, int&> ();73 test_is_not_assignable<int, int> ();74#endif75 test_is_not_assignable<A, B> ();76 test_is_not_assignable<void, const void> ();77 test_is_not_assignable<const void, const void> ();78 test_is_not_assignable<int(), int> ();79 80// pointer to incomplete template type81 test_is_assignable<X<D>*&, X<D>*> ();82 83 return 0;84}85