Delete forked function_traits
The function_traits class was very clearly "borrowed" from
boost::function traits, then added to to support lambdas.
boost::function_traits has been superceeded by boost::callable_traits,
which fixes the same shortcomings that we have fixed here.
This commit replaces almost the entirety of the uses of function_traits
with callable traits, with one exception: arg<i>. In the callable
traits model, arg_t is a std::tuple, which, while better, doesn't unpack
easily into a variadic pack that our router code expects. Ideally, at
some point, we would rewrite the router core to not rely on
std::make_integer_sequence, but that's a much more invasive change.
Tested:
Called
curl --insecure --user root:0penBmc https://192.168.7.2/redfish/v1/Managers/bmc/LogServices/Journal/Entries/1646953359619803
and verified callback return the correct result (not 404). That API has
several flexible router parameters, which is the only thing this commit
could break.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Icf3299b2d5c1a5ff111f68858bb46139735aaabe
diff --git a/http/routing.hpp b/http/routing.hpp
index 29ae22b..5f29761 100644
--- a/http/routing.hpp
+++ b/http/routing.hpp
@@ -488,10 +488,10 @@
template <typename Func>
void operator()(Func f)
{
- using function_t = utility::function_traits<Func>;
- erasedHandler =
- wrap(std::move(f),
- std::make_integer_sequence<unsigned, function_t::arity>{});
+ using boost::callable_traits::args_t;
+ constexpr size_t arity = std::tuple_size<args_t<Func>>::value;
+ constexpr auto is = std::make_integer_sequence<unsigned, arity>{};
+ erasedHandler = wrap(std::move(f), is);
}
// enable_if Arg1 == request && Arg2 == Response
@@ -504,7 +504,7 @@
const RoutingParams&)>
wrap(Func f, std::integer_sequence<unsigned, Indices...> /*is*/)
{
- using function_t = crow::utility::function_traits<Func>;
+ using function_t = crow::utility::FunctionTraits<Func>;
if (!black_magic::isParameterTagCompatible(
black_magic::getParameterTag(rule.c_str()),
diff --git a/http/utility.hpp b/http/utility.hpp
index a1561b0..da457be 100644
--- a/http/utility.hpp
+++ b/http/utility.hpp
@@ -3,6 +3,7 @@
#include <bmcweb_config.h>
#include <openssl/crypto.h>
+#include <boost/callable_traits.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/url/url.hpp>
@@ -340,49 +341,10 @@
{
template <typename T>
-struct function_traits;
-
-template <typename T>
-struct function_traits : public function_traits<decltype(&T::operator())>
+struct FunctionTraits
{
- using parent_t = function_traits<decltype(&T::operator())>;
- static const size_t arity = parent_t::arity;
- using result_type = typename parent_t::result_type;
template <size_t i>
- using arg = typename parent_t::template arg<i>;
-};
-
-template <typename ClassType, typename r, typename... Args>
-struct function_traits<r (ClassType::*)(Args...) const>
-{
- static const size_t arity = sizeof...(Args);
-
- using result_type = r;
-
- template <size_t i>
- using arg = typename std::tuple_element<i, std::tuple<Args...>>::type;
-};
-
-template <typename ClassType, typename r, typename... Args>
-struct function_traits<r (ClassType::*)(Args...)>
-{
- static const size_t arity = sizeof...(Args);
-
- using result_type = r;
-
- template <size_t i>
- using arg = typename std::tuple_element<i, std::tuple<Args...>>::type;
-};
-
-template <typename r, typename... Args>
-struct function_traits<std::function<r(Args...)>>
-{
- static const size_t arity = sizeof...(Args);
-
- using result_type = r;
-
- template <size_t i>
- using arg = typename std::tuple_element<i, std::tuple<Args...>>::type;
+ using arg = std::tuple_element_t<i, boost::callable_traits::args_t<T>>;
};
inline std::string base64encode(const std::string_view data)