Namespaces
Variants

std:: divides<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 divides < void > ;
(C++14 起)

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

目录

成员类型

类型 定义
is_transparent 未指定

成员函数

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

std::divides<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_divides = std::divides<void>{}; // “void” 可省略
    constexpr std::complex z1{8.0, 4.0}, z2{1.0, 2.0};
    std::cout << std::showpos
              << complex_divides(z1, z2) << ' ' << z1 / z2 << '\n'
              << complex_divides(z1, 5.) << ' ' << z1 / 5. << '\n'
              << complex_divides(6., z2) << ' ' << 6. / z2 << '\n';
}

输出:

(+3.2,-2.4) (+3.2,-2.4)
(+1.6,+0.8) (+1.6,+0.8)
(+1.2,-2.4) (+1.2,-2.4)