Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72291 - in sandbox/coerce: boost/coerce boost/coerce/detail libs/coerce/test
From: vexocide_at_[hidden]
Date: 2011-05-30 13:38:32


Author: vexocide
Date: 2011-05-30 13:38:31 EDT (Mon, 30 May 2011)
New Revision: 72291
URL: http://svn.boost.org/trac/boost/changeset/72291

Log:
Removed boost.range and re-added iterable.hpp as string.hpp
Added:
   sandbox/coerce/boost/coerce/char.hpp (contents, props changed)
   sandbox/coerce/boost/coerce/string.hpp (contents, props changed)
Text files modified:
   sandbox/coerce/boost/coerce/coerce.hpp | 4 ++--
   sandbox/coerce/boost/coerce/detail/qi.hpp | 27 +++++++++++++--------------
   sandbox/coerce/libs/coerce/test/integral.cpp | 2 +-
   3 files changed, 16 insertions(+), 17 deletions(-)

Added: sandbox/coerce/boost/coerce/char.hpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/boost/coerce/char.hpp 2011-05-30 13:38:31 EDT (Mon, 30 May 2011)
@@ -0,0 +1,40 @@
+// Copyright Jeroen Habraken 2011.
+//
+// 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)
+
+#ifndef BOOST_COERCE_CHAR_HPP
+#define BOOST_COERCE_CHAR_HPP
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+#include <boost/config.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/type_traits/remove_const.hpp>
+
+namespace boost { namespace coerce { namespace traits {
+
+ template <typename T>
+ struct is_char_impl
+ : mpl::false_ { };
+
+ template <>
+ struct is_char_impl<char>
+ : mpl::true_ { };
+
+#ifndef BOOST_NO_WCHAR_T
+ template <>
+ struct is_char_impl<wchar_t>
+ : mpl::true_ { };
+#endif
+
+ template <typename T, typename Enable = void>
+ struct is_char
+ : is_char_impl<typename remove_const<T>::type> { };
+
+} } } // namespace boost::coerce::traits
+
+#endif // BOOST_COERCE_CHAR_HPP

Modified: sandbox/coerce/boost/coerce/coerce.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/coerce.hpp (original)
+++ sandbox/coerce/boost/coerce/coerce.hpp 2011-05-30 13:38:31 EDT (Mon, 30 May 2011)
@@ -13,7 +13,7 @@
 
 #include <boost/coerce/detail/backend.hpp>
 #include <boost/coerce/detail/push_back.hpp>
-#include <boost/range/has_range_iterator.hpp>
+#include <boost/coerce/string.hpp>
 
 #include <boost/throw_exception.hpp>
 
@@ -27,7 +27,7 @@
         struct as
             : detail::backend<
                 typename detail::is_back_insertion_sequence<Target>::type,
- typename has_range_const_iterator<Source>::type
+ typename traits::is_string<Source>::type
>::type { };
 
     } // namespace traits

Modified: sandbox/coerce/boost/coerce/detail/qi.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/detail/qi.hpp (original)
+++ sandbox/coerce/boost/coerce/detail/qi.hpp 2011-05-30 13:38:31 EDT (Mon, 30 May 2011)
@@ -12,11 +12,8 @@
 #endif
 
 #include <boost/coerce/reserve.hpp>
+#include <boost/coerce/string.hpp>
 
-#include <boost/range/begin.hpp>
-#include <boost/range/const_iterator.hpp>
-#include <boost/range/end.hpp>
-#include <boost/range/size.hpp>
 #include <boost/spirit/home/qi/auto.hpp>
 #include <boost/spirit/home/qi/char.hpp>
 #include <boost/spirit/home/qi/numeric.hpp>
@@ -28,22 +25,24 @@
         template <typename Target, typename Source>
         static inline bool
         call(Target & target, Source const & source) {
- typename range_difference<Source>::type size =
- boost::size(source);
+ typedef traits::string<Source> string_type;
+ string_type string(source);
+
+ typedef typename string_type::size_type size_type;
+ size_type size = string.size();
+
             detail::call_reserve(target, size);
 
- typedef typename range_const_iterator<Source>::type iterator_type;
- iterator_type begin = boost::const_begin(source),
- iterator = begin;
- iterator_type end = boost::const_end(source);
+ typename string_type::const_iterator
+ begin = string.begin(), iterator = begin, end = string.end();
 
- bool result = spirit::qi::parse(
- iterator, end, target);
+ bool result = spirit::qi::parse(iterator, end, target);
 
- if (!result || !((begin <= iterator && iterator < end && *iterator == 0) || iterator == end))
+ if (static_cast<size_type>(iterator - begin) != size) {
                 return false;
+ }
 
- return true;
+ return result;
         }
     };
 

Added: sandbox/coerce/boost/coerce/string.hpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/boost/coerce/string.hpp 2011-05-30 13:38:31 EDT (Mon, 30 May 2011)
@@ -0,0 +1,151 @@
+// Copyright Jeroen Habraken 2011.
+//
+// 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)
+
+#ifndef BOOST_COERCE_STRING_HPP
+#define BOOST_COERCE_STRING_HPP
+
+#include <boost/coerce/char.hpp>
+
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/optional.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/remove_const.hpp>
+
+#include <cstddef> // std::size_t
+#include <string>
+
+namespace boost { namespace coerce { namespace traits {
+
+ template <typename T>
+ struct string_impl
+ : mpl::identity<void> { };
+
+ template <typename T, typename U = typename is_char<T>::type>
+ struct string_impl_pointer
+ : mpl::identity<void> { };
+
+ template <typename T>
+ struct string_impl_pointer<T, mpl::true_> {
+ typedef T * type;
+
+ typedef T const * const_iterator;
+ typedef std::size_t size_type;
+
+ string_impl_pointer(T const * const value)
+ : value_(value) { }
+
+ inline const_iterator
+ begin() const {
+ return value_;
+ }
+
+ inline const_iterator
+ end() const {
+ return value_ + size();
+ }
+
+ inline size_type
+ size() {
+ return std::char_traits<
+ typename remove_const<T>::type
+ >::length(value_);
+ }
+
+ private:
+ T const * const value_;
+ };
+
+ template <typename T>
+ struct string_impl<T *>
+ : string_impl_pointer<T> {
+ string_impl(T const * const value)
+ : string_impl_pointer<T>(value) { }
+ };
+
+ template <typename T, std::size_t N, typename U = typename is_char<T>::type>
+ struct string_impl_extent
+ : mpl::identity<void> { };
+
+ template <typename T, std::size_t N>
+ struct string_impl_extent<T, N, mpl::true_> {
+ typedef T type[N];
+
+ typedef T const * const_iterator;
+ typedef std::size_t size_type;
+
+ string_impl_extent(T const (& value)[N])
+ : value_(value) { }
+
+ inline const_iterator
+ begin() const {
+ return &value_[0];
+ }
+
+ inline const_iterator
+ end() const {
+ return &value_[0] + size();
+ }
+
+ inline size_type
+ size() const {
+ return value_[N - 1] == 0 ? N - 1 : N;
+ }
+
+ private:
+ T const (& value_)[N];
+ };
+
+ template <typename T, std::size_t N>
+ struct string_impl<T [N]>
+ : string_impl_extent<T, N> {
+ string_impl(T const (& value)[N])
+ : string_impl_extent<T, N>(value) { }
+ };
+
+ template <typename T, typename Traits, typename Allocator>
+ struct string_impl<std::basic_string<T, Traits, Allocator> > {
+ typedef std::basic_string<T, Traits, Allocator> type;
+
+ typedef typename type::const_iterator const_iterator;
+ typedef typename type::size_type size_type;
+
+ string_impl(type const & value)
+ : value_(value) { }
+
+ inline const_iterator
+ begin() const {
+ return value_.begin();
+ }
+
+ inline const_iterator
+ end() const {
+ return value_.end();
+ }
+
+ inline size_type
+ size() const {
+ return value_.size();
+ }
+
+ private:
+ type const & value_;
+ };
+
+ template <typename T, typename Enable = void>
+ struct string
+ : string_impl<T> {
+ string(T const & value)
+ : string_impl<T>(value) { }
+ };
+
+ template <typename T>
+ struct is_string
+ : mpl::not_<is_same<typename string<T>::type, void> > { };
+
+} } } // namespace boost::coerce::traits
+
+#endif // BOOST_COERCE_STRING_HPP

Modified: sandbox/coerce/libs/coerce/test/integral.cpp
==============================================================================
--- sandbox/coerce/libs/coerce/test/integral.cpp (original)
+++ sandbox/coerce/libs/coerce/test/integral.cpp 2011-05-30 13:38:31 EDT (Mon, 30 May 2011)
@@ -84,7 +84,7 @@
         CHECK_THROW(T, "-9223372036854775809");
 
         CHECK_THROW(T, "23X");
- CHECK_EQUAL(T, "23\0X", static_cast<T>(23));
+ CHECK_THROW(T, "23\0X");
 
         CHECK_THROW(T, "XXX");
     }


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