.. _program_listing_file_include_rclcpp_function_traits.hpp: Program Listing for File function_traits.hpp ============================================ |exhale_lsh| :ref:`Return to documentation for file ` (``include/rclcpp/function_traits.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2014 Open Source Robotics Foundation, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef RCLCPP__FUNCTION_TRAITS_HPP_ #define RCLCPP__FUNCTION_TRAITS_HPP_ #include #include #include namespace rclcpp { namespace function_traits { /* NOTE(esteve): * We support service callbacks that can optionally take the request id, * which should be possible with two overloaded create_service methods, * but unfortunately std::function's constructor on VS2015 is too greedy, * so we need a mechanism for checking the arity and the type of each argument * in a callback function. * See http://blogs.msdn.com/b/vcblog/archive/2015/06/19/c-11-14-17-features-in-vs-2015-rtm.aspx */ // Remove the first item in a tuple template struct tuple_tail; template struct tuple_tail> { using type = std::tuple; }; // std::function template struct function_traits { using arguments = typename tuple_tail< typename function_traits::arguments>::type; static constexpr std::size_t arity = std::tuple_size::value; template using argument_type = typename std::tuple_element::type; using return_type = typename function_traits::return_type; }; // Free functions template struct function_traits { using arguments = std::tuple; static constexpr std::size_t arity = std::tuple_size::value; template using argument_type = typename std::tuple_element::type; using return_type = ReturnTypeT; }; // Function pointers template struct function_traits: function_traits {}; // std::bind for object methods template #if defined DOXYGEN_ONLY struct function_traits> #elif defined _LIBCPP_VERSION // libc++ (Clang) struct function_traits> #elif defined _GLIBCXX_RELEASE // glibc++ (GNU C++ >= 7.1) struct function_traits> #elif defined __GLIBCXX__ // glibc++ (GNU C++) struct function_traits(FArgs ...)>> #elif defined _MSC_VER // MS Visual Studio struct function_traits< std::_Binder> #else #error "Unsupported C++ compiler / standard library" #endif : function_traits {}; // std::bind for object const methods template #if defined DOXYGEN_ONLY struct function_traits> #elif defined _LIBCPP_VERSION // libc++ (Clang) struct function_traits> #elif defined _GLIBCXX_RELEASE // glibc++ (GNU C++ >= 7.1) struct function_traits> #elif defined __GLIBCXX__ // glibc++ (GNU C++) struct function_traits(FArgs ...)>> #elif defined _MSC_VER // MS Visual Studio struct function_traits< std::_Binder> #else #error "Unsupported C++ compiler / standard library" #endif : function_traits {}; // std::bind for free functions template #if defined DOXYGEN_ONLY struct function_traits> #elif defined _LIBCPP_VERSION // libc++ (Clang) struct function_traits> #elif defined __GLIBCXX__ // glibc++ (GNU C++) struct function_traits> #elif defined _MSC_VER // MS Visual Studio struct function_traits> #else #error "Unsupported C++ compiler / standard library" #endif : function_traits {}; // Lambdas template struct function_traits : function_traits {}; template struct function_traits: function_traits {}; template struct function_traits: function_traits {}; /* NOTE(esteve): * VS2015 does not support expression SFINAE, so we're using this template to evaluate * the arity of a function. */ template struct arity_comparator : std::integral_constant< bool, (Arity == function_traits::arity)> {}; template struct check_arguments : std::is_same< typename function_traits::arguments, std::tuple > {}; template struct same_arguments : std::is_same< typename function_traits::arguments, typename function_traits::arguments > {}; namespace detail { template struct as_std_function_helper; template struct as_std_function_helper> { using type = std::function; }; } // namespace detail template< typename FunctorT, typename FunctionTraits = function_traits > struct as_std_function { using type = typename detail::as_std_function_helper< typename FunctionTraits::return_type, typename FunctionTraits::arguments >::type; }; } // namespace function_traits } // namespace rclcpp #endif // RCLCPP__FUNCTION_TRAITS_HPP_