Dmitry Chichkov
Dmitry Chichkov

Reputation: 570

How to query the length of the boost::filesystem::path?

I couldn't find a 'path length' method in the boost::filesystem::path, is there one?

If there is no such method (why?) - should I use .native().length() or .string().length() ?
I take it .string().length() should be faster, right?

Upvotes: 3

Views: 2636

Answers (3)

Tom Kerr
Tom Kerr

Reputation: 10730

There is no length on path and it doesn't really follow why you would want it.

.string() is the generally recommended thing to use for externally visible representations. Check out the path decomposition table in their docs to get that warm fuzzy reassurance on what to expect.

I have no reason to believe performance would differ with either. You probably shouldn't worry about it until your profiler tells you to. :)

Upvotes: 0

TeaWolf
TeaWolf

Reputation: 714

.native() directly returns the internal representation of the path, while string() might perform some conversions. All in all, it won't make much difference though whether you use native().length() or string().length().

Upvotes: 2

Pavel P
Pavel P

Reputation: 16940

How about string() method? (returns std::string)

fs::path path;
...
path.string().size();

Upvotes: 1

Related Questions