[EMAIL PROTECTED] writes: > BenoƮt Dejean wrote: > > [ &string[0] not guarenteed to be contigous, although most implement > > that way; c_str() is safe only for read ]
Is .data() assumed to be contigous as well? There are a lot of casts of string.data() to (const char *) or equivalent in the monotone code. Try fgrep '.data()' *.cc to find a bunch. > Scott Meyers has stated, that the only container forseen to be used with > C libraries is std::vector, where the trick above shall work. This is why I wrote: > Since guess_binary() took a string, I used the slightly questionable: > &string[0] trick to get a writeable pointer to the string in > file.read(&buf[0],bufsize) in monotone_guess_binary_filename_for_lua. > Does anyone know of a way to just read up to some number of bytes into > a string? If not, should guess_binaries signature be changed to > guess_binary(unsigned char *data, int datalen) and a char[bufsize] array > be used instead of a string? I didn't change the signature because I still don't have a feel for what changes are acceptable vs. not in the monotone code. Does someone have an opinion on changing the signature? The vector change would also be a signature change, and I'd prefer the unsigned char *, datalen version, as it simplifies the calling code, continues to interact properly with something that wants to call it on a string (those calls have to be foo.{c_str,data}(),foo.size()). -Eric _______________________________________________ Monotone-devel mailing list Monotone-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/monotone-devel