C++ 函式庫 - plus



描述

這是一個加法函式物件類和二元函式物件類,其呼叫返回其兩個引數相加的結果(如 operator + 返回的結果)。

宣告

以下是 std::plus 的宣告。

template <class T> struct plus;

C++11

template <class T> struct plus;

引數

T − 它是函式呼叫引數和返回型別的型別。

返回值

異常

noexcep − 它不丟擲任何異常。

示例

下面的示例解釋了 std::plus。

#include <iostream>
#include <functional>
#include <algorithm>

int main () {
   int first[]={15,12,30,45,15};
   int second[]={10,20,30,40,50};
   int results[5];
   std::transform (first, first+5, second, results, std::plus<int>());
   for (int i=0; i<5; i++)
      std::cout << results[i] << ' ';
   std::cout << '\n';
   return 0;
}

讓我們編譯並執行上面的程式,這將產生以下結果:

25 32 60 85 65 
functional.htm
廣告
© . All rights reserved.