Is there a way to pass an empty std::span<int>
to a function?
I have a function like below:
bool func( const std::vector<int>& indices )
{
if ( !indices.empty( ) )
{
/* do something */
}
...
}
// when calling it with an empty vector
const bool isAcceptable { func( std::vector<int>( 0 ) ) };
And I want to change it to use std::span
instead of std::vector
so that it can also get std::array
and raw array as its argument.
Now here:
bool func( const std::span<const int> indices )
{
if ( !indices.empty( ) )
{
/* do something */
}
...
}
// when calling it with an empty span
const bool isAcceptable { func( std::span<int>( ) ) }; // Is this valid code?
Also does std::span
properly support all contiguous containers (e.g. std::vector
, std::array
, etc.)?