brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · dd83f22 Raw
86 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_same12 13#include <type_traits>14 15#include "test_macros.h"16 17template <class T, class U>18void test_is_same()19{20    static_assert(( std::is_same<T, U>::value), "");21    static_assert((!std::is_same<const T, U>::value), "");22    static_assert((!std::is_same<T, const U>::value), "");23    static_assert(( std::is_same<const T, const U>::value), "");24#if TEST_STD_VER > 1425    static_assert(( std::is_same_v<T, U>), "");26    static_assert((!std::is_same_v<const T, U>), "");27    static_assert((!std::is_same_v<T, const U>), "");28    static_assert(( std::is_same_v<const T, const U>), "");29#endif30}31 32template <class T, class U>33void test_is_same_ref()34{35    static_assert((std::is_same<T, U>::value), "");36    static_assert((std::is_same<const T, U>::value), "");37    static_assert((std::is_same<T, const U>::value), "");38    static_assert((std::is_same<const T, const U>::value), "");39#if TEST_STD_VER > 1440    static_assert((std::is_same_v<T, U>), "");41    static_assert((std::is_same_v<const T, U>), "");42    static_assert((std::is_same_v<T, const U>), "");43    static_assert((std::is_same_v<const T, const U>), "");44#endif45}46 47template <class T, class U>48void test_is_not_same()49{50    static_assert((!std::is_same<T, U>::value), "");51}52 53template <class T>54struct OverloadTest55{56    void fn(std::is_same<T, int>) { }57    void fn(std::false_type) { }58    void x() { fn(std::false_type()); }59};60 61class Class62{63public:64    ~Class();65};66 67int main(int, char**)68{69    test_is_same<int, int>();70    test_is_same<void, void>();71    test_is_same<Class, Class>();72    test_is_same<int*, int*>();73    test_is_same_ref<int&, int&>();74 75    test_is_not_same<int, void>();76    test_is_not_same<void, Class>();77    test_is_not_same<Class, int*>();78    test_is_not_same<int*, int&>();79    test_is_not_same<int&, int>();80 81    OverloadTest<char> t;82    (void)t;83 84  return 0;85}86