fd_resource_traits.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * https://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * Copyright (c) 2023 Andrey Semashev
  7. */
  8. /*!
  9. * \file scope/fd_resource_traits.hpp
  10. *
  11. * This header contains definition of \c unique_resource traits
  12. * for compatibility with POSIX-like file descriptors.
  13. */
  14. #ifndef BOOST_SCOPE_FD_RESOURCE_TRAITS_HPP_INCLUDED_
  15. #define BOOST_SCOPE_FD_RESOURCE_TRAITS_HPP_INCLUDED_
  16. #include <boost/scope/detail/config.hpp>
  17. #include <boost/scope/detail/header.hpp>
  18. #ifdef BOOST_HAS_PRAGMA_ONCE
  19. #pragma once
  20. #endif
  21. namespace boost {
  22. namespace scope {
  23. //! POSIX-like file descriptor resource traits
  24. struct fd_resource_traits
  25. {
  26. //! Creates a default fd value
  27. static int make_default() noexcept
  28. {
  29. return -1;
  30. }
  31. //! Tests if the fd is allocated (valid)
  32. static bool is_allocated(int fd) noexcept
  33. {
  34. return fd >= 0;
  35. }
  36. };
  37. } // namespace scope
  38. } // namespace boost
  39. #include <boost/scope/detail/footer.hpp>
  40. #endif // BOOST_SCOPE_FD_RESOURCE_TRAITS_HPP_INCLUDED_