#pragma once #include "crow/utility.h" #include "crow/http_request.h" #include "crow/http_response.h" namespace crow { namespace detail { template struct partial_context : public black_magic::pop_back::template rebind, public black_magic::last_element_type::type::context { using parent_context = typename black_magic::pop_back::template rebind<::crow::detail::partial_context>; template using partial = typename std::conditional>::type; template typename T::context& get() { return static_cast(*this); } }; template<> struct partial_context<> { template using partial = partial_context; }; template struct context : private partial_context //struct context : private Middlewares::context... // simple but less type-safe { template class CallCriteria, int N, typename Context, typename Container> friend typename std::enable_if<(N == 0)>::type after_handlers_call_helper(Container& middlewares, Context& ctx, request& req, response& res); template class CallCriteria, int N, typename Context, typename Container> friend typename std::enable_if<(N > 0)>::type after_handlers_call_helper(Container& middlewares, Context& ctx, request& req, response& res); template class CallCriteria, int N, typename Context, typename Container> friend typename std::enable_if<(N < std::tuple_size::type>::value), bool>::type middleware_call_helper(Container& middlewares, request& req, response& res, Context& ctx); template typename T::context& get() { return static_cast(*this); } template using partial = typename partial_context::template partial; }; } // namespace detail } // namespace crow