2015-10-16 11:20:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-06-20 11:32:45 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2015-10-16 11:20:33 +00:00
|
|
|
namespace ext
|
|
|
|
{
|
2017-06-06 17:10:04 +00:00
|
|
|
/// \brief Identity function for use with other algorithms as a pass-through.
|
|
|
|
class identity
|
|
|
|
{
|
|
|
|
/** \brief Function pointer type template for converting identity to a function pointer.
|
|
|
|
* Presumably useless, provided for completeness. */
|
|
|
|
template <typename T> using function_ptr_t = T &&(*)(T &&);
|
2015-10-16 11:20:33 +00:00
|
|
|
|
2017-06-06 17:10:04 +00:00
|
|
|
/** \brief Implementation of identity as a non-instance member function for taking function pointer. */
|
|
|
|
template <typename T> static T && invoke(T && t) { return std::forward<T>(t); }
|
2015-10-16 11:20:33 +00:00
|
|
|
|
2017-06-06 17:10:04 +00:00
|
|
|
public:
|
|
|
|
/** \brief Returns the value passed as a sole argument using perfect forwarding. */
|
|
|
|
template <typename T> T && operator()(T && t) const { return std::forward<T>(t); }
|
2015-10-16 11:20:33 +00:00
|
|
|
|
2017-06-06 17:10:04 +00:00
|
|
|
/** \brief Allows conversion of identity instance to a function pointer. */
|
|
|
|
template <typename T> operator function_ptr_t<T>() const { return &invoke; };
|
|
|
|
};
|
2015-10-16 11:20:33 +00:00
|
|
|
}
|