1 //===-- sanitizer_type_traits.h ---------------------------------*- C++ -*-===// 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Implements a subset of C++ type traits. This is so we can avoid depending 10 // on system C++ headers. 11 // 12 //===----------------------------------------------------------------------===// 13 #ifndef SANITIZER_TYPE_TRAITS_H 14 #define SANITIZER_TYPE_TRAITS_H 15 16 namespace __sanitizer { 17 18 struct true_type { 19 static const bool value = true; 20 }; 21 22 struct false_type { 23 static const bool value = false; 24 }; 25 26 // is_same<T, U> 27 // 28 // Type trait to compare if types are the same. 29 // E.g. 30 // 31 // ``` 32 // is_same<int,int>::value - True 33 // is_same<int,char>::value - False 34 // ``` 35 template <typename T, typename U> 36 struct is_same : public false_type {}; 37 38 template <typename T> 39 struct is_same<T, T> : public true_type {}; 40 41 // conditional<B, T, F> 42 // 43 // Defines type as T if B is true or as F otherwise. 44 // E.g. the following is true 45 // 46 // ``` 47 // is_same<int, conditional<true, int, double>::type>::value 48 // is_same<double, conditional<false, int, double>::type>::value 49 // ``` 50 template <bool B, class T, class F> 51 struct conditional { 52 using type = T; 53 }; 54 55 template <class T, class F> 56 struct conditional<false, T, F> { 57 using type = F; 58 }; 59 60 } // namespace __sanitizer 61 62 #endif 63