This is not making the path absolute, nor making it canonical.
It's shell expansion of the ~
character. And it's not a feature in Boost Filesystem, as such.
You can code it yourself:
Live On Coliru
#include <boost/filesystem.hpp>
#include <iostream>
using boost::filesystem::path;
path expand(path p) {
char const* const home = getenv("HOME");
if (home == nullptr)
return p; // TODO handle as error?
auto s = p.generic_string<std::string>();
if (!s.empty() && s.find("~/") == 0u) {
return home + s.substr(1);
}
return p;
}
int main() {
path sample = "~/test.cpp";
std::cout << expand(sample) << "\n";
}
Which, on my system prints "/home/sehe/test.cpp"