traits.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // Copyright (c) 2023-2025 Ivica Siladic, Bruno Iljazovic, Korina Simicevic
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MQTT5_TRAITS_HPP
  8. #define BOOST_MQTT5_TRAITS_HPP
  9. #include <boost/container/small_vector.hpp>
  10. #include <boost/range/iterator_range_core.hpp>
  11. #include <boost/type_traits/remove_cv_ref.hpp>
  12. #include <optional>
  13. #include <utility>
  14. #include <vector>
  15. namespace boost::mqtt5::detail {
  16. template <typename>
  17. constexpr bool is_optional_impl = false;
  18. template <typename T>
  19. constexpr bool is_optional_impl<std::optional<T>> = true;
  20. template <typename T>
  21. constexpr bool is_optional = is_optional_impl<boost::remove_cv_ref_t<T>>;
  22. template <typename, template <typename...> typename>
  23. constexpr bool is_specialization = false;
  24. template <template <typename...> typename T, typename... Args>
  25. constexpr bool is_specialization<T<Args...>, T> = true;
  26. template <typename T>
  27. constexpr bool is_vector = is_specialization<
  28. boost::remove_cv_ref_t<T>, std::vector
  29. >;
  30. template <typename... Args>
  31. constexpr std::true_type is_small_vector_impl(
  32. boost::container::small_vector_base<Args...> const &
  33. );
  34. constexpr std::false_type is_small_vector_impl( ... );
  35. template <typename T>
  36. constexpr bool is_small_vector =
  37. decltype(is_small_vector_impl(std::declval<T>()))::value;
  38. template <typename T>
  39. constexpr bool is_pair = is_specialization<
  40. boost::remove_cv_ref_t<T>, std::pair
  41. >;
  42. template <typename T>
  43. constexpr bool is_boost_iterator = is_specialization<
  44. boost::remove_cv_ref_t<T>, boost::iterator_range
  45. >;
  46. } // end namespace boost::mqtt5::detail
  47. #endif // !BOOST_MQTT5_TRAITS_HPP