Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52479 - in sandbox/conversion: boost/conversion boost/conversion/boost boost/conversion/std libs/conversion libs/conversion/doc libs/conversion/example libs/conversion/test
From: vicente.botet_at_[hidden]
Date: 2009-04-19 04:14:27


Author: viboes
Date: 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
New Revision: 52479
URL: http://svn.boost.org/trac/boost/changeset/52479

Log:
Boost.Conversion V0.1
Added:
   sandbox/conversion/boost/conversion/
   sandbox/conversion/boost/conversion/boost/
   sandbox/conversion/boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/boost/chrono_posix_time.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/boost/interval.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/boost/optional.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/boost/rational.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/boost/tuple.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/convert_to.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/std/
   sandbox/conversion/boost/conversion/std/complex.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/std/pair.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/std/string.hpp (contents, props changed)
   sandbox/conversion/libs/conversion/
   sandbox/conversion/libs/conversion/doc/
   sandbox/conversion/libs/conversion/doc/Jamfile.v2 (contents, props changed)
   sandbox/conversion/libs/conversion/doc/conversion.qbk (contents, props changed)
   sandbox/conversion/libs/conversion/example/
   sandbox/conversion/libs/conversion/test/
   sandbox/conversion/libs/conversion/test/Jamfile.v2 (contents, props changed)
   sandbox/conversion/libs/conversion/test/builtings.cpp (contents, props changed)
   sandbox/conversion/libs/conversion/test/complex.cpp (contents, props changed)
   sandbox/conversion/libs/conversion/test/extrinsec.cpp (contents, props changed)
   sandbox/conversion/libs/conversion/test/interval.cpp (contents, props changed)
   sandbox/conversion/libs/conversion/test/intrinsec.cpp (contents, props changed)
   sandbox/conversion/libs/conversion/test/optional.cpp (contents, props changed)
   sandbox/conversion/libs/conversion/test/pair.cpp (contents, props changed)
   sandbox/conversion/libs/conversion/test/rational.cpp (contents, props changed)

Added: sandbox/conversion/boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,67 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CONVERT_TO_CHRONO_DURATION_TO_POSIX_TIME_DURATION__HPP
+#define BOOST_CONVERT_TO_CHRONO_DURATION_TO_POSIX_TIME_DURATION__HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <boost/conversion/convert_to.hpp>
+
+namespace boost {
+
+ namespace partial_specialization_workaround {
+ template < class Rep, class Period>
+ struct convert_to<posix_time::time_duration, chrono::duration<Rep, Period> > {
+ inline static posix_time::time_duration apply(chrono::duration<Rep, Period> const & from)
+ {
+ typedef chrono::duration<Rep, Period> src_duration_t;
+ typedef chrono::nanoseconds duration_t;
+ typedef duration_t::rep rep_t;
+ rep_t d = chrono::duration_cast<duration_t>(from).count();
+ rep_t sec = d/1000000000;
+ rep_t nsec = d%1000000000;
+ return boost::posix_time::seconds(static_cast<long>(sec))+
+#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
+ boost::posix_time::nanoseconds(nsec);
+#else
+ boost::posix_time::microseconds((nsec+500)/1000);
+#endif
+ }
+ };
+ template < class Rep, class Period>
+ struct assign_to<posix_time::time_duration, chrono::duration<Rep, Period> > {
+ inline static posix_time::time_duration& apply(const chrono::duration<Rep, Period>& from, posix_time::time_duration& to)
+ {
+ to = boost::convert_to<posix_time::time_duration>(from);
+ return to;
+ }
+ };
+
+ template < class Rep, class Period>
+ struct convert_to<chrono::duration<Rep, Period>, posix_time::time_duration> {
+ inline static chrono::duration<Rep, Period> apply(posix_time::time_duration const & from)
+ {
+ return chrono::nanoseconds(from.total_nanoseconds());
+ }
+ };
+ template < class Rep, class Period>
+ struct assign_to<chrono::duration<Rep, Period>, posix_time::time_duration> {
+ inline static chrono::duration<Rep, Period> & apply(const posix_time::time_duration& from, chrono::duration<Rep, Period> & to)
+ {
+ to = boost::convert_to<chrono::duration<Rep, Period> >(from);
+ return to;
+ }
+ };
+ }
+}
+
+#endif
+

Added: sandbox/conversion/boost/conversion/boost/chrono_posix_time.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/boost/chrono_posix_time.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,18 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CONVERT_TO_CHRONO_POSIX_TIME__HPP
+#define BOOST_CONVERT_TO_CHRONO_POSIX_TIME__HPP
+
+#include <boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp>
+#include <boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp>
+
+#endif
+

Added: sandbox/conversion/boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,73 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+//[CHRONO_TIME_POINT_TO_POSIX_TIME_PTIME__HPP
+#ifndef BOOST_CONVERT_TO_CHRONO_TIME_POINT_TO_POSIX_TIME_PTIME__HPP
+#define BOOST_CONVERT_TO_CHRONO_TIME_POINT_TO_POSIX_TIME_PTIME__HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <boost/conversion/convert_to.hpp>
+
+namespace boost {
+
+ namespace partial_specialization_workaround {
+ template < class Clock, class Duration>
+ struct convert_to<posix_time::ptime, chrono::time_point<Clock, Duration> > {
+ inline static posix_time::ptime apply(const chrono::time_point<Clock, Duration>& from)
+ {
+ typedef chrono::time_point<Clock, Duration> time_point_t;
+ typedef chrono::nanoseconds duration_t;
+ typedef duration_t::rep rep_t;
+ rep_t d = chrono::duration_cast<duration_t>(from.time_since_epoch()).count();
+ rep_t sec = d/1000000000;
+ rep_t nsec = d%1000000000;
+ return boost::posix_time::from_time_t(0)+
+ boost::posix_time::seconds(static_cast<long>(sec))+
+#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
+ boost::posix_time::nanoseconds(nsec);
+#else
+ boost::posix_time::microseconds((nsec+500)/1000);
+#endif
+ }
+ };
+ template < class Clock, class Duration>
+ struct assign_to<posix_time::ptime, chrono::time_point<Clock, Duration> > {
+ inline static posix_time::ptime& apply(const chrono::time_point<Clock, Duration>& from, posix_time::ptime& to)
+ {
+ to = boost::convert_to<posix_time::ptime>(from);
+ return to;
+ }
+ };
+
+ template < class Clock, class Duration>
+ struct convert_to<chrono::time_point<Clock, Duration>, posix_time::ptime> {
+ inline static chrono::time_point<Clock, Duration> apply(const posix_time::ptime& from)
+ {
+ boost::posix_time::time_duration const time_since_epoch=from-boost::posix_time::from_time_t(0);
+ chrono::time_point<Clock, Duration> t=chrono::system_clock::from_time_t(time_since_epoch.total_seconds());
+ long nsec=time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second());
+ return t+chrono::nanoseconds(nsec);
+
+ }
+ };
+ template < class Clock, class Duration>
+ struct assign_to<chrono::time_point<Clock, Duration>, posix_time::ptime> {
+ inline static chrono::time_point<Clock, Duration>& apply(const posix_time::ptime& from, chrono::time_point<Clock, Duration>& to)
+ {
+ to = boost::convert_to<chrono::time_point<Clock, Duration> >(from);
+ return to;
+ }
+ };
+ }
+}
+
+#endif
+//]

Added: sandbox/conversion/boost/conversion/boost/interval.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/boost/interval.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,40 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CONVERT_TO_PAIR__HPP
+#define BOOST_CONVERT_TO_PAIR__HPP
+
+#include <boost/numeric/interval.hpp>
+#include <boost/conversion/convert_to.hpp>
+
+namespace boost {
+
+ namespace partial_specialization_workaround {
+ template < class T, class PT, class U, class PU>
+ struct convert_to< numeric::interval<T,PT>, numeric::interval<U,PU> > {
+ inline static numeric::interval<T,PT> apply(numeric::interval<U,PU> const & from)
+ {
+ return numeric::interval<T,PT>(boost::convert_to<T>(from.lower()), boost::convert_to<U>(from.upper()));
+ }
+ };
+ template < class T, class PT, class U, class PU>
+ struct assign_to< numeric::interval<T,PT>, numeric::interval<U,PU> > {
+ inline static numeric::interval<T,PT>& apply(const numeric::interval<U,PU>& from, numeric::interval<T,PT>& to)
+ {
+ to.assign(boost::convert_to<T>(from.lower()), boost::convert_to<U>(from.upper()));
+ return to;
+ }
+ };
+
+ }
+}
+
+#endif
+

Added: sandbox/conversion/boost/conversion/boost/optional.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/boost/optional.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,43 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+//[OPTIONAL__HPP
+#ifndef BOOST_CONVERT_TO_OPTIONAL__HPP
+#define BOOST_CONVERT_TO_OPTIONAL__HPP
+
+#include <boost/optional.hpp>
+#include <boost/none.hpp>
+#include <boost/conversion/convert_to.hpp>
+
+namespace boost {
+
+ namespace partial_specialization_workaround {
+ template < class Target, class Source>
+ struct convert_to< optional<Target>, optional<Source> > {
+ inline static optional<Target> apply(optional<Source> const & from)
+ {
+ return (from?optional<Target>(boost::convert_to<Target>(from.get())):optional<Target>());
+ }
+ };
+ template < class Target, class Source>
+ struct assign_to< optional<Target>, optional<Source> > {
+ inline static optional<Target>& apply(const optional<Source>& from, optional<Target>& to)
+ {
+ to = from?boost::convert_to<Target>(from.get()):optional<Target>();
+ return to;
+ }
+ };
+
+ }
+}
+
+#endif
+
+//]

Added: sandbox/conversion/boost/conversion/boost/rational.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/boost/rational.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,40 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CONVERT_TO_PAIR__HPP
+#define BOOST_CONVERT_TO_PAIR__HPP
+
+#include <boost/rational.hpp>
+#include <boost/conversion/convert_to.hpp>
+
+namespace boost {
+
+ namespace partial_specialization_workaround {
+ template < class T, class U>
+ struct convert_to< rational<T>, rational<U> > {
+ inline static rational<T> apply(rational<U> const & from)
+ {
+ return rational<T>(boost::convert_to<T>(from.numerator()), boost::convert_to<T>(from.denominator()));
+ }
+ };
+ template < class T, class U>
+ struct assign_to< rational<T>, rational<U> > {
+ inline static rational<T>& apply(const rational<U>& from, rational<T>& to)
+ {
+ to.assign(boost::convert_to<T>(from.numerator()), boost::convert_to<T>(from.denominator()));
+ return to;
+ }
+ };
+
+ }
+}
+
+#endif
+

Added: sandbox/conversion/boost/conversion/boost/tuple.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/boost/tuple.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,56 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CONVERT_TO_PAIR__HPP
+#define BOOST_CONVERT_TO_PAIR__HPP
+
+#include <boost/tr1/tuple>
+#include <boost/conversion/convert_to.hpp>
+
+namespace boost {
+
+ namespace partial_specialization_workaround {
+ template < class T1, class T2, class U1, class U2>
+ struct convert_to< std::tr1::tuple<T1,T2>, std::tr1::tuple<U1,U2> > {
+ inline static std::tr1::tuple<T1,T2> apply(std::tr1::tuple<U1,U2> const & from)
+ {
+ return std::tr1::tuple<T1,T2>(
+ convert_to<T1>(std::tr1::get<0>(from))
+ , convert_to<T2>(std::tr1::get<1>(from))
+ );
+ }
+ inline static std::tr1::tuple<T1,T2>& apply(std::tr1::tuple<U1,U2> const & from, std::tr1::tuple<T1,T2>& to)
+ {
+ to = boost::convert(from);
+ return to;
+ }
+ };
+ template < class T1, class T2, class T3, class U1, class U2, class U3>
+ struct convert_to< std::tr1::tuple<T1,T2,T3>, std::tr1::tuple<U1,U2,U3> > {
+ inline static std::tr1::tuple<T1,T2,T3> apply(std::tr1::tuple<U1,U2,U3> const & from)
+ {
+ return std::tr1::tuple<T1,T2, T3>(
+ convert_to<T1>(std::tr1::get<0>(from))
+ , convert_to<T2>(std::tr1::get<1>(from))
+ , convert_to<T3>(std::tr1::get<2>(from))
+ );
+ }
+ inline static std::tr1::tuple<T1,T2,T3> apply(std::tr1::tuple<U1,U2,U3> const & from, std::tr1::tuple<T1,T2,T3>& to)
+ {
+ to = boost::convert(from);
+ return to;
+ }
+ };
+
+ }
+}
+
+#endif
+

Added: sandbox/conversion/boost/conversion/convert_to.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/convert_to.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,78 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CONVERT_TO__HPP
+#define BOOST_CONVERT_TO__HPP
+
+#include <cstddef> //for std::size_t
+
+namespace boost {
+
+ template < typename To, typename From >
+ To convert_to(const From& val);
+
+ namespace partial_specialization_workaround {
+ template < typename To, typename From >
+ struct convert_to {
+ inline static To apply(const From& val)
+ {
+ return To(val);
+ }
+ };
+ template < typename To, typename From >
+ struct assign_to {
+ inline static To& apply(const From& from, To& to)
+ {
+ to = from;
+ return to;
+ }
+ };
+ template < typename To, typename From, std::size_t N >
+ struct assign_to<To[N],From[N]> {
+ inline static To*& apply(const From(& from)[N], To (&to)[N])
+ {
+ for (std::size_t i = 0; i < N; ++i)
+ {
+ to[i] = boost::convert_to(from[i]);
+ }
+ return to;
+ }
+ };
+#if 0
+ template < typename To, typename From, std::size_t N >
+ struct convert_to<To[N],From[N]> {
+ inline static To[N] apply(const From (& val)[N])
+ {
+ To[N] to;
+ for (std::size_t i = 0; i < N; ++i)
+ {
+ to[i] = boost::convert(from[i]);
+ }
+ return to;
+ }
+ };
+#endif
+ }
+
+ template < typename To, typename From >
+ To convert_to(const From& val) {
+ return partial_specialization_workaround::convert_to<To,From>::apply(val);
+ }
+
+ template < typename To, typename From >
+ To& assign_to(const From& from, To& to) {
+ return partial_specialization_workaround::assign_to<To,From>::apply(from, to);
+ }
+
+
+}
+
+#endif
+

Added: sandbox/conversion/boost/conversion/std/complex.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/std/complex.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,41 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CONVERT_TO_PAIR__HPP
+#define BOOST_CONVERT_TO_PAIR__HPP
+
+#include <complex>
+#include <boost/conversion/convert_to.hpp>
+
+namespace boost {
+
+ namespace partial_specialization_workaround {
+ template < class T, class U>
+ struct convert_to< std::complex<T>, std::complex<U> > {
+ inline static std::complex<T> apply(std::complex<U> const & from)
+ {
+ return std::complex<T>(boost::convert_to<T>(from.real()), boost::convert_to<T>(from.imag()));
+ }
+ };
+ template < class T, class U>
+ struct assign_to< std::complex<T>, std::complex<U> > {
+ inline static std::complex<T>& apply(const std::complex<U>& from, std::complex<T>& to)
+ {
+ to.real() = boost::convert_to<T>(from.real());
+ to.imag() = boost::convert_to<T>(from.imag());
+ return to;
+ }
+ };
+
+ }
+}
+
+#endif
+

Added: sandbox/conversion/boost/conversion/std/pair.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/std/pair.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,41 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+//[PAIR__HPP
+#ifndef BOOST_CONVERT_TO_PAIR__HPP
+#define BOOST_CONVERT_TO_PAIR__HPP
+
+#include <utility>
+#include <boost/conversion/convert_to.hpp>
+
+namespace boost {
+ namespace partial_specialization_workaround {
+ template < class T1, class T2, class U1, class U2>
+ struct convert_to< std::pair<T1,T2>, std::pair<U1,U2> > {
+ inline static std::pair<T1,T2> apply(std::pair<U1,U2> const & from)
+ {
+ return std::pair<T1,T2>(boost::convert_to<T1>(from.first), boost::convert_to<T2>(from.second));
+ }
+ };
+ template < class T1, class T2, class U1, class U2>
+ struct assign_to< std::pair<T1,T2>, std::pair<U1,U2> > {
+ inline static std::pair<T1,T2>& apply(const std::pair<U1,U2>& from, std::pair<T1,T2>& to)
+ {
+ to.first = boost::convert_to<T1>(from.first);
+ to.second = boost::convert_to<T2>(from.second);
+ return to;
+ }
+ };
+ }
+}
+
+#endif
+
+//]

Added: sandbox/conversion/boost/conversion/std/string.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/std/string.hpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,57 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CONVERT_TO_PAIR__HPP
+#define BOOST_CONVERT_TO_PAIR__HPP
+
+#include <string>
+#include <boost/conversion/convert_to.hpp>
+#include <boost/convert/convert.hpp>
+
+namespace boost {
+
+ namespace partial_specialization_workaround {
+
+ template<typename T, typename CharT, typename Traits, typename Alloc>
+ struct convert_to< std::basic_string<CharT,Traits,Alloc>, T > {
+ inline static std::basic_string<CharT,Traits,Alloc> apply(T const & from)
+ {
+ return convert<std::basic_string<CharT,Traits,Alloc> >::from(from);
+ }
+ }
+ template<typename T, typename CharT, typename Traits, typename Alloc>
+ struct assign_to< std::basic_string<CharT,Traits,Alloc>, T > {
+ inline static std::basic_string<CharT,Traits,Alloc>& apply(const T& from, std::basic_string<CharT,Traits,Alloc>& to)
+ {
+ to = convert<std::basic_string<CharT,Traits,Alloc> >::from(from);
+ return to;
+ }
+ };
+ template<typename T, typename CharT, typename Traits, typename Alloc>
+ struct convert_to< T, std::basic_string<CharT,Traits,Alloc>> {
+ inline static T apply(std::basic_string<CharT,Traits,Alloc> const & from)
+ {
+ return convert<T>::from(from);
+ }
+ };
+ template<typename T, typename CharT, typename Traits, typename Alloc>
+ struct assign_to< T, std::basic_string<CharT,Traits,Alloc>> {
+ inline static void apply(const std::basic_string<CharT,Traits,Alloc>& from, T& to)
+ {
+ to = convert<T>::from(from);
+ return to;
+ }
+ };
+
+ }
+}
+
+#endif
+

Added: sandbox/conversion/libs/conversion/doc/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/doc/Jamfile.v2 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,72 @@
+# Boost.LUID library documentation Jamfile ---------------------------------
+#
+# Copyright Vicente J. Botet Escriba 2009. Use, modification and
+# distribution is subject to the Boost Software License, Version
+# 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+#
+# See http://www.boost.org for updates, documentation, and revision history.
+
+#import doxygen ;
+import quickbook ;
+
+#doxygen autodoc
+# :
+# [ glob ../../../boost/interprocess/*.hpp ]
+# [ glob ../../../boost/interprocess/allocators/*.hpp ]
+# :
+# <doxygen:param>EXTRACT_ALL=NO
+# <doxygen:param>HIDE_UNDOC_MEMBERS=YES
+# <doxygen:param>EXTRACT_PRIVATE=NO
+# <doxygen:param>EXPAND_ONLY_PREDEF=YES
+# <doxygen:param>PREDEFINED=BOOST_INTERPROCESS_DOXYGEN_INVOKED
+# <xsl:param>"boost.doxygen.reftitle=Boost.Interprocess Reference"
+# ;
+
+xml conversion : conversion.qbk ;
+
+boostbook standalone
+ :
+ conversion
+ :
+ # HTML options first:
+ # Use graphics not text for navigation:
+ <xsl:param>navig.graphics=1
+ # How far down we chunk nested sections, basically all of them:
+ <xsl:param>chunk.section.depth=2
+ # Don't put the first section on the same page as the TOC:
+ <xsl:param>chunk.first.sections=1
+ # How far down sections get TOC's
+ <xsl:param>toc.section.depth=4
+ # Max depth in each TOC:
+ <xsl:param>toc.max.depth=2
+ # How far down we go with TOC's
+ <xsl:param>generate.section.toc.level=10
+ # Path for links to Boost:
+ <xsl:param>boost.root=../../../..
+ # Path for libraries index:
+ <xsl:param>boost.libraries=../../../../libs/libraries.htm
+ # Use the main Boost stylesheet:
+ <xsl:param>html.stylesheet=../../../../doc/html/boostbook.css
+
+ # PDF Options:
+ # TOC Generation: this is needed for FOP-0.9 and later:
+ #<xsl:param>fop1.extensions=1
+ # Or enable this if you're using XEP:
+ <xsl:param>xep.extensions=1
+ # TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9!
+ <xsl:param>fop.extensions=0
+ # No indent on body text:
+ <xsl:param>body.start.indent=0pt
+ # Margin size:
+ <xsl:param>page.margin.inner=0.5in
+ # Margin size:
+ <xsl:param>page.margin.outer=0.5in
+ # Yes, we want graphics for admonishments:
+ <xsl:param>admon.graphics=1
+ # Set this one for PDF generation *only*:
+ # default pnd graphics are awful in PDF form,
+ # better use SVG's instead:
+ <format>pdf:<xsl:param>admon.graphics.extension=".svg"
+ <format>pdf:<xsl:param>admon.graphics.path=$(boost-images)/
+ ;

Added: sandbox/conversion/libs/conversion/doc/conversion.qbk
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/doc/conversion.qbk 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,713 @@
+[/
+ / Copyright (c) 2008 Vicente J. Botet Escriba
+ /
+ / Distributed under the Boost Software License, Version 1.0. (See accompanying
+ / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ /]
+
+[library Boost.Conversion
+ [quickbook 1.3]
+ [authors [Botet Escriba, Vicente J.]]
+ [copyright 2009 Vicente J. Botet Escriba]
+ [id boost.conversion]
+ [dirname conversion]
+ [purpose Conversion utilities]
+ [license
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ [@http://www.boost.org/LICENSE_1_0.txt])
+ ]
+]
+
+[def __convert_to__ `convert_to`]
+[def __assign_to__ `assign_to`]
+
+[import ../../../boost/conversion/chrono_time_point_to_posix_time_ptime.hpp]
+[import ../../../boost/conversion/std/pair.hpp]
+[import ../../../boost/conversion/boost/optional.hpp]
+
+[/
+[section Preface]
+
+[:[".]]
+[:[*['-- ]]]
+
+[endsect]
+/]
+
+[warning Conversion is not a part of the Boost libraries.]
+
+[/import ../../../boost/conversion/lockable_traits.hpp]
+
+[/import ../example/BankAccount.cpp]
+
+[/========================]
+[section Overview]
+[/========================]
+
+[/==================]
+[heading Description]
+[/==================]
+
+Generic explict conversion between unrelated types.
+
+The main source of inspiration of this library were Boost.StringConvert.
+
+[*Boost.Conversion] provides:
+
+* a generic convert_to function which can be specialized by the user to make explict conversion between unrelated types.
+* a generic assign_to function which can be specialized by the user to make explict assignation between unrelated types.
+
+[/====================================]
+[heading How to Use This Documentation]
+[/====================================]
+
+This documentation makes use of the following naming and formatting conventions.
+
+* Code is in `fixed width font` and is syntax-highlighted.
+* Replaceable text that you will need to supply is in [~italics].
+* If a name refers to a free function, it is specified like this:
+ `free_function()`; that is, it is in code font and its name is followed by `()` to indicate that it is a free function.
+* If a name refers to a class template, it is specified like this: `class_template<>`; that is, it is in code font and its name is followed by `<>` to indicate that it is a class template.
+* If a name refers to a function-like macro, it is specified like this: `MACRO()`;
+ that is, it is uppercase in code font and its name is followed by `()` to indicate that it is a function-like macro. Object-like macros appear without the trailing `()`.
+* Names that refer to /concepts/ in the generic programming sense are specified in CamelCase.
+
+[note In addition, notes such as this one specify non-essential information that provides additional background or rationale.]
+
+Finally, you can mentally add the following to any code fragments in this document:
+
+ // Include all of Conversion files
+ #include <boost/conversion.hpp>
+
+[section Motivation]
+
+Imagine you need to convert unrelated types Source and Target. You can get it by defining a specific function such as
+
+ Target SourceToTarget(Source& v);
+
+Imagine now that you need to convert a `std::pair<Source, Source>` to a `std::pair<Target, Target>`. Well you can again define a specific function
+
+ std::pair<Target,Target> PairOfSourceToPairOfTarget(std::pair<Source,Source>& v) {
+ return std::make_pair(SourceToTarget(v.fisrt), SourceToTarget(v.second));
+ }
+
+While the SourceToTarget could be specific, the PairOfSourceToPairOfTarget sould be generic
+
+ template <typename Target1, typename Target2, typename Source1, typename Source2)
+ std::pair<Target1,Target2> ConvertPair(std::pair<Source1,Source2>& v);
+
+In order to do that we need that the pair template parameters define a common function, let it call convert_to,
+
+ template <typename Target, typename Source)
+ Target convert_to(Source& v);
+
+so ConvertPair can be defined as
+
+ template <typename Target1, typename Target2, typename Source1, typename Source2)
+ std::pair<Target1,Target2> ConvertPair(std::pair<Source1,Source2>& v) {
+ return std::make_pair(convert_to(v.fisrt), convert_to(v.second));
+ }
+
+The issue is that we need to specialize the convert_to function for the classes Source and Target. We can do it as follows
+
+ template <>
+ Target convert_to<Target, Source>(Source& v) {return SourceToTarget(v);}
+
+What about converting std::pair<Source,std::pair<Source,Source>> to std::pair<Target,std::pair<Target,Target>>?
+
+The issue now is that convert_to(std::make_pair<to, std::make_pair<to,to>>) do not compiles because the conversion of std::pair is named ConvertPair. So we need to specialize the function convert_to for pairs. With C++0x there is no major problem as it allows partial specialization of function templates. With C++98, we need to use a trick; as it allows partial specialization of classes we can define convert_to by as relying to a specific function of a class, as follows:
+
+ namespace partial_specialization_workaround {
+ template < typename Target, typename Source >
+ struct convert_to {
+ static Target apply(const Source& val);
+ };
+ }
+
+ template < typename Target, typename Source >
+ Target convert_to(const Source& val) {
+ return partial_specialization_workaround::convert_to<Target,Source>::apply(val);
+ }
+
+So now we can specialize partial_specialization_workaround::convert_to for pairs as follows:
+
+ namespace partial_specialization_workaround {
+ template <typename Target1, typename Target2, typename Source1, typename Source2)
+ struct convert_to< std::pair<Target1,Target2>, std::pair<Source1,Source2> > {
+ inline static std::pair<Target1,Target2> apply(std::pair<Source1,Source2>& v) {
+ {
+ return std::pair<T1,T2>(convert_to<T1>(from.first), convert_to<T2>(from.second));
+ }
+ };
+
+ }
+
+There is one more issue. The preceding design works well with unrelated classes, but what about classes that already define some kind of conversion, unisng a constructor or a conversion operator. Do we need to make specialization for these conversion? The answer is no. We need just to define the default implementation of the partial_specialization_workaround::convert_to::apply function to just return the explicit conversion.
+
+ namespace partial_specialization_work_around {
+ template < typename T, typename U>
+ struct convert_to {
+ inline static T apply(const U& val)
+ {
+ return T(val);
+ }
+ };
+ }
+
+
+What have we learned? Classes or algorithms relying on a conversion by construction or by the conversion operator can be made more generic by relaying in a function that explicitly states this conversion. So instead of requiring
+
+ Target(from)
+
+requires
+
+ convert_to<Target>(from)
+
+The same applies to classes or algorithms relying on the assignment operator. So instead of requiring
+
+ to = from
+
+requires
+
+ assign_to(from, to);
+
+The default implementation of assign_to relies on the assignement operator
+
+ namespace partial_specialization_workaround {
+ template < typename Target, typename Source >
+ struct assign_to {
+ inline static To& apply(const Source& from, Target& to)
+ {
+ to = from;
+ return to;
+ }
+ };
+ }
+ template < typename Target, typename Source >
+ To& assign_to(const Source& from, Target& to) {
+ return partial_specialization_workaround::assign_to<Target,Source>::apply(from, to);
+ }
+
+For classes that are explicitly convertible and having a self assignment operator it is easy to make a specialization of assign_to as follows.
+
+ to = convert_to<Target>(from);
+
+The rationale is that if there was not a copy constructor from a Source seems reasonable to think that there will not be an assignment operator. So in most of the cases, once we have specialized the convert_to function we recover a reasonable implementation for the assign_to function.
+
+We can even generalize this, so classes or algorithms relying on a member function can be made more generic by relaying on a function. The default function implementation could just to call to the member function with the equivalent prototype, but this is out of the scope of this library.
+
+So one of the advantages of using this common functions is uniformity. The other is that now we are able to find all the explicit conversions to one type, as we can do with explict casts.
+
+[endsect]
+[endsect]
+
+[/==============================]
+[section:users_guide Users'Guide]
+[/==============================]
+
+[/======================================]
+[section:getting_started Getting Started]
+[/======================================]
+
+[/======================================]
+[section:install Installing Conversion]
+[/======================================]
+
+[/=================================]
+[heading Getting Boost.Conversion]
+[/=================================]
+
+You can get the last stable release of Boost.Conversion by downloading [^conversion.zip] from the
+[@http://www.boost-consulting.com/vault/index.php?directory=Concurrent%20Programming Boost Vault]
+
+You can also access the latest (unstable?) state from the [@https://svn.boost.org/svn/boost/sandbox/conversion Boost Sandbox].
+
+[/=================================]
+[heading Building Boost.Conversion]
+[/=================================]
+
+There is no need to compile [*Boost.Conversion], since it's
+a header only library. Just include your Boost header directory in your
+compiler include path.
+
+[/=========================]
+[heading Requirements]
+[/=========================]
+
+[*Boost.Conversion] do not depends on any Boost library, at least for the generic part. Of course it dependens on the specific libraries when specific conversion are used. For these specific parts you must use either Boost version 1.38.0 or the version in SVN trunk (even if Boost version 1.35.x should works also).
+
+
+[/========================]
+[heading Exceptions safety]
+[/========================]
+
+All functions in the library are exception-neutral and provide strong guarantee of exception safety as long as
+the underlying parameters provide it.
+
+[/====================]
+[heading Thread safety]
+[/====================]
+
+All functions in the library are thread-unsafe except when noted explicitly.
+
+
+[/=======================]
+[heading Tested compilers]
+[/=======================]
+Currently, [*Boost.Conversion] has been tested in the following compilers/platforms:
+
+* GCC 3.4.4 Cygwin
+* GCC 3.4.6 Linux
+[/* GCC 4.3.2 Cygwin]
+* GCC 4.1.2 Linux
+
+[note Please send any questions, comments and bug reports to boost <at> lists <dot> boost <dot> org.]
+
+[endsect]
+[/=============================]
+[section Hello World! ]
+[/=============================]
+
+
+[endsect]
+
+[endsect]
+
+[section Tutorial]
+
+[section Using generic conversions]
+
+When you need to make a generic explicit conversion or assignation you just need to include the file boost/conversion/convert_to.hpp or boost/conversion/assign_to.hpp and just use the boost conversion function.
+
+ #include <boost/conversion/std/pair.hpp>
+
+ // ...
+
+ int i = convert_to<int>(3.5);
+
+[endsect]
+
+[section Using specific conversions]
+
+When you need make a specific conversion you will need to include the specific conversion file. E.g.
+
+ #include <boost/conversion/std/pair.hpp>
+
+ std::pair<int,int> pint(0,1);
+ std::pair<double,double> pdouble=boost::convert_to<std::pair<double,double> >(pint);
+
+Do not forget to include this files when you use a generic class or algorithm using the generic convert_to or assign_to, otherwise your program should not compile. E.g. if you want to convert a pair of chrono::time_point<> to a pair of posix_time::ptime do not forget to include in addition to the boost/conversion/std/pair.hpp the file boost/conversion/boost/chrono_posix_time.hpp
+
+[endsect]
+
+[section How to completly specialize the conversion functions]
+
+You can completly specialize the convert_to and assign_to functions as you will do for other functions. Just add an complete overload. E.g. if you want to add an explicit convertion from a type F to a type T do the following:
+
+ T convert_to(const F& from);
+
+[endsect]
+
+[section How to partially specialize the conversion functions]
+
+As it has been explained in the introduction, until you use a C++ compiler supporting the new partial specialization of function templates you will need to follow partial specialization workaround and partialy specialize the partial_specialization_workaround::convert_to class.
+
+[endsect]
+
+
+[endsect]
+
+
+[section:ext_references References]
+[variablelist
+[
+ [[@http://www.boostpro.com/vault/index.php?action=downloadfile&filename=boost-string-convert.zip&directory=&
+ [*Boost.Convert]]]
+ [Vladimir Batov. Not yet scheduled]
+]
+
+[
+ [[@http://www.boost.org/libs/conversion/lexical_cast.htm [*Boost.Conversion.LexicalCast]]]
+ [general literal text conversions, such as an int represented as a string, or vice-versa from Kevlin Henney]
+]
+
+[
+ [[@http://www.boost.org/libs/numeric/conversion [*Boost.NumericConversion]]]
+ [Optimized Policy-based Numeric Conversions from Fernando Cacciola.]
+]
+
+]
+
+[endsect]
+
+[endsect]
+
+
+[section Reference]
+[/==========================================================================================]
+[section:convert_to_hpp Header `<boost/conversion/convert_to.hpp>`]
+[/==========================================================================================]
+
+ namespace boost {
+ namespace partial_specialization_workaround {
+ template < typename To, typename From >
+ struct convert_to {
+ static To apply(const From& val);
+ };
+
+ template < typename To, typename From, std::size_t N >
+ struct convert_to<To[N],From[N]> {
+ static To[N] apply(const From (& val)[N]);
+ };
+ }
+
+ template < typename To, typename From >
+ To convert_to(const From& val);
+ }
+
+[endsect]
+
+[/==========================================================================================]
+[section:assign_to_hpp Header `<boost/conversion/assign_to.hpp>`]
+[/==========================================================================================]
+
+ namespace boost {
+ namespace partial_specialization_workaround {
+ template < typename To, typename From >
+ struct assign_to {
+ static void apply(const From& from, To& to);
+ };
+ template < typename To, typename From, std::size_t N >
+ struct assign_to<To[N],From[N]> {
+ static void apply(const From(& from)[N], To (&to)[N]);
+ };
+ }
+
+ template < typename To, typename From >
+ void assign_to(const From& from, To& to);
+ }
+
+[endsect]
+
+[/==========================================================================================]
+[section:complex_hpp Header `<boost/conversion/std/complex.hpp>`]
+[/==========================================================================================]
+
+ namespace boost {
+ namespace partial_specialization_workaround {
+ template < class T, class U>
+ struct convert_to< std::complex<T>, std::complex<U> > {
+ static std::complex<T> apply(std::complex<U> const & from);
+ };
+ template < class T, class U>
+ struct convert_to< std::complex<T>, std::complex<U> > {
+ static std::complex<T>& apply(const std::complex<U>& from, std::complex<T>& to);
+ };
+
+ }
+ }
+
+[endsect]
+[/==========================================================================================]
+[section:pair_hpp Header `<boost/conversion/std/pair.hpp>`]
+[/==========================================================================================]
+
+ namespace boost {
+ namespace partial_specialization_workaround {
+ template < class T1, class T2, class U1, class U2>
+ struct convert_to< std::pair<T1,T2>, std::pair<U1,U2> > {
+ static std::pair<T1,T2> apply(std::pair<U1,U2> const & from);
+ };
+ template < class T1, class T2, class U1, class U2>
+ struct assign_to< std::pair<T1,T2>, std::pair<U1,U2> > {
+ static std::pair<T1,T2>& apply(const std::pair<U1,U2>& from, std::pair<T1,T2>& to);
+ };
+ }
+ }
+
+[endsect]
+[/==========================================================================================]
+[section:string_hpp Header `<boost/conversion/std/string.hpp>`]
+[/==========================================================================================]
+
+ namespace boost {
+ namespace partial_specialization_workaround {
+ template<typename T, typename CharT, typename Traits, typename Alloc>
+ struct convert_to< std::basic_string<CharT,Traits,Alloc>, T > {
+ static std::basic_string<CharT,Traits,Alloc> apply(T const & from);
+ }
+ template<typename T, typename CharT, typename Traits, typename Alloc>
+ struct assign_to< std::basic_string<CharT,Traits,Alloc>, T > {
+ static std::basic_string<CharT,Traits,Alloc>& apply(
+ const T& from, std::basic_string<CharT,Traits,Alloc>& to);
+ };
+ template<typename T, typename CharT, typename Traits, typename Alloc>
+ struct convert_to< T, std::basic_string<CharT,Traits,Alloc>> {
+ static T apply(std::basic_string<CharT,Traits,Alloc> const & from);
+ };
+ template<typename T, typename CharT, typename Traits, typename Alloc>
+ struct assign_to< T, std::basic_string<CharT,Traits,Alloc>> {
+ static void apply(
+ const std::basic_string<CharT,Traits,Alloc>& from, T& to);
+ };
+ }
+ }
+
+[endsect]
+[/==========================================================================================]
+[section:rational_hpp Header `<boost/conversion/boost/rational.hpp>`]
+[/==========================================================================================]
+
+ namespace boost {
+ namespace partial_specialization_workaround {
+ template < class T, class U>
+ struct convert_to< rational<T>, rational<U> > {
+ inline static rational<T> apply(rational<U> const & from);
+ };
+ template < class T, class U>
+ struct assign_to< rational<T>, rational<U> > {
+ inline static rational<T>& apply(const rational<U>& from, rational<T>& to);
+ };
+ }
+ }
+
+[endsect]
+[/==========================================================================================]
+[section:chrono_posix_time_hpp Header `<boost/conversion/boost/chrono_posix_time.hpp>`]
+[/==========================================================================================]
+
+ namespace boost {
+ namespace partial_specialization_workaround {
+ template < class Rep, class Period>
+ struct convert_to<posix_time::time_duration, chrono::duration<Rep, Period> > {
+ static posix_time::time_duration apply(
+ chrono::duration<Rep, Period> const & from);
+ };
+ template < class Rep, class Period>
+ struct assign_to<posix_time::time_duration, chrono::duration<Rep, Period> > {
+ static posix_time::time_duration& apply(
+ const chrono::duration<Rep, Period>& from,
+ posix_time::time_duration& to);
+ };
+
+ template < class Rep, class Period>
+ struct convert_to<chrono::duration<Rep, Period>, posix_time::time_duration> {
+ static chrono::duration<Rep, Period> apply(posix_time::time_duration const & from);
+ };
+ template < class Rep, class Period>
+ struct assign_to<chrono::duration<Rep, Period>, posix_time::time_duration> {
+ static chrono::duration<Rep, Period> & apply(
+ const posix_time::time_duration& from,
+ chrono::duration<Rep, Period> & to);
+ };
+ }
+ }
+
+ namespace boost {
+ namespace partial_specialization_workaround {
+ template < class Clock, class Duration>
+ struct convert_to<posix_time::ptime, chrono::time_point<Clock, Duration> > {
+ static posix_time::ptime apply(const chrono::time_point<Clock, Duration>& from);
+ };
+ template < class Clock, class Duration>
+ struct assign_to<posix_time::ptime, chrono::time_point<Clock, Duration> > {
+ static posix_time::ptime& apply(
+ const chrono::time_point<Clock, Duration>& from,
+ posix_time::ptime& to);
+ };
+
+ template < class Clock, class Duration>
+ struct convert_to<chrono::time_point<Clock, Duration>, posix_time::ptime> {
+ static chrono::time_point<Clock, Duration> apply(const posix_time::ptime& from);
+ };
+ template < class Clock, class Duration>
+ struct assign_to<chrono::time_point<Clock, Duration>, posix_time::ptime> {
+ static chrono::time_point<Clock, Duration>& apply(
+ const posix_time::ptime& from,
+ chrono::time_point<Clock, Duration>& to);
+ };
+ }
+ }
+
+[endsect]
+[/==========================================================================================]
+[section:interval_hpp Header `<boost/conversion/boost/interval.hpp>`]
+[/==========================================================================================]
+
+ namespace boost {
+ namespace partial_specialization_workaround {
+ template < class T, class PT, class U, class PU>
+ struct convert_to< interval<T,PT>, interval<U,PU> > {
+ static interval<T,PT> apply(interval<U,PU> const & from);
+ };
+ template < class T, class PT, class U, class PU>
+ struct assign_to< interval<T,PT>, interval<U,PU> > {
+ static interval<T,PT>& apply(
+ const interval<U,PU>& from, interval<T,PT>& to);
+ };
+
+ }
+ }
+
+[endsect]
+[/==========================================================================================]
+[section:optional_hpp Header `<boost/conversion/boost/optional.hpp>`]
+[/==========================================================================================]
+
+ namespace boost {
+ namespace partial_specialization_workaround {
+ template < class Target, class Source>
+ struct convert_to< optional<Target>, optional<Source> > {
+ static optional<Target> apply(optional<Source> const & from);
+ };
+ template < class Target, class Source>
+ struct assign_to< optional<Target>, optional<Source> > {
+ static optional<Target>& apply(
+ const optional<Target>& from, optional<Target>& to);
+ };
+
+ }
+ }
+
+[endsect]
+[endsect]
+
+[section Examples]
+[section chrono::time_point and posix_time::ptime]
+
+[CHRONO_TIME_POINT_TO_POSIX_TIME_PTIME__HPP]
+
+[endsect]
+[section boost::optional]
+[OPTIONAL__HPP]
+
+[endsect]
+[section std::pair]
+[PAIR__HPP]
+[endsect]
+[endsect]
+
+[/=================]
+[section Appendices]
+[/=================]
+[section:history Appendix A: History]
+[section [*Version 0.1.0, April 16, 2009] ['Announcement of Conversions]]
+
+[*Features:]
+
+* a generic convert_to function which can be specialized by the user to make explict conversion between unrelated types.
+* a generic assign_to function which can be specialized by the user to make explict assignation between unrelated types.
+* conversion between C-arrays of explicitly convertible types.
+
+* conversion between std::complex of explicitly convertible types.
+* conversion between std::pair of explicitly convertible types.
+* conversion between std::string and Streamable types.
+
+* conversion between boost::optional of explicitly convertible types.
+* conversion between boost::rational of explicitly convertible types.
+* conversion between boost::interval of explicitly convertible types.
+
+* conversion between boost::chrono::time_point and boost::ptime.
+* conversion between boost::chrono::duration and boost::time_duration.
+
+[endsect]
+[endsect]
+
+[section:rationale Appendix B: Rationale]
+
+[heading Why use partial function specialization and not ADL?]
+
+[endsect]
+
+[section:implementation Appendix C: Implementation Notes]
+
+TBC
+
+[endsect]
+[section:acknowledgements Appendix D: Acknowledgements]
+
+Thanks to Vladimir Batov proposing Boost.StringConversion which was the source of inspiration of this generic library.
+
+[endsect]
+[section Appendix E: Tests]
+
+[section Builtings]
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[convert_to_with_builting_types] [run] [check convert_to works for builting types] [Pass] [#]]
+ [[assign_to_with_builting_types] [run] [check assign_to works for builting types] [Pass] [#]]
+]
+[endsect]
+
+
+[section Intrinsec Conversions]
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[convert_to_with_implicit_constructor] [run] [check convert_to works when there is an implicit constructor] [Pass] [#]]
+ [[convert_to_with_explicit_constructor] [run] [check convert_to works when there is an explicit constructor] [Pass] [#]]
+ [[convert_to_with_conversion_operator] [run] [check assign_to works when there is an conversion operator] [Pass] [#]]
+ [[assign_to_with_assignemet_operator] [run] [check assign_to works when there is an assignement operator] [Pass] [#]]
+ [[assign_to_with_assignemet_operator_and_implicit_constructor] [run] [check assign_to works when there is an assignemet operator and implicit constructor] [Pass] [#]]
+ [[assign_to_with_assignemet_operator_and_conversion_operator] [run] [check convert_to works when there is an assignemet operator and a conversion operator] [Pass] [#]]
+]
+[endsect]
+
+[section Extrinsec Conversions]
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[explicit_convert_to] [run] [check convert_to works when convert_to is overloaded] [Pass] [#]]
+ [[explicit_assign_to] [run] [check assign_to works when assign_to is overloaded] [Pass] [#]]
+]
+[endsect]
+
+[section STD]
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[convert_to_pair] [run] [check convert_to pair works when the parameters are convertible] [Pass] [#]]
+ [[convert_to_complex] [run] [check convert_to complex works when the parameters are convertible] [Pass] [#]]
+ [[convert_to_string] [run] [check convert_to string works when the parameter defines the operator<<] [Pass] [#]]
+ [[convert_from_string] [run] [check convert_to from string works when the parameter defines the operator>>] [Pass] [#]]
+]
+[endsect]
+
+[section Boost]
+[table
+ [[Name] [kind] [Description] [Result] [Ticket]]
+ [[convert_to_rational] [run] [check convert_to rational works when the parameters are convertible] [Pass] [#]]
+ [[convert_to_interval] [run] [check convert_to interval works when the parameters are convertible] [Pass] [#]]
+ [[convert_to_optional] [run] [check convert_to optional works when the parameters are convertible] [Pass] [#]]
+ [[convert_to_time_point] [run] [check convert_to time_point from ptime works] [Pass] [#]]
+ [[convert_to_ptime] [run] [check convert_to ptime from time_point works] [Pass] [#]]
+ [[convert_to_duration] [run] [check convert_to duration from time_duration works] [Pass] [#]]
+ [[convert_to_time_duration] [run] [check convert_to time_duration from duration works] [Pass] [#]]
+]
+[endsect]
+
+[endsect]
+[section Appendix F: Tickets]
+
+[endsect]
+
+[/=====================================]
+[section:todo Appendix F: Future plans]
+[/=====================================]
+
+[heading Tasks to do before review]
+
+* conversion between std::vector of explicitly convertible types.
+* conversion between boost::array of explicitly convertible types.
+* conversion between Boost.Fusion sequences of explicitly convertible types.
+
+[heading For later releases]
+
+
+* conversion between types for which lexical_cast works.
+* conversion between types for which numeric_cast works.
+
+
+[endsect]
+[endsect]
+
+
+

Added: sandbox/conversion/libs/conversion/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/test/Jamfile.v2 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,61 @@
+#
+# Boost.Synchro
+# Build script for tests.
+#
+# Copyright (c) 2008-2009 Vicente J. Botet Escriba]
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+using testing ;
+
+if ! $(BOOST_ROOT)
+{
+ BOOST_ROOT = [ modules.peek : BOOST_ROOT ] ;
+}
+
+# bjam -V2 threading=multi target-os=cygwin threadapi=pthread variant=debug
+
+project :
+ : requirements
+ <include>$(BOOST_ROOT)
+ <include>../../..
+ <include>../../../../chrono
+
+ <threading>multi
+# <target-os>cygwin
+ #<threadapi>pthread
+ <variant>debug
+
+ #<library>/boost/test//boost_unit_test_framework/<link>static
+ #<library>/boost/thread//boost_thread/<link>static
+ <library>../../../../chrono/libs/chrono/build//boost_chrono/<link>static
+
+ <library>../../../../../boost_1_38_0/libs/test/build//boost_unit_test_framework/<link>static
+# <library>../../../../../boost_1_38_0/libs/thread/build//boost_thread/<link>static
+# <library>../../../../../boost_1_38_0/libs/system/build//boost_system/<link>static
+
+;
+
+#exe helpers
+# : ../example/IL_BancAccount.cpp
+# : <define>BOOST_SYNCHRO_DO_NOT_COMPILE
+# ;
+
+
+
+test-suite "conversion" :
+ [ run builtings.cpp ]
+ [ run intrinsec.cpp ]
+ [ run extrinsec.cpp ]
+ [ run pair.cpp ]
+ [ run complex.cpp ]
+ [ run interval.cpp ]
+ [ run rational.cpp ]
+ [ run optional.cpp ]
+ ;
+
+
+test-suite "compile_fail_test" :
+# [ compile-fail ../example/IL_BancAccount.cpp : <define>BOOST_SYNCHRO_DO_NOT_COMPILE : IL_BancAccount_comp_fail ]
+ ;
+

Added: sandbox/conversion/libs/conversion/test/builtings.cpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/test/builtings.cpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,125 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/conversion/convert_to.hpp>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+
+
+
+void convert_to_with_builting_types() {
+ char c=0;
+ short s=1;
+ int i=2;
+ long l=3;
+ unsigned char uc(c);
+ unsigned short us(s);
+ unsigned int ui(i);
+ unsigned long ul(l);
+
+ c=convert_to<char>(c);
+ s=convert_to<short>(c);
+ i=convert_to<int>(c);
+ l=convert_to<long>(c);
+ uc=convert_to<unsigned char>(c);
+ us=convert_to<unsigned short>(c);
+ ui=convert_to<unsigned int>(c);
+ ul=convert_to<unsigned long>(c);
+
+
+ c=convert_to<char>(s);
+ s=convert_to<short>(s);
+ i=convert_to<int>(s);
+ l=convert_to<long>(s);
+ uc=convert_to<unsigned char>(s);
+ us=convert_to<unsigned short>(s);
+ ui=convert_to<unsigned int>(s);
+ ul=convert_to<unsigned long>(s);
+
+ c=convert_to<char>(i);
+ s=convert_to<short>(i);
+ i=convert_to<int>(i);
+ l=convert_to<long>(i);
+ uc=convert_to<unsigned char>(i);
+ us=convert_to<unsigned short>(i);
+ ui=convert_to<unsigned int>(i);
+ ul=convert_to<unsigned long>(i);
+
+ c=convert_to<char>(l);
+ s=convert_to<short>(l);
+ i=convert_to<int>(l);
+ l=convert_to<long>(l);
+ uc=convert_to<unsigned char>(l);
+ us=convert_to<unsigned short>(l);
+ ui=convert_to<unsigned int>(l);
+ ul=convert_to<unsigned long>(l);
+}
+
+
+void assign_to_with_builting_types() {
+ char c=0;
+ short s=1;
+ int i=2;
+ long l=3;
+ unsigned char uc(c);
+ unsigned short us(s);
+ unsigned int ui(i);
+ unsigned long ul(l);
+
+ assign_to(c,c);
+ assign_to(c, s);
+ assign_to(c, i);
+ assign_to(c, l);
+ assign_to(c, uc);
+ assign_to(c, us);
+ assign_to(c, ui);
+ assign_to(c, ul);
+
+ assign_to(s,c);
+ assign_to(s, s);
+ assign_to(s, i);
+ assign_to(s, l);
+ assign_to(s, uc);
+ assign_to(s, us);
+ assign_to(s, ui);
+ assign_to(s, ul);
+
+ assign_to(i,c);
+ assign_to(i, s);
+ assign_to(i, i);
+ assign_to(i, l);
+ assign_to(i, uc);
+ assign_to(i, us);
+ assign_to(i, ui);
+ assign_to(i, ul);
+
+ assign_to(l,c);
+ assign_to(l, s);
+ assign_to(l, i);
+ assign_to(l, l);
+ assign_to(l, uc);
+ assign_to(l, us);
+ assign_to(l, ui);
+ assign_to(l, ul);
+
+
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("builtings");
+ test->add(BOOST_TEST_CASE(&convert_to_with_builting_types));
+ test->add(BOOST_TEST_CASE(&assign_to_with_builting_types));
+ return test;
+}
+

Added: sandbox/conversion/libs/conversion/test/complex.cpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/test/complex.cpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,78 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/conversion/convert_to.hpp>
+#include <boost/conversion/std/complex.hpp>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+
+struct A1{};
+struct A2{};
+struct B1{};
+struct B2{};
+
+namespace boost {
+ template <>
+ A1 convert_to<A1,B1>(const B1& val) {
+ return A1();
+ }
+
+ template <>
+ A1& assign_to<A1,B1>(const B1& from, A1& to) {
+ return to;
+ }
+
+ namespace partial_specialization_workaround {
+ template <>
+ struct convert_to< A2,B2 > {
+ inline static A2 apply(B2 const & from)
+ {
+ return A2();
+ }
+ };
+ template < >
+ struct assign_to< A2,B2 > {
+ inline static A2& apply(const B2& from, A2& to)
+ {
+ return to;
+ }
+ };
+ }
+
+
+}
+void explicit_convert_to() {
+ B1 b1;
+ B1 b2;
+ std::complex<B1> b;
+ std::complex<A1> a1(convert_to<std::complex<A1> >(b));
+ std::complex<A1> a2(convert_to<std::complex<A1> >(std::complex<B1>(b1,b2)));
+
+}
+void explicit_assign_to() {
+ B1 b1;
+ B1 b2;
+ std::complex<A1> a;
+ std::complex<B1> b;
+ assign_to(b,a);
+ assign_to(std::complex<B1>(b1,b2),a);
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("complex");
+ test->add(BOOST_TEST_CASE(&explicit_convert_to));
+ test->add(BOOST_TEST_CASE(&explicit_assign_to));
+ return test;
+}
+

Added: sandbox/conversion/libs/conversion/test/extrinsec.cpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/test/extrinsec.cpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,51 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/conversion/convert_to.hpp>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+
+struct A{};
+struct B{};
+
+namespace boost {
+ template <>
+ A convert_to<A,B>(const B& val) {
+ return A();
+ }
+
+ template <>
+ A& assign_to<A,B>(const B& from, A& to) {
+ return to;
+ }
+
+}
+void explicit_convert_to() {
+ B b;
+ A a(convert_to<A>(b));
+
+}
+void explicit_assign_to() {
+ B b;
+ A a;
+ assign_to(b,a);
+
+}
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("extrinsec");
+ test->add(BOOST_TEST_CASE(&explicit_convert_to));
+ test->add(BOOST_TEST_CASE(&explicit_assign_to));
+ return test;
+}
+

Added: sandbox/conversion/libs/conversion/test/interval.cpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/test/interval.cpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,46 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/conversion/convert_to.hpp>
+#include <boost/conversion/boost/interval.hpp>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+
+typedef int A1;
+typedef short B1;
+
+void explicit_convert_to() {
+ B1 b1;
+ B1 b2;
+ boost::numeric::interval<B1> b;
+ boost::numeric::interval<A1> a1(convert_to<boost::numeric::interval<A1> >(b));
+ boost::numeric::interval<A1> a2(convert_to<boost::numeric::interval<A1> >(boost::numeric::interval<B1>(b1,b2)));
+
+}
+void explicit_assign_to() {
+ B1 b1;
+ B1 b2;
+ boost::numeric::interval<A1> a;
+ boost::numeric::interval<B1> b;
+ assign_to(b,a);
+ assign_to(boost::numeric::interval<B1>(b1,b2),a);
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("interval");
+ test->add(BOOST_TEST_CASE(&explicit_convert_to));
+ test->add(BOOST_TEST_CASE(&explicit_assign_to));
+ return test;
+}
+

Added: sandbox/conversion/libs/conversion/test/intrinsec.cpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/test/intrinsec.cpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,123 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/conversion/convert_to.hpp>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+
+struct B{};
+struct A {
+ A(int){};
+ A(const B&b){};
+};
+struct AE {
+ explicit AE(const B&b){};
+};
+struct AA {
+ AA(int){};
+ AA& operator=(const A&a) { return *this;}
+};
+
+struct C {
+ operator B() const{return B();};
+};
+struct CC {
+ CC(int){};
+ CC& operator=(const B&b) { return *this;}
+};
+
+void convert_to_with_implicit_constructor() {
+ {
+ B b;
+ A a(b);
+ }
+ {
+ B b;
+ A a(convert_to<A>(b));
+ }
+
+}
+void convert_to_with_explicit_constructor() {
+ {
+ B b;
+ AE ae(b);
+ }
+ {
+ B b;
+ AE ae(convert_to<AE>(b));
+ }
+
+}
+
+void convert_to_with_conversion_operator() {
+ {
+ C c;
+ A a(c);
+ }
+ {
+ C c;
+ A a(convert_to<A>(c));
+ }
+
+}
+void assign_to_with_assignemet_operator() {
+ {
+ A a(0);
+ AA aa(0);
+ aa=a;
+ }
+ {
+ A a(0);
+ AA aa(0);
+ assign_to(a,aa);
+ }
+
+}
+void assign_to_with_assignemet_operator_and_implicit_constructor() {
+ {
+ B b;
+ AA aa(1);
+ aa=b;
+ }
+ {
+ B b;
+ AA a(1);
+ assign_to(b,a);
+ }
+
+}
+void assign_to_with_assignemet_operator_and_conversion_operator() {
+ {
+ C c;
+ CC a(1);
+ a=c;
+ }
+ {
+ C c;
+ CC cc(1);
+ assign_to(c,cc);
+ }
+
+}
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("intrinsec");
+ test->add(BOOST_TEST_CASE(&convert_to_with_implicit_constructor));
+ test->add(BOOST_TEST_CASE(&convert_to_with_explicit_constructor));
+ test->add(BOOST_TEST_CASE(&convert_to_with_conversion_operator));
+ test->add(BOOST_TEST_CASE(&assign_to_with_assignemet_operator));
+ test->add(BOOST_TEST_CASE(&assign_to_with_assignemet_operator_and_implicit_constructor));
+ test->add(BOOST_TEST_CASE(&assign_to_with_assignemet_operator_and_conversion_operator));
+ return test;
+}
+

Added: sandbox/conversion/libs/conversion/test/optional.cpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/test/optional.cpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,46 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/conversion/convert_to.hpp>
+#include <boost/conversion/boost/optional.hpp>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+
+typedef int A1;
+typedef short B1;
+
+void explicit_convert_to() {
+ B1 b1;
+ boost::optional<B1> b;
+ boost::optional<A1> a1(convert_to<boost::optional<A1> >(b));
+ //boost::optional<A1> a1;
+ //a1=convert_to<boost::optional<A1> >(b);
+ boost::optional<A1> a2(convert_to<boost::optional<A1> >(boost::optional<B1>(b1)));
+
+}
+void explicit_assign_to() {
+ B1 b1;
+ boost::optional<A1> a;
+ boost::optional<B1> b;
+ //assign_to(b,a);
+ assign_to(boost::optional<B1>(b1),a);
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("optional");
+ test->add(BOOST_TEST_CASE(&explicit_convert_to));
+ test->add(BOOST_TEST_CASE(&explicit_assign_to));
+ return test;
+}
+

Added: sandbox/conversion/libs/conversion/test/pair.cpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/test/pair.cpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,81 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/conversion/convert_to.hpp>
+#include <boost/conversion/std/pair.hpp>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+
+struct A1{};
+struct A2{};
+struct B1{};
+struct B2{};
+
+namespace boost {
+ template <>
+ A1 convert_to<A1,B1>(const B1& val) {
+ return A1();
+ }
+
+ template <>
+ A1& assign_to<A1,B1>(const B1& from, A1& to) {
+ return to;
+ }
+
+ namespace partial_specialization_workaround {
+ template <>
+ struct convert_to< A2,B2 > {
+ inline static A2 apply(B2 const & from)
+ {
+ return A2();
+ }
+ };
+ template < >
+ struct assign_to< A2,B2 > {
+ inline static A2& apply(const B2& from, A2& to)
+ {
+ return to;
+ }
+ };
+ }
+
+
+}
+void explicit_convert_to() {
+ B1 b1;
+ B2 b2;
+ std::pair<B1,B2> b;
+ std::pair<A1,A2> a1(convert_to<std::pair<A1,A2> >(b));
+ std::pair<A1,A2> a2(convert_to<std::pair<A1,A2> >(std::pair<B1,B2>(b1,b2)));
+ std::pair<A1,A2> a3(convert_to<std::pair<A1,A2> >(std::make_pair(b1,b2)));
+
+}
+void explicit_assign_to() {
+ B1 b1;
+ B2 b2;
+ std::pair<A1,A2> a;
+ std::pair<B1,B2> b;
+ assign_to(b,a);
+ assign_to(std::pair<B1,B2>(b1,b2),a);
+ assign_to(std::make_pair(b1,b2),a);
+
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("pair");
+ test->add(BOOST_TEST_CASE(&explicit_convert_to));
+ test->add(BOOST_TEST_CASE(&explicit_assign_to));
+ return test;
+}
+

Added: sandbox/conversion/libs/conversion/test/rational.cpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion/test/rational.cpp 2009-04-19 04:14:19 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,46 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/conversion/convert_to.hpp>
+#include <boost/conversion/boost/rational.hpp>
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+
+typedef int A1;
+typedef short B1;
+
+void explicit_convert_to() {
+ B1 b1;
+ B1 b2(2);
+ boost::rational<B1> b(1,2);
+ boost::rational<A1> a1(convert_to<boost::rational<A1> >(b));
+ boost::rational<A1> a2(convert_to<boost::rational<A1> >(boost::rational<B1>(b1,b2)));
+
+}
+void explicit_assign_to() {
+ B1 b1;
+ B1 b2(2);
+ boost::rational<A1> a;
+ boost::rational<B1> b(1,2);
+ assign_to(b,a);
+ assign_to(boost::rational<B1>(b1,b2),a);
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("rational");
+ test->add(BOOST_TEST_CASE(&explicit_convert_to));
+ test->add(BOOST_TEST_CASE(&explicit_assign_to));
+ return test;
+}
+


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