Path: blob/main/contrib/llvm-project/libcxx/include/__cxx03/__functional/operations.h
213799 views
// -*- C++ -*-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-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___CXX03___FUNCTIONAL_OPERATIONS_H10#define _LIBCPP___CXX03___FUNCTIONAL_OPERATIONS_H1112#include <__cxx03/__config>13#include <__cxx03/__functional/binary_function.h>14#include <__cxx03/__functional/unary_function.h>15#include <__cxx03/__type_traits/desugars_to.h>16#include <__cxx03/__utility/forward.h>1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)19# pragma GCC system_header20#endif2122_LIBCPP_BEGIN_NAMESPACE_STD2324// Arithmetic operations2526template <class _Tp>27struct _LIBCPP_TEMPLATE_VIS plus : __binary_function<_Tp, _Tp, _Tp> {28typedef _Tp __result_type; // used by valarray29_LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }30};31_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus);3233// The non-transparent std::plus specialization is only equivalent to a raw plus34// operator when we don't perform an implicit conversion when calling it.35template <class _Tp>36inline const bool __desugars_to_v<__plus_tag, plus<_Tp>, _Tp, _Tp> = true;3738template <class _Tp, class _Up>39inline const bool __desugars_to_v<__plus_tag, plus<void>, _Tp, _Up> = true;4041template <class _Tp>42struct _LIBCPP_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp> {43typedef _Tp __result_type; // used by valarray44_LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }45};46_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(minus);4748template <class _Tp>49struct _LIBCPP_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp> {50typedef _Tp __result_type; // used by valarray51_LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }52};53_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(multiplies);5455template <class _Tp>56struct _LIBCPP_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp> {57typedef _Tp __result_type; // used by valarray58_LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }59};60_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(divides);6162template <class _Tp>63struct _LIBCPP_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp> {64typedef _Tp __result_type; // used by valarray65_LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }66};67_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(modulus);6869template <class _Tp = void>70struct _LIBCPP_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp> {71typedef _Tp __result_type; // used by valarray72_LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return -__x; }73};74_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(negate);7576// Bitwise operations7778template <class _Tp>79struct _LIBCPP_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp> {80typedef _Tp __result_type; // used by valarray81_LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x & __y; }82};83_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_and);8485template <class _Tp>86struct _LIBCPP_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp> {87typedef _Tp __result_type; // used by valarray88_LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x | __y; }89};90_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_or);9192template <class _Tp = void>93struct _LIBCPP_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp> {94typedef _Tp __result_type; // used by valarray95_LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x ^ __y; }96};97_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_xor);9899// Comparison operations100101template <class _Tp>102struct _LIBCPP_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool> {103typedef bool __result_type; // used by valarray104_LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }105};106_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(equal_to);107108// The non-transparent std::equal_to specialization is only equivalent to a raw equality109// comparison when we don't perform an implicit conversion when calling it.110template <class _Tp>111inline const bool __desugars_to_v<__equal_tag, equal_to<_Tp>, _Tp, _Tp> = true;112113// In the transparent case, we do not enforce that114template <class _Tp, class _Up>115inline const bool __desugars_to_v<__equal_tag, equal_to<void>, _Tp, _Up> = true;116117template <class _Tp>118struct _LIBCPP_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool> {119typedef bool __result_type; // used by valarray120_LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }121};122_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(not_equal_to);123124template <class _Tp>125struct _LIBCPP_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool> {126typedef bool __result_type; // used by valarray127_LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }128};129_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less);130131template <class _Tp>132inline const bool __desugars_to_v<__less_tag, less<_Tp>, _Tp, _Tp> = true;133134template <class _Tp>135struct _LIBCPP_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool> {136typedef bool __result_type; // used by valarray137_LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }138};139_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less_equal);140141template <class _Tp>142struct _LIBCPP_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool> {143typedef bool __result_type; // used by valarray144_LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }145};146_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater_equal);147148template <class _Tp>149struct _LIBCPP_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool> {150typedef bool __result_type; // used by valarray151_LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }152};153_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater);154155// Logical operations156157template <class _Tp>158struct _LIBCPP_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool> {159typedef bool __result_type; // used by valarray160_LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }161};162_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_and);163164template <class _Tp>165struct _LIBCPP_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool> {166typedef bool __result_type; // used by valarray167_LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x) const { return !__x; }168};169_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_not);170171template <class _Tp>172struct _LIBCPP_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool> {173typedef bool __result_type; // used by valarray174_LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }175};176_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_or);177178_LIBCPP_END_NAMESPACE_STD179180#endif // _LIBCPP___CXX03___FUNCTIONAL_OPERATIONS_H181182183