adapt.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Copyright (c) 2018-2024 Marcelo Zimbres Silva (mzimbres@gmail.com)
  2. *
  3. * Distributed under the Boost Software License, Version 1.0. (See
  4. * accompanying file LICENSE.txt)
  5. */
  6. #ifndef BOOST_REDIS_ADAPTER_ADAPT_HPP
  7. #define BOOST_REDIS_ADAPTER_ADAPT_HPP
  8. #include <boost/redis/adapter/detail/response_traits.hpp>
  9. #include <boost/redis/adapter/detail/result_traits.hpp>
  10. #include <boost/redis/ignore.hpp>
  11. namespace boost::redis::adapter {
  12. /** @brief Adapts a type to be used as a response.
  13. *
  14. * The type T must be either
  15. *
  16. * @li a `response<T1, T2, T3, ...>`
  17. * @li `std::vector<node<String>>`
  18. *
  19. * The types T1, T2, etc can be any STL container, any integer type
  20. * and `std::string`.
  21. *
  22. * @tparam T The response type.
  23. */
  24. template <class T>
  25. auto boost_redis_adapt(T& t) noexcept
  26. {
  27. return detail::response_traits<T>::adapt(t);
  28. }
  29. /** @brief Adapts a type to be used as the response to an individual command.
  30. *
  31. * It can be used with low-level APIs, like @ref boost::redis::resp3::parser.
  32. */
  33. template <class T>
  34. auto adapt2(T& t = redis::ignore) noexcept
  35. {
  36. return detail::result_traits<T>::adapt(t);
  37. }
  38. } // namespace boost::redis::adapter
  39. #endif // BOOST_REDIS_ADAPTER_ADAPT_HPP