rvalue_t.hpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) 2016-2021 Antony Polukhin
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_PFR_DETAIL_RVALUE_T_HPP
  6. #define BOOST_PFR_DETAIL_RVALUE_T_HPP
  7. #pragma once
  8. #include <type_traits>
  9. #include <utility> // std::enable_if_t
  10. // This header provides aliases rvalue_t and lvalue_t.
  11. //
  12. // Usage: template <class T> void foo(rvalue<T> rvalue);
  13. //
  14. // Those are useful for
  15. // * better type safety - you can validate at compile time that only rvalue reference is passed into the function
  16. // * documentation and readability - rvalue_t<T> is much better than T&&+SFINAE
  17. namespace boost { namespace pfr { namespace detail {
  18. /// Binds to rvalues only, no copying allowed.
  19. template <class T
  20. #ifdef BOOST_PFR_DETAIL_STRICT_RVALUE_TESTING
  21. , class = std::enable_if_t<std::is_rvalue_reference<T&&>::value>
  22. #endif
  23. >
  24. using rvalue_t = T&&;
  25. /// Binds to mutable lvalues only
  26. }}} // namespace boost::pfr::detail
  27. #endif // BOOST_PFR_DETAIL_RVALUE_T_HPP