Namespaces
Variants

std:: minus<void>

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
定义于头文件 <functional>
template <>
class minus < void > ;
(C++14 起)

std:: minus < void > std::minus 的特化版本,其参数和返回类型由编译器自动推导。

目录

成员类型

类型 定义
is_transparent 未指定

成员函数

operator()
返回两个参数的差值
(公开成员函数)

std::minus<void>:: operator()

template < class T, class U >

constexpr auto operator ( ) ( T && lhs, U && rhs ) const

- > decltype ( std:: forward < T > ( lhs ) - std:: forward < U > ( rhs ) ) ;

返回 lhs rhs 的差值。

参数

lhs, rhs - 待相减的值

返回值

std:: forward < T > ( lhs ) - std:: forward < U > ( rhs )

示例

#include <complex>
#include <functional>
#include <iostream>
int main()
{
    auto complex_minus = std::minus<void>{}; // “void”可省略
    constexpr std::complex<int> z(4, 2);
    std::cout << complex_minus(z, 1) << '\n';
    std::cout << (z - 1) << '\n';
}

输出:

(3,2)
(3,2)