std::integral_constant won't compile?

后端 未结 2 1405
执笔经年
执笔经年 2021-01-16 18:16

I want to make integral constant from char* and \"kernel32.dll\", but failed always. The following are my failed attempts, anyone can show me the correct usage?



        
2条回答
  •  执笔经年
    2021-01-16 18:59

    You may declare a static const char* and use it in std::integral_constant, something like:

    static constexpr const char money[] = "money";
    
    int main()
    {
        typedef void(*function_t)(int);
        function_t ptrFunc =
            delegate
                ::adapter<
                    &Class::print,
                    std::integral_constant >::invoke_no_fwd;
        auto type = delegate::
            adapter<&Class::print, std::integral_constant>::invoke_no_fwd;
        ptrFunc(-42); // 0
        type(0); // 42
    
        return 0;
    }
    

    Live example

    You may use something like in Aligning static string literals to allow to write the literal string in std::integral_constant with a Macro.

提交回复
热议问题