[Boost-bugs] [Boost C++ Libraries] #6775: boost::filesystem::path cannot be created from lexical_cast("")

Subject: [Boost-bugs] [Boost C++ Libraries] #6775: boost::filesystem::path cannot be created from lexical_cast("")
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-04-09 14:04:32


#6775: boost::filesystem::path cannot be created from lexical_cast("")
-----------------------------------------------------------+----------------
 Reporter: Ulrik Mikaelsson <ulrik.mikaelsson@…> | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
  Version: Boost 1.48.0 | Severity: Problem
 Keywords: |
-----------------------------------------------------------+----------------
 The boost {{{filesystem::path}}} can hold an "empty" state, where
 {{{.string()}}} returns {{{""}}}. It even has a designated check for this
 state, {{{empty()}}} This state is useful as a kind of null-value, to turn
 on or off certain behavior.

 However, this state cannot be reached through {{{lexical_cast}}}, the
 following code will for example end with a {{{boost::bad_lexical_cast}}}
 error.

 {{{
 #include <boost/lexical_cast.hpp>
 #include <boost/filesystem/path.hpp>
 #include <string>

 int main() {
   boost::filesystem::path str =
 boost::lexical_cast<boost::filesystem::path, std::string>("");
   return 0;
 }
 }}}

 IMO, this is a bug. {{{path}}} clearly has a normal and useful
 {{{empty()}}} state, which cannot for some reason be reached through
 {{{lexical_cast}}}. The equivalent test works for {{{std::string}}}, for
 example, so should not be inherent problem with {{{lexical_cast}}} itself.

 One consequence is that {{{path}}} cannot be used as a value-type for
 {{{program_options}}}, while allowing options with default-values to be
 turned of using empty values. (I.E. {{{--config-file ""}}})

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6775>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:09 UTC