xproxy_wrapper.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /***************************************************************************
  2. * Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
  3. * *
  4. * Distributed under the terms of the BSD 3-Clause License. *
  5. * *
  6. * The full license is in the file LICENSE, distributed with this software. *
  7. ****************************************************************************/
  8. #ifndef XTL_XPROXY_WRAPPER_HPP
  9. #define XTL_XPROXY_WRAPPER_HPP
  10. #include "xclosure.hpp"
  11. namespace xtl
  12. {
  13. template <class P>
  14. class xproxy_wrapper_impl : public P
  15. {
  16. public:
  17. using self_type = xproxy_wrapper_impl<P>;
  18. using lv_pointer = xclosure_pointer<P&>;
  19. using rv_pointer = xclosure_pointer<P>;
  20. explicit xproxy_wrapper_impl(P&& rhs)
  21. : P(std::move(rhs))
  22. {
  23. }
  24. inline lv_pointer operator&() & { return lv_pointer(*this); }
  25. inline rv_pointer operator&() && { return rv_pointer(std::move(*this)); }
  26. };
  27. template <class P>
  28. using xproxy_wrapper = std::conditional_t<std::is_class<P>::value,
  29. xproxy_wrapper_impl<P>,
  30. xclosure_wrapper<P>>;
  31. template <class P>
  32. inline xproxy_wrapper<P> proxy_wrapper(P&& proxy)
  33. {
  34. return xproxy_wrapper<P>(std::forward<P>(proxy));
  35. }
  36. }
  37. #endif