object_fwd.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // MessagePack for C++ static resolution routine
  3. //
  4. // Copyright (C) 2008-2018 FURUHASHI Sadayuki and KONDO Takatoshi
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef MSGPACK_V3_OBJECT_FWD_HPP
  11. #define MSGPACK_V3_OBJECT_FWD_HPP
  12. #include "msgpack/v3/object_fwd_decl.hpp"
  13. #include "msgpack/object_fwd.hpp"
  14. namespace msgpack {
  15. /// @cond
  16. MSGPACK_API_VERSION_NAMESPACE(v3) {
  17. /// @endcond
  18. #if !defined(MSGPACK_USE_CPP03)
  19. namespace adaptor {
  20. // If v2 has as specialization for T, then dispatch v2::adaptor::as<T>.
  21. // So I call v2::has_as<T> meta function intentionally.
  22. template <typename T>
  23. struct as<T, typename std::enable_if<v2::has_as<T>::value>::type> : v2::adaptor::as<T> {
  24. };
  25. } // namespace adaptor
  26. template <typename T>
  27. struct has_as {
  28. private:
  29. template <typename U>
  30. static auto check(U*) ->
  31. typename std::enable_if<
  32. // check v3 specialization
  33. std::is_same<
  34. decltype(adaptor::as<U>()(std::declval<msgpack::object>())),
  35. U
  36. >::value
  37. ||
  38. // check v2 specialization
  39. v2::has_as<U>::value
  40. ||
  41. // check v1 specialization
  42. v1::has_as<U>::value,
  43. std::true_type
  44. >::type;
  45. template <typename...>
  46. static std::false_type check(...);
  47. public:
  48. using type = decltype(check<T>(MSGPACK_NULLPTR));
  49. static constexpr bool value = type::value;
  50. };
  51. #endif // !defined(MSGPACK_USE_CPP03)
  52. /// @cond
  53. } // MSGPACK_API_VERSION_NAMESPACE(v3)
  54. /// @endcond
  55. } // namespace msgpack
  56. #endif // MSGPACK_V3_OBJECT_FWD_HPP