15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier
95a83710eSEric Fiselier // type_traits
105a83710eSEric Fiselier
115a83710eSEric Fiselier // is_same
125a83710eSEric Fiselier
135a83710eSEric Fiselier #include <type_traits>
145a83710eSEric Fiselier
15e12a536dSMarshall Clow #include "test_macros.h"
16e12a536dSMarshall Clow
175a83710eSEric Fiselier template <class T, class U>
test_is_same()185a83710eSEric Fiselier void test_is_same()
195a83710eSEric Fiselier {
205a83710eSEric Fiselier static_assert(( std::is_same<T, U>::value), "");
215a83710eSEric Fiselier static_assert((!std::is_same<const T, U>::value), "");
225a83710eSEric Fiselier static_assert((!std::is_same<T, const U>::value), "");
235a83710eSEric Fiselier static_assert(( std::is_same<const T, const U>::value), "");
24803a8bb1SMarshall Clow #if TEST_STD_VER > 14
25e12a536dSMarshall Clow static_assert(( std::is_same_v<T, U>), "");
26e12a536dSMarshall Clow static_assert((!std::is_same_v<const T, U>), "");
27e12a536dSMarshall Clow static_assert((!std::is_same_v<T, const U>), "");
28e12a536dSMarshall Clow static_assert(( std::is_same_v<const T, const U>), "");
29e12a536dSMarshall Clow #endif
305a83710eSEric Fiselier }
315a83710eSEric Fiselier
325a83710eSEric Fiselier template <class T, class U>
test_is_same_ref()335a83710eSEric Fiselier void test_is_same_ref()
345a83710eSEric Fiselier {
355a83710eSEric Fiselier static_assert((std::is_same<T, U>::value), "");
365a83710eSEric Fiselier static_assert((std::is_same<const T, U>::value), "");
375a83710eSEric Fiselier static_assert((std::is_same<T, const U>::value), "");
385a83710eSEric Fiselier static_assert((std::is_same<const T, const U>::value), "");
39803a8bb1SMarshall Clow #if TEST_STD_VER > 14
40e12a536dSMarshall Clow static_assert((std::is_same_v<T, U>), "");
41e12a536dSMarshall Clow static_assert((std::is_same_v<const T, U>), "");
42e12a536dSMarshall Clow static_assert((std::is_same_v<T, const U>), "");
43e12a536dSMarshall Clow static_assert((std::is_same_v<const T, const U>), "");
44e12a536dSMarshall Clow #endif
455a83710eSEric Fiselier }
465a83710eSEric Fiselier
475a83710eSEric Fiselier template <class T, class U>
test_is_not_same()485a83710eSEric Fiselier void test_is_not_same()
495a83710eSEric Fiselier {
505a83710eSEric Fiselier static_assert((!std::is_same<T, U>::value), "");
515a83710eSEric Fiselier }
525a83710eSEric Fiselier
53*5ade17e0Szoecarver template <class T>
54*5ade17e0Szoecarver struct OverloadTest
55*5ade17e0Szoecarver {
fnOverloadTest56*5ade17e0Szoecarver void fn(std::is_same<T, int>) { }
fnOverloadTest57*5ade17e0Szoecarver void fn(std::false_type) { }
xOverloadTest58*5ade17e0Szoecarver void x() { fn(std::false_type()); }
59*5ade17e0Szoecarver };
60*5ade17e0Szoecarver
615a83710eSEric Fiselier class Class
625a83710eSEric Fiselier {
635a83710eSEric Fiselier public:
645a83710eSEric Fiselier ~Class();
655a83710eSEric Fiselier };
665a83710eSEric Fiselier
main(int,char **)672df59c50SJF Bastien int main(int, char**)
685a83710eSEric Fiselier {
695a83710eSEric Fiselier test_is_same<int, int>();
705a83710eSEric Fiselier test_is_same<void, void>();
715a83710eSEric Fiselier test_is_same<Class, Class>();
725a83710eSEric Fiselier test_is_same<int*, int*>();
735a83710eSEric Fiselier test_is_same_ref<int&, int&>();
745a83710eSEric Fiselier
755a83710eSEric Fiselier test_is_not_same<int, void>();
765a83710eSEric Fiselier test_is_not_same<void, Class>();
775a83710eSEric Fiselier test_is_not_same<Class, int*>();
785a83710eSEric Fiselier test_is_not_same<int*, int&>();
795a83710eSEric Fiselier test_is_not_same<int&, int>();
802df59c50SJF Bastien
81*5ade17e0Szoecarver OverloadTest<char> t;
82*5ade17e0Szoecarver (void)t;
83*5ade17e0Szoecarver
842df59c50SJF Bastien return 0;
855a83710eSEric Fiselier }
86