mirror of
https://github.com/boostorg/core.git
synced 2025-07-31 05:17:22 +02:00
Move functor to its own namespace to block bringing boost::core to ADL.
This commit is contained in:
@ -18,6 +18,9 @@
|
||||
|
||||
namespace boost::core {
|
||||
|
||||
// Block unintended ADL
|
||||
namespace functor_ns {
|
||||
|
||||
//! A function object that invokes a function specified as its template parameter
|
||||
template< auto Function >
|
||||
struct functor
|
||||
@ -29,6 +32,10 @@ struct functor
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace functor_ns
|
||||
|
||||
using functor_ns::functor;
|
||||
|
||||
} // namespace boost::core
|
||||
|
||||
#endif // BOOST_CORE_FUNCTOR_HPP
|
||||
|
@ -195,6 +195,9 @@ compile-fail fclose_deleter_compile_fail_adl.cpp
|
||||
: <target-os>windows:<define>_CRT_SECURE_NO_WARNINGS <target-os>windows:<define>_CRT_SECURE_NO_DEPRECATE $(warnings-as-errors-off) ;
|
||||
|
||||
run functor_test.cpp ;
|
||||
compile-fail functor_compile_fail_adl.cpp
|
||||
: $(warnings-as-errors-off) ;
|
||||
|
||||
|
||||
run pointer_traits_pointer_test.cpp ;
|
||||
run pointer_traits_element_type_test.cpp ;
|
||||
|
32
test/functor_compile_fail_adl.cpp
Normal file
32
test/functor_compile_fail_adl.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright Andrey Semashev 2024.
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
/*!
|
||||
* \file functor_compile_fail_adl.cpp
|
||||
* \author Andrey Semashev
|
||||
* \date 02.02.2024
|
||||
*
|
||||
* This file tests that \c boost::core::functor doesn't bring namespace
|
||||
* boost::core into ADL.
|
||||
*/
|
||||
|
||||
#include <boost/core/functor.hpp>
|
||||
|
||||
void func() {}
|
||||
|
||||
namespace boost::core {
|
||||
|
||||
void check_adl(functor< ::func > const&)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace boost::core
|
||||
|
||||
int main()
|
||||
{
|
||||
// Must not find boost::check_adl
|
||||
check_adl(boost::core::functor< ::func >());
|
||||
}
|
Reference in New Issue
Block a user