Path: blob/main/contrib/llvm-project/libcxx/include/__tuple/find_index.h
35233 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___TUPLE_FIND_INDEX_H9#define _LIBCPP___TUPLE_FIND_INDEX_H1011#include <__config>12#include <__type_traits/is_same.h>13#include <cstddef>1415#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)16# pragma GCC system_header17#endif1819#if _LIBCPP_STD_VER >= 142021_LIBCPP_BEGIN_NAMESPACE_STD2223namespace __find_detail {2425static constexpr size_t __not_found = static_cast<size_t>(-1);26static constexpr size_t __ambiguous = __not_found - 1;2728inline _LIBCPP_HIDE_FROM_ABI constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {29return !__matches ? __res : (__res == __not_found ? __curr_i : __ambiguous);30}3132template <size_t _Nx>33inline _LIBCPP_HIDE_FROM_ABI constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {34return __i == _Nx35? __not_found36: __find_detail::__find_idx_return(__i, __find_detail::__find_idx(__i + 1, __matches), __matches[__i]);37}3839template <class _T1, class... _Args>40struct __find_exactly_one_checked {41static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};42static constexpr size_t value = __find_detail::__find_idx(0, __matches);43static_assert(value != __not_found, "type not found in type list");44static_assert(value != __ambiguous, "type occurs more than once in type list");45};4647template <class _T1>48struct __find_exactly_one_checked<_T1> {49static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");50};5152} // namespace __find_detail5354template <typename _T1, typename... _Args>55struct __find_exactly_one_t : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {};5657_LIBCPP_END_NAMESPACE_STD5859#endif // _LIBCPP_STD_VER >= 146061#endif // _LIBCPP___TUPLE_FIND_INDEX_H626364