任何人都可以帮助解释以下构造函数的工作原理,
class StringData {
public:
/**
* Constructs a StringData explicitly, for the case of a literal whose size is known at
* compile time.
*/
struct LiteralTag {};
template<size_t N>
StringData( const char (&val)[N], LiteralTag )
: _data(&val[0]), _size(N-1) {}
private:
const char* _data; // is not guaranted to be null terminated
mutable size_t _size; // 'size' does not include the null terminator
}
为什么不直接使用这个构造函数?
StringData(const char *c):_data(c){}
完整的源代码可以在这里找到:http: //api.mongodb.org/cplusplus/1.7.1/stringdata_8h_source.html