Move fclose_deleter and null_deleter to their own namespaces to block ADL.

This prevents bringing namespace boost into ADL when the deleters are used
in template parameters, e.g. in std::unique_ptr.
This commit is contained in:
Andrey Semashev
2024-02-02 05:12:41 +03:00
parent 7b1d3718c1
commit 95f0b35c36
6 changed files with 88 additions and 0 deletions

View File

@@ -26,6 +26,9 @@
namespace boost {
// Block unintended ADL
namespace fclose_deleter_ns {
//! A function object that closes a file
struct fclose_deleter
{
@@ -41,6 +44,10 @@ struct fclose_deleter
}
};
} // namespace fclose_deleter_ns
using fclose_deleter_ns::fclose_deleter;
} // namespace boost
#endif // BOOST_CORE_FCLOSE_DELETER_HPP

View File

@@ -27,6 +27,9 @@
namespace boost {
// Block unintended ADL
namespace null_deleter_ns {
//! A function object that does nothing and can be used as an empty deleter for \c shared_ptr
struct null_deleter
{
@@ -39,6 +42,10 @@ struct null_deleter
void operator() (T*) const BOOST_NOEXCEPT {}
};
} // namespace null_deleter_ns
using null_deleter_ns::null_deleter;
} // namespace boost
#endif // BOOST_CORE_NULL_DELETER_HPP