7

別の関数のラッパーである機能オブジェクトがあります。

template <typename FuncT>
class Wrapper
{
    private:
        FuncT funcToWrap;

    public:
        Wrapper(FuncT ftw) : funcToWrap(ftw){};

        template<typename ...ARG>
        typename std::result_of<FuncT(ARG&&...)>::type operator()(ARG&&... args){
            return funcToWrap(std::forward<ARG>(args)...);
        }
};

int main(){
    std::function<void()> testfunc = [](){ std::cout << "Test" << std::endl; };
    Wrapper<decltype(testfunc)> test{testfunc};
    test();
}

私がやりたいことは、を is notのoperator()ようにマークすることです。[[nodiscard]]std::result_of<FuncT(ARG&&...)>::typevoid

私が気付いたのは[[nodiscard]]、戻り値の型のテンプレート評価の場合に を配置voidすると、コンパイラによって単に無視されることです。

これは私が信頼できる動作ですか、それは何らかの方法で標準化されていますか?

4

2 に答える 2