functor.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright Andrey Semashev 2024.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file functor.hpp
  9. * \author Andrey Semashev
  10. * \date 2024-01-23
  11. *
  12. * This header contains a \c functor implementation. This is a function object
  13. * that invokes a function that is specified as its template parameter.
  14. */
  15. #ifndef BOOST_CORE_FUNCTOR_HPP
  16. #define BOOST_CORE_FUNCTOR_HPP
  17. namespace boost::core {
  18. // Block unintended ADL
  19. namespace functor_ns {
  20. //! A function object that invokes a function specified as its template parameter
  21. template< auto Function >
  22. struct functor
  23. {
  24. template< typename... Args >
  25. auto operator() (Args&&... args) const noexcept(noexcept(Function(static_cast< Args&& >(args)...))) -> decltype(Function(static_cast< Args&& >(args)...))
  26. {
  27. return Function(static_cast< Args&& >(args)...);
  28. }
  29. };
  30. } // namespace functor_ns
  31. using functor_ns::functor;
  32. } // namespace boost::core
  33. #endif // BOOST_CORE_FUNCTOR_HPP