proxygen
folly::Identity Struct Reference

#include <Utility.h>

Public Member Functions

template<class T >
constexpr T && operator() (T &&x) const noexcept
 

Detailed Description

A simple function object that passes its argument through unchanged.

Example:

int i = 42; int &j = Identity()(i); assert(&i == &j);

Warning: passing a prvalue through Identity turns it into an xvalue, which can effect whether lifetime extension occurs or not. For instance:

auto&& x = std::make_unique<int>(42); cout << *x ; // OK, x refers to a valid unique_ptr.

auto&& y = Identity()(std::make_unique<int>(42)); cout << *y ; // ERROR: y did not lifetime-extend the unique_ptr. It // is no longer valid

Definition at line 359 of file Utility.h.

Member Function Documentation

template<class T >
constexpr T&& folly::Identity::operator() ( T &&  x) const
inlinenoexcept

Definition at line 361 of file Utility.h.

References x.

361  {
362  return static_cast<T&&>(x);
363  }
const int x
folly::std T

The documentation for this struct was generated from the following file: