Skip to content

database.path() returns std::string const& to reduce friction#254

Merged
kennykerr merged 2 commits into
microsoft:masterfrom
oldnewthing:database-path
Mar 29, 2019
Merged

database.path() returns std::string const& to reduce friction#254
kennykerr merged 2 commits into
microsoft:masterfrom
oldnewthing:database-path

Conversation

@oldnewthing

Copy link
Copy Markdown
Member

This reduces friction with the std::set<std::string> returned by reader.files(),

This reduces friction with the `std::set<std::string>`
returned by `reader.files()`,
@DefaultRyan

Copy link
Copy Markdown
Member

My first instinct was to resolve this friction by making the std::set's comparator transparent to allow it to operate with std::string_view.

  std::set<std::string, std::less<>> s; // std::less<> deduces parameter types
  auto iter = s.find(std::string_view{"asdf"});

@oldnewthing

Copy link
Copy Markdown
Member Author

My first instinct was to resolve this friction by making the std::set's comparator transparent to allow it to operate with std::string_view.
std::set<std::string, std::less<>> s; // std::less<> deduces parameter types
auto iter = s.find(std::string_view{"asdf"});

I thought about that, but suspected (perhaps erroneously) that transparency would result in a std::string being created at every node comparison inside std::set<>::find().

Even if transparency worked, that would create friction between reader.files() and anybody else who wants to use std::set<std::string>, because std::set<std::string> and a std::set<std::string, std::less<>> would not be compatible.

@kennykerr kennykerr merged commit 65b6a1c into microsoft:master Mar 29, 2019
@oldnewthing oldnewthing deleted the database-path branch March 29, 2019 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants