簡體   English   中英

有沒有辦法使用 C++17 折疊表達式來實現這個?

[英]Is there a way to implement this using C++17 Fold Expressions?

想象一下,我有這個模板 class。

template <typename... TMessageHandler>
class message_handler_set
{
public:

    static bool call_handler(const MessageType& command)
    {
         // Call each TMessageHandler type's 'call_handler' and return the OR of the returns.
    }
};

我希望能夠為每個TMessageHandler類型調用 static call_handler並返回返回值的 OR。 對於三種消息處理程序類型,代碼將等效於此...

template <typename TMessageHandler1, typename TMessageHandler2, typename TMessageHandler3>
class message_handler_set
{
public:

    static bool call_handler(const MessageType& command)
    {
         return TMessageHandler1::call_handler(command) ||
                TMessageHandler2::call_handler(command) ||
                TMessageHandler3::call_handler(command);
    }
};

是否可以使用折疊表達式來實現這一點?

語法應該是:

static bool call_handler(const MessageType& command)
{
    return (... || TMessageHandler::call_handler(command));
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM