1343175Sdim//===-- sanitizer_type_traits.h ---------------------------------*- C++ -*-===//
2343175Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6343175Sdim//
7343175Sdim//===----------------------------------------------------------------------===//
8343175Sdim//
9343175Sdim// Implements a subset of C++ type traits. This is so we can avoid depending
10343175Sdim// on system C++ headers.
11343175Sdim//
12343175Sdim//===----------------------------------------------------------------------===//
13343175Sdim#ifndef SANITIZER_TYPE_TRAITS_H
14343175Sdim#define SANITIZER_TYPE_TRAITS_H
15343175Sdim
16343175Sdimnamespace __sanitizer {
17343175Sdim
18343175Sdimstruct true_type {
19343175Sdim  static const bool value = true;
20343175Sdim};
21343175Sdim
22343175Sdimstruct false_type {
23343175Sdim  static const bool value = false;
24343175Sdim};
25343175Sdim
26343175Sdim// is_same<T, U>
27343175Sdim//
28343175Sdim// Type trait to compare if types are the same.
29343175Sdim// E.g.
30343175Sdim//
31343175Sdim// ```
32343175Sdim// is_same<int,int>::value - True
33343175Sdim// is_same<int,char>::value - False
34343175Sdim// ```
35343175Sdimtemplate <typename T, typename U>
36343175Sdimstruct is_same : public false_type {};
37343175Sdim
38343175Sdimtemplate <typename T>
39343175Sdimstruct is_same<T, T> : public true_type {};
40343175Sdim
41353358Sdim// conditional<B, T, F>
42353358Sdim//
43353358Sdim// Defines type as T if B is true or as F otherwise.
44353358Sdim// E.g. the following is true
45353358Sdim//
46353358Sdim// ```
47353358Sdim// is_same<int, conditional<true, int, double>::type>::value
48353358Sdim// is_same<double, conditional<false, int, double>::type>::value
49353358Sdim// ```
50353358Sdimtemplate <bool B, class T, class F>
51353358Sdimstruct conditional {
52353358Sdim  using type = T;
53353358Sdim};
54353358Sdim
55353358Sdimtemplate <class T, class F>
56353358Sdimstruct conditional<false, T, F> {
57353358Sdim  using type = F;
58353358Sdim};
59353358Sdim
60343175Sdim}  // namespace __sanitizer
61343175Sdim
62343175Sdim#endif
63