Sponsored Link •
The value_type for readdir_sequence is struct dirent const*. If it was something that was implicitly convertible to std::string, then you�d be able to write the succinct:
readdir_sequence dir(HOME, readdir_sequence::directories); vector<string> dirNames; std::copy(dir.begin(), dir.end(), std::back_inserter(dirNames));or the positively parsimonious:
readdir_sequence dir(HOME, readdir_sequence::directories); vector<string> dirNames(dir.begin(), dir.end());Since
d_nameis the only member of
struct direntthat is guaranteed to be available on any platform, it's clear, in hindsight — that great friend of the library writer — that
readdir_sequence::const_iteratorshould have been designed to have a value type
char const*. Unfortunately, we are stuck with it , since consideration for its users constrains us from making breaking changes to existing classes. Subsequent STLSoft sequence classes have learned from this, and generally provide more manipulable value types.
readdir_sequenceand a whole variety of other sequence types whose value_types are not implicitly convertible to
string, but which are logically strings or things meaningfully expressible strings. But that's going to have to be a whole 'nuther article.