|
Boost Users : |
Subject: [Boost-users] [Filesystem] V3 interface inconsistency
From: Peter Klotz (Peter.Klotz_at_[hidden])
Date: 2011-02-24 03:13:39
Hello
I came across the following interface inconsistency in Boost.Filesystem V3 (Boost 1.46.0) in boost::filesystem::path
Windows:
const std::string string()
const std::wstring& wstring()
Linux:
const std::string& string()
const std::wstring wstring()
We converted V2 code looking like this (necessary since filename() in V3 returns a path instead of a string):
const std::string& filename=path.filename();
The converted V3 code:
const std::string& filename=path.filename().string();
Obviously this code crashes in Linux since filename() returns a temporary object and string() returns a reference to one of its members.
However this code works in Windows due to the different return types.
My question:
Wouldn't it make sense for all methods to return a value instead of a reference?
It would ease the transition from V2 to V3 and avoid subtle programming errors.
Regards, Peter.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net