Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80895 - in sandbox/coerce: boost/coerce boost/coerce/tag libs/coerce/test
From: vexocide_at_[hidden]
Date: 2012-10-07 07:29:33


Author: vexocide
Date: 2012-10-07 07:29:32 EDT (Sun, 07 Oct 2012)
New Revision: 80895
URL: http://svn.boost.org/trac/boost/changeset/80895

Log:
Allow std::vector<CharT> as a source string
Text files modified:
   sandbox/coerce/boost/coerce/string.hpp | 16 ++++++++++++++++
   sandbox/coerce/boost/coerce/tag/base.hpp | 2 +-
   sandbox/coerce/libs/coerce/test/qi.cpp | 6 ++++++
   3 files changed, 23 insertions(+), 1 deletions(-)

Modified: sandbox/coerce/boost/coerce/string.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/string.hpp (original)
+++ sandbox/coerce/boost/coerce/string.hpp 2012-10-07 07:29:32 EDT (Sun, 07 Oct 2012)
@@ -103,6 +103,18 @@
     struct string_traits_impl<std::vector<T, Allocator> > {
         typedef std::vector<T, Allocator> type;
 
+ typedef typename type::const_iterator const_iterator;
+
+ static inline const_iterator
+ begin(type const & value) {
+ return value.begin();
+ }
+
+ static inline const_iterator
+ end(type const & value) {
+ return value.end();
+ }
+
         typedef std::back_insert_iterator<type> back_insert_iterator;
 
         static inline back_insert_iterator
@@ -135,6 +147,10 @@
     struct is_source_string_impl<boost::iterator_range<T> >
         : traits::is_char<typename boost::iterator_range<T>::value_type> { };
 
+ template <typename T, typename Allocator>
+ struct is_source_string_impl<std::vector<T, Allocator> >
+ : traits::is_char<T> { };
+
     template <typename T, typename Enable = void>
     struct is_source_string
         : is_source_string_impl<T> { };

Modified: sandbox/coerce/boost/coerce/tag/base.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/tag/base.hpp (original)
+++ sandbox/coerce/boost/coerce/tag/base.hpp 2012-10-07 07:29:32 EDT (Sun, 07 Oct 2012)
@@ -114,4 +114,4 @@
 
 } } } // namespace boost::coerce::tag
 
-#endif // !defined(BOOST_COERCE_TAG_HPP)
+#endif // !defined(BOOST_COERCE_TAG_BASE_HPP)

Modified: sandbox/coerce/libs/coerce/test/qi.cpp
==============================================================================
--- sandbox/coerce/libs/coerce/test/qi.cpp (original)
+++ sandbox/coerce/libs/coerce/test/qi.cpp 2012-10-07 07:29:32 EDT (Sun, 07 Oct 2012)
@@ -12,6 +12,7 @@
 #include <boost/test/unit_test.hpp>
 
 #include <string>
+#include <vector>
 
 BOOST_AUTO_TEST_CASE(qi) {
     using namespace boost;
@@ -68,6 +69,11 @@
 
     BOOST_CHECK_EQUAL(coerce::as<int>(std::string("1")), 1);
     BOOST_CHECK_EQUAL(coerce::as<int>(std::wstring(L"1")), 1);
+
+ std::vector<char> vector_char(1, '1');
+ BOOST_CHECK_EQUAL(coerce::as<int>(vector_char), 1);
+ std::vector<wchar_t> vector_wchar_t(1, L'1');
+ BOOST_CHECK_EQUAL(coerce::as<int>(vector_wchar_t), 1);
 }
 
 BOOST_AUTO_TEST_CASE(throw_) {


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