Q: Check if path contains another in C++ I'm looking to achieve something like
if (basePath.contains(subPath)) {
    // subPath is a subPath of the basePath
}

I know I could achieve this by traversing the subPath's parents, checking for basePath on the way.
Is there an std method for this?

std::filesystem::path("/a/b/").contains("/a/b/c/d") == true

A: Depending on your requirements (i.e. what you consider to be a subpath), you could try analysing the result of std::filesystem::relative(), for example:
bool is_subpath(const std::filesystem::path &path,
                const std::filesystem::path &base)
{
    auto rel = std::filesystem::relative(path, base);
    return !rel.empty() && rel.native()[0] != '.';
}

Note, this function returns false if the path relation cannot be determined, or if paths match.

A: https://en.cppreference.com/w/cpp/algorithm/mismatch can easily solve it in one line:
bool is_subpath(const fs::path& path, const fs::path& base) {
    const auto mismatch_pair = std::mismatch(path.begin(), path.end(), base.begin(), base.end());
    return mismatch_pair.second == base.end();
}

with the following tests (Catch2):
TEST_CASE("is_subpath", "[path]") {
    REQUIRE( is_subpath("a/b/c", "a/b") );
    REQUIRE_FALSE( is_subpath("a/b/c", "b") );
    REQUIRE_FALSE( is_subpath("a", "a/b/c") );
    REQUIRE_FALSE( is_subpath(test_root / "a", "a") );
    REQUIRE( is_subpath(test_root / "a", test_root / "a") );
}


A: You can iterate through items in both paths:
for (auto b = basePath.begin(), s = subPath.begin(); b != basePath.end(); ++b, ++s)
{
    if (s == subPath.end() || *s != *b)
    {
        return false;
    }
}
return true;

