A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/functional/cref/ below:

function template

<functional>

std::cref reference (1)
template <class T>  reference_wrapper<const T> cref (const T& elem) noexcept;
copy (2)
template <class T>  reference_wrapper<const T> cref (reference_wrapper<T>& x) noexcept;
move (3)
template <class T>  void cref (const T&&) = delete;

Construct reference_wrapper to const

Constructs an object of the appropriate reference_wrapper type to hold a const T reference to elem.

If the argument is itself a reference_wrapper to a const T (2), it creates a copy of x instead.

The function calls the proper reference_wrapper constructor.



Parameters
elem
An lvalue reference, whose const reference is stored in the object.
x
A reference_wrapper object to const T, which is copied.

Return Value A reference_wrapper object of the appropriate type to hold an element of type const T.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// cref example
#include <iostream>     // std::cout
#include <functional>   // std::ref

int main () {
  int foo (10);

  auto bar = std::cref(foo);

  ++foo;

  std::cout << bar << '\n';

  return 0;
}

Output:


Data races The initialization version (1) does not access elem, but the returned object can be used to access it.
The copying version (2) accesses its argument (x), returning an object that which can be used to access its referred element.

Exception safetyNo-throw guarantee: never throws exceptions.

See also
reference_wrapper::reference_wrapper
Construct reference wrapper (public member function)
ref
Construct reference_wrapper (function template)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4