开发者

boost::filesystem: Updating from 1.34.1 to current

I've got some legacy code here that makes use of boost::filesystem in version 1.34.1. I've isolated it into a little test program:

#include <iostream>

#include <boost/filesystem/path.hpp>

int main()
{
    // note the second parameter
    boost::filesystem::path p( "/tmp/foo", boost::filesystem::native );
    std::cout << p.string() << std::endl;
    return 0;
}

When I try to compile this code with the current (1.46.1) version of Boost, I get the following error:

test.cpp: In function ‘int main()’:
test.cpp:7: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘void*’
test.cpp:7: error:   initializing argument 2 of ‘boost::files开发者_StackOverflowystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<T>::type>, void>::type*) [with Source = char [9]]’

I've tried to make heads or tails of the Boost documentation, but I can't seem to figure out what that second parameter was good for, or what to replace it with. Can anybody shed some light on this?

UPDATE: I was not really clear on the requirements. For a transition period at least, I will have to support both versions (1.34.1 and 1.46.1). Is there a compatible way to cover both versions of Boost with the same code, or will I have to resort to #if BOOST_VERSION magic?

UPDATE 2: Used #if BOOST_VERSION ... as no further opinion was forthcoming. Thanks for the help.


boost::filesystem defines two formats for filenames: native, which differs from system to system, and generic which is identical across systems. Under POSIX (which appears to be what you are using) the two are identical. Under Windows the native format allows backslashes whereas the generic format does not. Under VMS (for example) the two are very different (the native format is something like [dir.subdir]file).

boost::filesystem::native appears to have been intended to indicate that the filename you are providing is in native format. I believe the current version of boost::filesystem is supposed to decide automatically, and since you're on a POSIX system it makes no difference anyway.

In short, the correct thing to do is simply to omit the parameter.


native seems to be a function now and the path constructor doesn't seem to need the native specifier. So just removing it should be fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜