242 if constexpr (std::is_same_v<Arg1, std::shared_ptr<Session>>)
245 [
session_ = std::weak_ptr<Session>(
session_), moved_handler = std::move(handler)](
246 std::unique_ptr<CustomPacket> &&packet) { moved_handler(
session_.lock(), std::move(packet)); },
247 (
bool(filter) ? ([
session_ = std::weak_ptr<Session>(
session_), moved_filter = std::move(filter)](
248 const CustomPacket &packet) {
return moved_filter(
session_.lock(), packet); })
252 else if constexpr (std::is_same_v<Arg1, Session &>)
255 [
session_ = std::weak_ptr<Session>(
session_), moved_handler = std::move(handler)](
256 std::unique_ptr<CustomPacket> &&packet) { moved_handler(*
session_.lock(), std::move(packet)); },
257 (
bool(filter) ? ([
session_ = std::weak_ptr<Session>(
session_), moved_filter = std::move(filter)](
258 const CustomPacket &packet) {
return moved_filter(*
session_.lock(), packet); })
262 else if constexpr (std::is_same_v<Arg1, boost::asio::io_context &>)
266 std::unique_ptr<CustomPacket> &&packet) { moved_handler(
io_context_, std::move(packet)); },
268 const CustomPacket &packet) {
return moved_filter(
io_context_, packet); })
272 else if constexpr (std::is_same_v<Arg1, std::shared_ptr<PacketDispatcher>>)
276 moved_handler = std::move(handler)](std::unique_ptr<CustomPacket> &&packet)
277 { moved_handler(
dispatcher_.lock(), std::move(packet)); },
279 moved_filter = std::move(filter)](
const CustomPacket &packet)
280 {
return moved_filter(
dispatcher_.lock(), packet); })
284 else if constexpr (std::is_same_v<Arg1, PacketDispatcher &>)
288 moved_handler = std::move(handler)](std::unique_ptr<CustomPacket> &&packet)
289 { moved_handler(*
dispatcher_.lock(), std::move(packet)); },
291 moved_filter = std::move(filter)](
const CustomPacket &packet)
292 {
return moved_filter(*
dispatcher_.lock(), packet); })
298 []<
bool flag =
false>()
301 "Unknown type passed! Supported types for handler are: Session&, "
302 "std::shared_ptr<Session>, io_context &, std::shared_ptr<PacketDispatcher> and "
303 "PacketDispatcher&. The CustomPacket type should be last.");
335 if constexpr (std::is_same_v<Arg1, std::shared_ptr<Session>>)
338 [
session_ = std::weak_ptr<Session>(
session_), moved_handler = std::move(handler)](
339 Arg2 &&arg2, Args &&...args, std::unique_ptr<CustomPacket> &&packet) {
340 moved_handler(
session_.lock(), std::forward<Arg2>(arg2), std::forward<Args>(args)...,
344 [
session_ = std::weak_ptr<Session>(
session_), moved_filter = std::move(filter)](
345 Arg2 &&arg2, Args &&...args,
const CustomPacket &packet) {
346 return moved_filter(
session_.lock(), std::forward<Arg2>(arg2),
347 std::forward<Args>(args)..., packet);
352 else if constexpr (std::is_same_v<Arg1, Session &>)
355 [
session_ = std::weak_ptr<Session>(
session_), moved_handler = std::move(handler)](
356 Arg2 &&arg2, Args &&...args, std::unique_ptr<CustomPacket> &&packet) {
357 moved_handler(*
session_.lock(), std::forward<Arg2>(arg2), std::forward<Args>(args)...,
361 [
session_ = std::weak_ptr<Session>(
session_), moved_filter = std::move(filter)](
362 Arg2 &&arg2, Args &&...args,
const CustomPacket &packet) {
363 return moved_filter(*
session_.lock(), std::forward<Arg2>(arg2),
364 std::forward<Args>(args)..., packet);
369 else if constexpr (std::is_same_v<Arg1, boost::asio::io_context &>)
373 Arg2 &&arg2, Args &&...args, std::unique_ptr<CustomPacket> &&packet) {
374 moved_handler(
io_context_, std::forward<Arg2>(arg2), std::forward<Args>(args)...,
379 Arg2 &&arg2, Args &&...args,
const CustomPacket &packet) {
380 return moved_filter(
io_context_, std::forward<Arg2>(arg2),
381 std::forward<Args>(args)..., packet);
386 else if constexpr (std::is_same_v<Arg1, std::shared_ptr<PacketDispatcher>>)
390 Arg2 &&arg2, Args &&...args, std::unique_ptr<CustomPacket> &&packet) {
391 moved_handler(
dispatcher_.lock(), std::forward<Arg2>(arg2), std::forward<Args>(args)...,
396 moved_filter = std::move(filter)](Arg2 &&arg2, Args &&...args,
397 const CustomPacket &packet) {
398 return moved_filter(
dispatcher_.lock(), std::forward<Arg2>(arg2),
399 std::forward<Args>(args)..., packet);
404 else if constexpr (std::is_same_v<Arg1, PacketDispatcher &>)
408 Arg2 &&arg2, Args &&...args, std::unique_ptr<CustomPacket> &&packet) {
409 moved_handler(*
dispatcher_.lock(), std::forward<Arg2>(arg2), std::forward<Args>(args)...,
414 moved_filter = std::move(filter)](Arg2 &&arg2, Args &&...args,
415 const CustomPacket &packet) {
416 return moved_filter(*
dispatcher_.lock(), std::forward<Arg2>(arg2),
417 std::forward<Args>(args)..., packet);
424 []<
bool flag =
false>()
427 "Unknown type passed! Supported types for handler are: Session&, "
428 "std::shared_ptr<Session>, io_context &, std::shared_ptr<PacketDispatcher> and "
429 "PacketDispatcher&. The CustomPacket type should be last.");