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_CAN_EXTRACT_KEY_H 10#define _LIBCPP___TYPE_TRAITS_CAN_EXTRACT_KEY_H 11 12#include <__config> 13#include <__fwd/pair.h> 14#include <__type_traits/conditional.h> 15#include <__type_traits/integral_constant.h> 16#include <__type_traits/is_same.h> 17#include <__type_traits/remove_const.h> 18#include <__type_traits/remove_const_ref.h> 19 20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 21# pragma GCC system_header 22#endif 23 24_LIBCPP_BEGIN_NAMESPACE_STD 25 26// These traits are used in __tree and __hash_table 27struct __extract_key_fail_tag {}; 28struct __extract_key_self_tag {}; 29struct __extract_key_first_tag {}; 30 31template <class _ValTy, class _Key, class _RawValTy = __remove_const_ref_t<_ValTy> > 32struct __can_extract_key 33 : __conditional_t<_IsSame<_RawValTy, _Key>::value, __extract_key_self_tag, __extract_key_fail_tag> {}; 34 35template <class _Pair, class _Key, class _First, class _Second> 36struct __can_extract_key<_Pair, _Key, pair<_First, _Second> > 37 : __conditional_t<_IsSame<__remove_const_t<_First>, _Key>::value, __extract_key_first_tag, __extract_key_fail_tag> { 38}; 39 40// __can_extract_map_key uses true_type/false_type instead of the tags. 41// It returns true if _Key != _ContainerValueTy (the container is a map not a set) 42// and _ValTy == _Key. 43template <class _ValTy, class _Key, class _ContainerValueTy, 44 class _RawValTy = __remove_const_ref_t<_ValTy> > 45struct __can_extract_map_key 46 : integral_constant<bool, _IsSame<_RawValTy, _Key>::value> {}; 47 48// This specialization returns __extract_key_fail_tag for non-map containers 49// because _Key == _ContainerValueTy 50template <class _ValTy, class _Key, class _RawValTy> 51struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy> 52 : false_type {}; 53 54_LIBCPP_END_NAMESPACE_STD 55 56#endif // _LIBCPP___TYPE_TRAITS_CAN_EXTRACT_KEY_H 57