| 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-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#ifndef _LIBCPP___TYPE_TRAITS_CONDITIONAL_H |
| 10 |
#define _LIBCPP___TYPE_TRAITS_CONDITIONAL_H |
| 11 |
|
| 12 |
#include <__config> |
| 13 |
|
| 14 |
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 15 |
# pragma GCC system_header |
| 16 |
#endif |
| 17 |
|
| 18 |
_LIBCPP_BEGIN_NAMESPACE_STD |
| 19 |
|
| 20 |
template <bool> |
| 21 |
struct _IfImpl; |
| 22 |
|
| 23 |
template <> |
| 24 |
struct _IfImpl<true> { |
| 25 |
template <class _IfRes, class _ElseRes> |
| 26 |
using _Select _LIBCPP_NODEBUG = _IfRes; |
| 27 |
}; |
| 28 |
|
| 29 |
template <> |
| 30 |
struct _IfImpl<false> { |
| 31 |
template <class _IfRes, class _ElseRes> |
| 32 |
using _Select _LIBCPP_NODEBUG = _ElseRes; |
| 33 |
}; |
| 34 |
|
| 35 |
template <bool _Cond, class _IfRes, class _ElseRes> |
| 36 |
using _If _LIBCPP_NODEBUG = typename _IfImpl<_Cond>::template _Select<_IfRes, _ElseRes>; |
| 37 |
|
| 38 |
template <bool _Bp, class _If, class _Then> |
| 39 |
struct _LIBCPP_TEMPLATE_VIS conditional { |
| 40 |
using type _LIBCPP_NODEBUG = _If; |
| 41 |
}; |
| 42 |
template <class _If, class _Then> |
| 43 |
struct _LIBCPP_TEMPLATE_VIS conditional<false, _If, _Then> { |
| 44 |
using type _LIBCPP_NODEBUG = _Then; |
| 45 |
}; |
| 46 |
|
| 47 |
#if _LIBCPP_STD_VER >= 14 |
| 48 |
template <bool _Bp, class _IfRes, class _ElseRes> |
| 49 |
using conditional_t _LIBCPP_NODEBUG = typename conditional<_Bp, _IfRes, _ElseRes>::type; |
| 50 |
#endif |
| 51 |
|
| 52 |
// Helper so we can use "conditional_t" in all language versions. |
| 53 |
template <bool _Bp, class _If, class _Then> |
| 54 |
using __conditional_t _LIBCPP_NODEBUG = typename conditional<_Bp, _If, _Then>::type; |
| 55 |
|
| 56 |
_LIBCPP_END_NAMESPACE_STD |
| 57 |
|
| 58 |
#endif // _LIBCPP___TYPE_TRAITS_CONDITIONAL_H |