]> git.ipfire.org Git - thirdparty/gcc.git/blame - libsanitizer/sanitizer_common/sanitizer_type_traits.h
Correct a function pre/postcondition [PR102403].
[thirdparty/gcc.git] / libsanitizer / sanitizer_common / sanitizer_type_traits.h
CommitLineData
b667dd70
ML
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
16namespace __sanitizer {
17
18struct true_type {
19 static const bool value = true;
20};
21
22struct 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// ```
35template <typename T, typename U>
36struct is_same : public false_type {};
37
38template <typename T>
39struct 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// ```
50template <bool B, class T, class F>
51struct conditional {
52 using type = T;
53};
54
55template <class T, class F>
56struct conditional<false, T, F> {
57 using type = F;
58};
59
60} // namespace __sanitizer
61
62#endif