id.hpp 905 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*!
  2. @file
  3. Defines `boost::hana::id`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_FUNCTIONAL_ID_HPP
  9. #define BOOST_HANA_FUNCTIONAL_ID_HPP
  10. #include <boost/hana/config.hpp>
  11. BOOST_HANA_NAMESPACE_BEGIN
  12. //! @ingroup group-functional
  13. //! The identity function -- returns its argument unchanged.
  14. //!
  15. //! ### Example
  16. //! @include example/functional/id.cpp
  17. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  18. constexpr auto id = [](auto&& x) -> decltype(auto) {
  19. return forwarded(x);
  20. };
  21. #else
  22. struct id_t {
  23. template <typename T>
  24. constexpr T operator()(T&& t) const {
  25. return static_cast<T&&>(t);
  26. }
  27. };
  28. constexpr id_t id{};
  29. #endif
  30. BOOST_HANA_NAMESPACE_END
  31. #endif // !BOOST_HANA_FUNCTIONAL_ID_HPP