namespace cpp {}

C++ lernen, kennen, anwenden

Benutzer-Werkzeuge

Webseiten-Werkzeuge


kennen:lib:ref
no way to compare when less than two revisions

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.


kennen:lib:ref [2019-11-20 15:07] (aktuell) – angelegt - Externe Bearbeitung 127.0.0.1
Zeile 1: Zeile 1:
 +====== ref() ======
 +''#include'' [[..:include:functional]]
 +
 +<code cpp>
 +template <class T> reference_wrapper<T> ref(T& x)
 +template <class T> reference_wrapper<const T> cref(const T& x)
 +</code>
 + Kapselt eine (konstante) Referenz auf eine Variable.
 +
 +==== Parameter ====
 +| ''x''   | (konstante) Variable |
 +==== Ergebnis ====
 +Rückgabewert: Wrapper. 
 +
 +==== Siehe auch ====
 +[[async]],
 +[[bind]],
 +[[..:include:thread]].
 +
 +==== Beispiel ====
 +<code cpp ref.cpp>
 +#include <functional>
 +#include <algorithm>
 +#include <iostream>
 +#include <string>
 +
 +void add(std::string& ziel, std::string quelle)
 +{
 +  ziel += quelle;
 +}
 +
 +int main()
 +{
 +  auto woerter = { "super", "cali", "fragi", "listisch" };
 +
 +  std::string s;
 +  auto f = std::bind(add, std::ref(s), std::placeholders::_1); 
 +  std::for_each(begin(woerter), end(woerter), f);
 +  std::cout << s << '\n';
 +}
 +</code>
  
kennen/lib/ref.txt · Zuletzt geändert: 2019-11-20 15:07 von 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki