Guest User

Untitled

a guest
Jan 22nd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. namespace detail {
  2.  
  3. template<class T, class = void>
  4. struct has_close : std::false_type
  5. {
  6. };
  7.  
  8. template<class T>
  9. struct has_close<T, boost::void_t<
  10. decltype(std::declval<T&>().close())>>
  11. : std::true_type
  12. {
  13. };
  14.  
  15. template<class Stream>
  16. void
  17. close_stream(Stream& stream)
  18. {
  19. static_assert(has_close<Stream>::value,
  20. "Requirements not met: no close() and no customization point");
  21. stream.close();
  22. }
  23.  
  24. struct close_stream_impl
  25. {
  26. template<class Stream>
  27. void
  28. operator()(Stream& stream) const
  29. {
  30. using detail::close_stream;
  31. close_stream(stream);
  32. }
  33. };
  34.  
  35. } // detail
  36.  
  37. constexpr
  38. detail::close_stream_impl
  39. close_stream{};
Add Comment
Please, Sign In to add comment