How to avoid decay with template parameter deduction

前端 未结 2 2046
萌比男神i
萌比男神i 2021-01-04 05:28

Simplified:

// CHAR_TYPE == char, wchar_t, ...
template 
void Foo(CHAR_TYPE const (&value)[CHAR_COUNT]) no         


        
2条回答
  •  猫巷女王i
    2021-01-04 06:25

    Taking the argument by (const) reference blocks array-to-pointer decay during template argument deduction. See [temp.deduct.call]/2. So:

    template 
    void Foo(CHAR_TYPE const* const & value) noexcept
    {
        TRACE("const ptr");
        // perform a bit of logic and forward...
    }
    

提交回复
热议问题