#include <folly/portability/Filesystem.h>
namespace folly::fs {
#if __cpp_lib_filesystem >= 201703
path lexically_normal_fn::operator()(path const& p) const { … }
#elif __cpp_lib_experimental_filesystem >= 201406
path lexically_normal_fn::operator()(path const& p) const {
path dest;
bool lastDotDot = false;
for (path::string_type s : p) {
if (s == ".") {
dest /= "";
continue;
} else if (s == ".." && !dest.empty()) {
auto root = p.root_path();
if (dest == root) {
continue;
} else if (*(--dest.end()) != "..") {
auto drepr = dest.native();
if (drepr.back() == path::preferred_separator) {
drepr.pop_back();
dest = std::move(drepr);
}
dest.remove_filename();
continue;
}
}
if (!(s.empty() && lastDotDot)) {
dest /= s;
}
lastDotDot = s == "..";
}
if (dest.empty()) {
dest = ".";
}
return dest;
}
#else
#error require filesystem
#endif
}