Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Middleware documentation and compile time static assertions #864

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/crow/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,8 @@ namespace crow
template<typename... Ts>
std::tuple<Middlewares...> make_middleware_tuple(Ts&&... ts)
{
static_assert(black_magic::type_pack<Middlewares...>::template is_superset_of<Ts...>::value, "Constructor argument types must be a subset of the Crow template types");

auto fwd = std::forward_as_tuple((ts)...);
return std::make_tuple(
std::forward<Middlewares>(
Expand Down
26 changes: 26 additions & 0 deletions include/crow/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,32 @@ namespace crow
struct contains<Tp> : std::false_type
{};

template<typename Tp, typename... List>
struct contains_decayed : std::true_type
{};

template<typename Tp, typename Head, typename... Rest>
struct contains_decayed<Tp, Head, Rest...> :
std::conditional<std::is_same<typename std::decay<Tp>::type, typename std::decay<Head>::type>::value, std::true_type, contains_decayed<Tp, Rest...>>::type
{};

template<typename Tp>
struct contains_decayed<Tp> : std::false_type
{};

template<typename... Tsuper>
struct type_pack
{
template<typename... Tsub>
struct is_superset_of : std::true_type
{};

template<typename T, typename... Tsub>
struct is_superset_of<T, Tsub...> :
std::conditional<contains_decayed<T, Tsuper...>::value, is_superset_of<Tsub...>, std::false_type>::type
{};
};

template<typename T>
struct empty_context
{};
Expand Down
Loading