Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62291 - in sandbox/conversion/boost/conversion: . std
From: vicente.botet_at_[hidden]
Date: 2010-05-28 07:52:41


Author: viboes
Date: 2010-05-28 07:52:40 EDT (Fri, 28 May 2010)
New Revision: 62291
URL: http://svn.boost.org/trac/boost/changeset/62291

Log:
Boost.Conversion:
* Add pack function
* Add conversion between vector of convertibles

Added:
   sandbox/conversion/boost/conversion/pack.hpp (contents, props changed)
   sandbox/conversion/boost/conversion/std/vector.hpp (contents, props changed)

Added: sandbox/conversion/boost/conversion/pack.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/pack.hpp 2010-05-28 07:52:40 EDT (Fri, 28 May 2010)
@@ -0,0 +1,42 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_CONVERSION_PACK__HPP
+#define BOOST_CONVERSION_PACK__HPP
+
+#include <boost/ref.hpp>
+#include <boost/fusion/adapted/std_pair.hpp>
+#include <boost/fusion/include/at_c.hpp>
+
+namespace boost { namespace conversion {
+
+
+template <typename T1, typename T2>
+struct result_of_pack {
+ typedef std::pair<
+ reference_wrapper<T1>, reference_wrapper<T2>
+ > type;
+};
+
+template <typename T1, typename T2>
+typename result_of_pack<T1 const, T2 const>::type pack(
+ T1 const& t1, T2 const& t2) {
+ return std::make_pair(boost::cref(t1), boost::cref(t2));
+}
+
+template <typename T1, typename T2>
+typename result_of_pack<T1 const, T2>::type pack(T1 const& t1, T2 & t2) {
+ return std::make_pair(boost::cref(t1), boost::ref(t2));
+}
+
+}}
+
+#endif
+

Added: sandbox/conversion/boost/conversion/std/vector.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/std/vector.hpp 2010-05-28 07:52:40 EDT (Fri, 28 May 2010)
@@ -0,0 +1,71 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+//[VECTOR__HPP
+#ifndef BOOST_CONVERT_TO_PAIR__HPP
+#define BOOST_CONVERT_TO_PAIR__HPP
+
+#include <vector>
+#include <boost/conversion/convert_to.hpp>
+#include <boost/conversion/assign_to.hpp>
+#include <boost/conversion/pack.hpp>
+
+
+namespace boost { namespace conversion {
+
+ namespace partial_specialization_workaround {
+ template < class T1, class A1, class T2, class A2>
+ struct convert_to< std::vector<T1,A1>, std::vector<T2,A2> > {
+ inline static std::vector<T1,A1> apply(std::vector<T2,A2> const & from)
+ {
+ std::vector<T1,A1> res;
+ boost::assign_to(res, from);
+ return res;
+ }
+ };
+ template < class T1, class A1, class T2, class A2>
+ struct assign_to< std::vector<T1,A1>, std::vector<T2,A2> > {
+ inline static std::vector<T1,A1>& apply(
+ std::vector<T1,A1>& to,
+ std::vector<T2,A2> const & from)
+ {
+ to.resize(from.size());
+ for (unsigned int i=0; i<from.size(); ++i) {
+ boost::assign_to(to[i], from[i]);
+ }
+ return to;
+ }
+ };
+
+ template < class T1, class A1, class T2, class A2>
+ struct convert_to< std::vector<T1,A1>,
+ std::pair<
+ boost::reference_wrapper<std::vector<T2,A2> const>,
+ boost::reference_wrapper<A1 const>
+ >
+ > {
+ inline static std::vector<T1,A1> apply(
+ std::pair<
+ boost::reference_wrapper<std::vector<T2,A2> const>,
+ boost::reference_wrapper<A1 const>
+ > const & pack)
+ {
+ std::vector<T1,A1> res(fusion::at_c<1>(pack));
+ boost::assign_to(res, fusion::at_c<0>(pack).get());
+ return res;
+ }
+ };
+
+ }
+}}
+
+#endif
+
+//]


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