I don't think there is a builtin function.
You could use this, though:
if ("." != p.filename())
p += fs::path::preferred_separator;
This will not add the separator if the path ends in /.
Optionally, call p.remove_trailing_separator first, but that will also remove any trailing double-slash if it was part of the input (some applications treat this as having significant meaning).
Live On Coliru
#include <boost/filesystem.hpp>
#include <boost/range/iterator_range.hpp>
#include <iostream>
namespace fs = boost::filesystem;
int main(int argc, char** argv) {
for (std::string s : boost::make_iterator_range(argv+1, argv+argc)) {
fs::path p = s;
//p.remove_trailing_separator();
if ("." != p.filename())
p += fs::path::preferred_separator;
std::cout << "'" << s << "'\t" << p << "\n";
}
}
Prints (on linux, obviously):
'.' "."
'' "/"
'/' "//"
'/tmp' "/tmp/"
'/tmp/' "/tmp/"
'/tmp//' "/tmp//"
'/tmp/.' "/tmp/."
'/tmp/..' "/tmp/../"
'/tmp/...' "/tmp/.../"
'/tmp/aa.txt' "/tmp/aa.txt/"
'c:\test.txt' "c:\test.txt/"
C:/testas a file andC:/test/as a directory - until you check it.. Your best bet would be to convert to string and check if it ends with a path separator and if not, add it to the string!