Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] A suggestion
From: Anders Dalvander (boost_at_[hidden])
Date: 2009-02-07 08:17:31


> some bashing snipped...

Why not compromise?

1. Make the lexical_cast changes for optional that Andrew Troschinetz
suggested.
2. Add the following convert_to.hpp file:

#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>

namespace boost
{
   template <typename Target, typename Source>
   inline Target convert_to(const Source& arg)
   {
      return lexical_cast< optional<Target> >(arg).get_value_or(Target());
   }

   template <typename Target, typename Source>
   inline Target convert_to(const Source& arg, const Target& fallback)
   {
      return lexical_cast< optional<Target> >(arg).get_value_or(fallback);
   }
}

3. Use convert_to instead of lexical_cast.
4. Everyone happy?

Regards,
Anders Dalvander


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk