Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57260 - in sandbox/numeric_adaptor: boost/numeric_adaptor libs/numeric_adaptor/test
From: bruno.lalande_at_[hidden]
Date: 2009-10-31 16:24:48


Author: bruno.lalande
Date: 2009-10-31 16:24:47 EDT (Sat, 31 Oct 2009)
New Revision: 57260
URL: http://svn.boost.org/trac/boost/changeset/57260

Log:
Added conversion from char*
Text files modified:
   sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp | 15 ++++++++++++---
   sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp | 15 ++++++++++++---
   sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp | 2 +-
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_conversions.cpp | 1 +
   4 files changed, 26 insertions(+), 7 deletions(-)

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp 2009-10-31 16:24:47 EDT (Sat, 31 Oct 2009)
@@ -142,16 +142,25 @@
 
 
 template <>
-struct to_traits<cln_value_type, std::string>
+struct to_traits<cln_value_type, const char*>
 {
- static cln_value_type apply(const std::string& source)
+ static cln_value_type apply(const char* source)
     {
         cln_value_type result;
- result.m_value = source.c_str();
+ result.m_value = source;
         return result;
     }
 };
 
+template <>
+struct to_traits<cln_value_type, std::string>
+{
+ static cln_value_type apply(const std::string& source)
+ {
+ return to_traits<cln_value_type, const char*>::apply(source.c_str());
+ }
+};
+
 
 } // namespace numeric_adaptor
 

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp 2009-10-31 16:24:47 EDT (Sat, 31 Oct 2009)
@@ -180,17 +180,26 @@
 
 
 template <>
-struct to_traits<gmp_value_type, std::string>
+struct to_traits<gmp_value_type, const char*>
 {
- static gmp_value_type apply(const std::string& source)
+ static gmp_value_type apply(const char* source)
     {
         gmp_value_type result;
         mpf_init(result.m_value);
- mpf_set_str(result.m_value, source.c_str(), 10);
+ mpf_set_str(result.m_value, source, 10);
         return result;
     }
 };
 
+template <>
+struct to_traits<gmp_value_type, std::string>
+{
+ static gmp_value_type apply(const std::string& source)
+ {
+ return to_traits<gmp_value_type, const char*>::apply(source.c_str());
+ }
+};
+
 
 } // namespace numeric_adaptor
 

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp 2009-10-31 16:24:47 EDT (Sat, 31 Oct 2009)
@@ -66,7 +66,7 @@
 { return boost::math::hypot(a, b); }
 
 template <class Target, class Source>
-Target to(const Source& source)
+Target to(Source source)
 { return numeric_adaptor::to_traits<Target, Source>::apply(source); }
 
 

Modified: sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_conversions.cpp
==============================================================================
--- sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_conversions.cpp (original)
+++ sandbox/numeric_adaptor/libs/numeric_adaptor/test/test_conversions.cpp 2009-10-31 16:24:47 EDT (Sat, 31 Oct 2009)
@@ -27,6 +27,7 @@
     double epsilon = 0.0001;
 
     BOOST_CHECK_CLOSE((double)boost::to<ValueType>(std::string("123.456")), 123.456, epsilon);
+ BOOST_CHECK_CLOSE((double)boost::to<ValueType>("123.456"), 123.456, epsilon);
 }
 
 int test_main(int, char*[])


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk