Deduce template argument for size of initializer list

前端 未结 2 1359
既然无缘
既然无缘 2021-01-21 03:14

I have the following (not compilable) code:

template< size_t N >
void foo( std::array )
{
  // Code, where \"N\" is used.
}

int main()
{
  f         


        
2条回答
  •  孤独总比滥情好
    2021-01-21 04:00

    Thanks to core issue 1591, you can use

    template 
    void foo( int const (&arr)[N] )
    {
      // Code, where "N" is used.
    }
    
    foo({1, 2, 3});
    

提交回复
热议问题