25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

76 satır
2.0 KiB

  1. namespace cpphibernate {
  2. namespace mariadb {
  3. /* nullable_helper - cppcore::nullable */
  4. template<typename T_value>
  5. struct nullable_helper<cppcore::nullable<T_value>, void>
  6. {
  7. using nullable_type = cppcore::nullable<T_value>;
  8. using value_type = T_value;
  9. static inline value_type* get(nullable_type& x)
  10. { return x.has_value() ? &x.value() : nullptr; }
  11. static inline const value_type* get(const nullable_type& x)
  12. { return x.has_value() ? &x.value() : nullptr; }
  13. static inline value_type& set(nullable_type& x, const value_type* value)
  14. { return *(x = *value); }
  15. static inline value_type& set(nullable_type& x, const value_type& value)
  16. { return *(x = value); }
  17. static inline value_type& set(nullable_type& x, value_type&& value)
  18. { return *(x = std::move(value)); }
  19. static void clear(nullable_type& x)
  20. { x.reset(); }
  21. };
  22. /* nullable_helper - std::unique_ptr/std::shared_ptr */
  23. template<typename T>
  24. struct nullable_helper<
  25. T,
  26. mp::enable_if_t<
  27. mp::is_specialization_of_v<T, std::unique_ptr>
  28. || mp::is_specialization_of_v<T, std::shared_ptr>>>
  29. {
  30. using nullable_type = T;
  31. using value_type = typename nullable_type::element_type;
  32. static inline value_type* get(const nullable_type& x)
  33. { return x.get(); }
  34. static inline value_type& set(nullable_type& x, value_type* value)
  35. {
  36. x.reset(value);
  37. return *x;
  38. }
  39. static inline value_type& set(nullable_type& x, const value_type& value)
  40. {
  41. x.reset(new value_type(value));
  42. return *x;
  43. }
  44. static inline value_type& set(nullable_type& x, value_type&& value)
  45. {
  46. x.reset(new value_type(std::move(value)));
  47. return *x;
  48. }
  49. static void clear(nullable_type& x)
  50. { return x.reset(); }
  51. };
  52. } }