Path: blob/main/contrib/llvm-project/libcxx/include/__algorithm/half_positive.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___ALGORITHM_HALF_POSITIVE_H9#define _LIBCPP___ALGORITHM_HALF_POSITIVE_H1011#include <__config>12#include <__type_traits/enable_if.h>13#include <__type_traits/is_integral.h>14#include <__type_traits/make_unsigned.h>1516#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17# pragma GCC system_header18#endif1920_LIBCPP_BEGIN_NAMESPACE_STD2122// Perform division by two quickly for positive integers (llvm.org/PR39129)2324template <typename _Integral, __enable_if_t<is_integral<_Integral>::value, int> = 0>25_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Integral __half_positive(_Integral __value) {26return static_cast<_Integral>(static_cast<__make_unsigned_t<_Integral> >(__value) / 2);27}2829template <typename _Tp, __enable_if_t<!is_integral<_Tp>::value, int> = 0>30_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp __half_positive(_Tp __value) {31return __value / 2;32}3334_LIBCPP_END_NAMESPACE_STD3536#endif // _LIBCPP___ALGORITHM_HALF_POSITIVE_H373839