plus (STL/CLR)
Popisuje šablony třídy functor, pokud je volána, vrátí první argument a druhý.Umožňuje určit funkce jako svůj argument typ objektu.
template<typename Arg>
ref class plus
{ // wrap operator()
public:
typedef Arg first_argument_type;
typedef Arg second_argument_type;
typedef Arg result_type;
typedef Microsoft::VisualC::StlClr::BinaryDelegate<
first_argument_type, second_argument_type, result_type>
delegate_type;
plus();
plus(plus<Arg>% right);
result_type operator()(first_argument_type left,
second_argument_type right);
operator delegate_type^();
};
Parametry
- Arg
Typ argumenty a vrácené hodnoty.
Členské funkce
Definice typu |
Popis |
---|---|
delegate_type |
Typ obecného delegáta. |
first_argument_type |
Typ první argument functor. |
result_type |
Typ výsledku functor. |
second_argument_type |
Typ functor druhého argumentu. |
Člen |
Popis |
---|---|
plus |
Konstrukce functor. |
Operátor |
Popis |
---|---|
Operator() |
Vypočítá požadované funkce. |
operátor delegate_type ^ |
Vrhá functor pro delegáta. |
Poznámky
Třída šablony popisuje dvě argument functor.Definuje operátor členské operator() tak, že když objekt se nazývá jako funkce, vrátí první argument a druhý.
Objekt můžete také předat jako argument funkce, jejíž typ je delegate_type^ a budou převedeny správně.
Příklad
// cliext_plus.cpp
// compile with: /clr
#include <cliext/algorithm>
#include <cliext/functional>
#include <cliext/vector>
typedef cliext::vector<int> Myvector;
int main()
{
Myvector c1;
c1.push_back(4);
c1.push_back(3);
Myvector c2;
c2.push_back(2);
c2.push_back(1);
Myvector c3(2, 0);
// display initial contents " 4 3" and " 2 1"
for each (int elem in c1)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();
for each (int elem in c2)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();
// transform and display
cliext::transform(c1.begin(), c1.begin() + 2,
c2.begin(), c3.begin(), cliext::plus<int>());
for each (int elem in c3)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();
return (0);
}
Požadavky
Záhlaví:<cliext, funkční>
Obor názvů: cliext