Restrict passed parameter to a string literal

前端 未结 6 1184
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 23:20

I have a class to wrap string literals and calculate the size at compile time.

The constructor looks like this:

template< std::size_t N >
Liter         


        
6条回答
  •  伪装坚强ぢ
    2020-12-03 23:22

    No there is no way to do this. String literals have a particular type and all method overload resolution is done on that type, not that it's a string literal. Any method which accepts a string literal will end up accepting any value which has the same type.

    If your function absolutely depends on an item being a string literal to function then you probably need to revisit the function. It's depending on data it can't guarantee.

提交回复
热议问题