The Artima Developer Community
Sponsored Link

The C++ Source
Sidebar - Choose your value type carefully

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[1]:

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_name is the only member of struct dirent that is guaranteed to be available on any platform, it's clear, in hindsight — that great friend of the library writer — that readdir_sequence::const_iterator should have been designed to have a value type char const*. Unfortunately, we are stuck with it [1], 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.

Note

  1. I'm actually working on an adaptor that will facilitate such syntax for readdir_sequence and 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.

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us