Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71711 - in sandbox/coerce/boost: . coerce
From: vexocide_at_[hidden]
Date: 2011-05-04 09:28:01


Author: vexocide
Date: 2011-05-04 09:28:00 EDT (Wed, 04 May 2011)
New Revision: 71711
URL: http://svn.boost.org/trac/boost/changeset/71711

Log:
Use SFINAE toch check for T::push_back(T::value_type) instead of is_container and initial style change
Added:
   sandbox/coerce/boost/coerce/push_back.hpp (contents, props changed)
Removed:
   sandbox/coerce/boost/coerce/container.hpp
Text files modified:
   sandbox/coerce/boost/coerce.hpp | 4
   sandbox/coerce/boost/coerce/coerce.hpp | 208 +++++++++++++-------------
   sandbox/coerce/boost/coerce/reserve.hpp | 320 +++++++++++++++++++--------------------
   3 files changed, 266 insertions(+), 266 deletions(-)

Modified: sandbox/coerce/boost/coerce.hpp
==============================================================================
--- sandbox/coerce/boost/coerce.hpp (original)
+++ sandbox/coerce/boost/coerce.hpp 2011-05-04 09:28:00 EDT (Wed, 04 May 2011)
@@ -7,6 +7,10 @@
 #ifndef BOOST_COERCE_HPP
 #define BOOST_COERCE_HPP
 
+#ifdef _MSC_VER
+#pragma once
+#endif
+
 #include <boost/coerce/coerce.hpp>
 
 #endif // BOOST_COERCE_HPP

Modified: sandbox/coerce/boost/coerce/coerce.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/coerce.hpp (original)
+++ sandbox/coerce/boost/coerce/coerce.hpp 2011-05-04 09:28:00 EDT (Wed, 04 May 2011)
@@ -7,7 +7,11 @@
 #ifndef BOOST_COERCE_COERCE_HPP
 #define BOOST_COERCE_COERCE_HPP
 
-#include <boost/coerce/container.hpp>
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+#include <boost/coerce/push_back.hpp>
 #include <boost/coerce/reserve.hpp>
 
 #include <boost/mpl/bool.hpp>
@@ -29,133 +33,129 @@
 
 #include <typeinfo> // for std::bad_cast
 
-namespace boost {
+namespace boost { namespace coerce { namespace detail {
 
- namespace coerce {
+ template <typename Target, typename Source>
+ struct as {
+ static inline bool
+ call(Target & target, Source const & source) {
+ return do_call(
+ target,
+ source,
+ has_range_const_iterator<Source>(),
+ typename detail::has_push_back<Target>::type());
+ }
 
- class bad_cast
- : public std::bad_cast { };
+ private:
+ static inline bool
+ do_call(
+ Target & target,
+ Source const & source,
+ mpl::true_,
+ bool
+ ) {
+ typename range_difference<Source>::type size =
+ boost::size(source);
+ 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);
 
- namespace detail {
+ bool result = spirit::qi::parse(
+ iterator, end, target);
 
- template <typename Target, typename Source>
- struct as {
- static inline bool
- call(Target & target, Source const & source) {
- return do_call(
- target,
- source,
- has_range_const_iterator<Source>(),
- traits::is_container<Target>());
- }
-
- private:
- static inline bool
- do_call(
- Target & target,
- Source const & source,
- mpl::true_,
- bool
- ) {
- typedef typename range_const_iterator<Source>::type iterator_type;
-
- typename range_difference<Source>::type size;
- size = boost::size(source);
-
- call_reserve(target, size);
-
- iterator_type begin = const_begin(source),
- iterator = begin;
- iterator_type end = const_end(source);
-
- bool result = spirit::qi::parse(
- iterator, end, target);
-
- if (!result || !((begin <= iterator && iterator < end && *iterator == 0) || iterator == end))
- return false;
-
- return true;
- }
-
- static inline bool
- do_call(
- Target & target,
- Source const & source,
- mpl::false_,
- mpl::true_
- ) {
- call_reserve(
- target,
- traits::reserve_size<Source>::call(source));
+ if (!result || !((begin <= iterator && iterator < end && *iterator == 0) || iterator == end))
+ return false;
+
+ return true;
+ }
+
+ static inline bool
+ do_call(
+ Target & target,
+ Source const & source,
+ mpl::false_,
+ mpl::true_
+ ) {
+ call_reserve(
+ target,
+ traits::reserve_size<Source>::call(source));
 
- bool result = spirit::karma::generate(
- std::back_inserter(target),
+ bool result = spirit::karma::generate(
+ std::back_inserter(target),
 #if SPIRIT_VERSION <= 0x2030
- spirit::karma::auto_,
+ spirit::karma::auto_,
 #endif
- source);
+ source);
 
- return result;
- }
+ return result;
+ }
 
- static inline bool
- do_call(
- Target & target,
- Source const & source,
- mpl::false_,
- mpl::false_
- ) {
- BOOST_STATIC_ASSERT(sizeof(Target) == 0);
+ static inline bool
+ do_call(
+ Target & target,
+ Source const & source,
+ mpl::false_,
+ mpl::false_
+ ) {
+ BOOST_STATIC_ASSERT(sizeof(Target) == 0);
 
- return false;
- }
- };
+ return false;
+ }
+ };
 
- } // namespace detail
+} } } // namespace boost::coerce::detail
 
- namespace traits {
+namespace boost { namespace coerce { namespace traits {
 
- template <typename Target, typename Source, typename Enable = void>
- struct as
- : coerce::detail::as<Target, Source> { };
+ template <typename Target, typename Source, typename Enable = void>
+ struct as
+ : coerce::detail::as<Target, Source> { };
 
- } // namespace traits
+} } } // namespace boost::coerce::traits
 
- template <typename Target, typename Source>
- inline Target
- as(Source const & source) {
- Target target;
+namespace boost { namespace coerce {
 
- bool result = traits::as<
- Target, Source
- >::call(target, source);
+ class bad_cast
+ : public std::bad_cast { };
 
- if (!result)
- throw coerce::bad_cast();
+ template <typename Target, typename Source>
+ inline Target
+ as(Source const & source) {
+ Target target;
 
- return target;
- }
+ bool result = traits::as<
+ Target, Source
+ >::call(target, source);
 
- template <typename Target, typename Source>
- inline Target
- as_default(
- Source const & source,
- Target const & default_value = Target()
- ) {
- Target target;
+ if (!result) {
+ throw coerce::bad_cast();
+ }
 
- bool result = traits::as<
- Target, Source
- >::call(target, source);
+ return target;
+ }
 
- if (!result)
- return default_value;
+ template <typename Target, typename Source>
+ inline Target
+ as_default(
+ Source const & source,
+ Target const & default_value = Target()
+ ) {
+ Target target;
+
+ bool result = traits::as<
+ Target, Source
+ >::call(target, source);
 
- return target;
+ if (!result) {
+ return default_value;
         }
 
- } // namespace coerce
+ return target;
+ }
 
-} // namespace boost
+} } // namespace boost::coerce
 
 #endif // BOOST_COERCE_COERCE_HPP

Deleted: sandbox/coerce/boost/coerce/container.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/container.hpp 2011-05-04 09:28:00 EDT (Wed, 04 May 2011)
+++ (empty file)
@@ -1,47 +0,0 @@
-// Copyright Jeroen Habraken 2010 - 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_CONTAINER_HPP
-#define BOOST_COERCE_CONTAINER_HPP
-
-#include <boost/mpl/and.hpp>
-#include <boost/mpl/has_xxx.hpp>
-
-namespace boost {
-
- namespace coerce {
-
- namespace traits {
-
- namespace detail {
-
- BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
- BOOST_MPL_HAS_XXX_TRAIT_DEF(iterator)
- BOOST_MPL_HAS_XXX_TRAIT_DEF(size_type)
- BOOST_MPL_HAS_XXX_TRAIT_DEF(reference)
-
- } // namespace detail
-
- template <typename Type>
- struct is_container_impl
- : mpl::and_<
- detail::has_value_type<Type>,
- detail::has_iterator<Type>,
- detail::has_size_type<Type>,
- detail::has_reference<Type>
- > { };
-
- template <typename Type, typename Enable = void>
- struct is_container
- : is_container_impl<Type> { };
-
- } // namespace traits
-
- } // namespace coerce
-
-} // namespace boost
-
-#endif // BOOST_COERCE_CONTAINER_HPP

Added: sandbox/coerce/boost/coerce/push_back.hpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/boost/coerce/push_back.hpp 2011-05-04 09:28:00 EDT (Wed, 04 May 2011)
@@ -0,0 +1,38 @@
+// 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_PUSH_BACK_HPP
+#define BOOST_COERCE_PUSH_BACK_HPP
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+#include <boost/mpl/bool.hpp>
+#include <boost/type_traits/detail/yes_no_type.hpp>
+
+namespace boost { namespace coerce { namespace detail {
+
+ template <typename Sequence>
+ class has_push_back {
+ template <typename U, void (U::*)(typename U::value_type) = &U::push_back>
+ struct impl { };
+
+ template <typename U>
+ static type_traits::yes_type test(U*, impl<U>* = 0);
+
+ template <typename U>
+ static type_traits::no_type test(...);
+
+ public:
+ BOOST_STATIC_CONSTANT(bool, value =
+ sizeof(test<Sequence>(0)) == sizeof(type_traits::yes_type));
+ typedef mpl::bool_<value> type;
+ };
+
+} } } // namespace boost::coerce::detail
+
+#endif // BOOST_COERCE_PUSH_BACK_HPP

Modified: sandbox/coerce/boost/coerce/reserve.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/reserve.hpp (original)
+++ sandbox/coerce/boost/coerce/reserve.hpp 2011-05-04 09:28:00 EDT (Wed, 04 May 2011)
@@ -8,6 +8,10 @@
 #ifndef BOOST_COERCE_RESERVE_HPP
 #define BOOST_COERCE_RESERVE_HPP
 
+#ifdef _MSC_VER
+#pragma once
+#endif
+
 #include <boost/config.hpp>
 #include <boost/limits.hpp>
 #include <boost/mpl/bool.hpp>
@@ -16,175 +20,167 @@
 
 #include <cstddef> // std::size_t
 
-namespace boost {
-
- namespace coerce {
-
- namespace traits {
+namespace boost { namespace coerce { namespace traits {
 
- template <typename Type>
- struct reserve_size_impl {
- BOOST_STATIC_CONSTANT(std::size_t, value =
- 3 * sizeof(Type) + 1);
- };
-
- template <>
- struct reserve_size_impl<char> {
- BOOST_STATIC_CONSTANT(std::size_t, value = 1);
- };
-
- template <>
- struct reserve_size_impl<wchar_t> {
- BOOST_STATIC_CONSTANT(std::size_t, value = 1);
- };
-
- template <typename Type>
- struct reserve_size_impl_integral {
- BOOST_STATIC_CONSTANT(std::size_t, value =
- std::numeric_limits<Type>::is_signed +
- 1 +
- std::numeric_limits<Type>::digits10);
- };
-
- template <>
- struct reserve_size_impl<int>
- : reserve_size_impl_integral<int> { };
-
- template <>
- struct reserve_size_impl<short>
- : reserve_size_impl_integral<short> { };
-
- template <>
- struct reserve_size_impl<long>
- : reserve_size_impl_integral<long> { };
-
- template <>
- struct reserve_size_impl<unsigned int>
- : reserve_size_impl_integral<unsigned int> { };
-
- template <>
- struct reserve_size_impl<unsigned short>
- : reserve_size_impl_integral<unsigned short> { };
-
- template <>
- struct reserve_size_impl<unsigned long>
- : reserve_size_impl_integral<unsigned long> { };
+ template <typename Type>
+ struct reserve_size_impl {
+ BOOST_STATIC_CONSTANT(std::size_t, value =
+ 3 * sizeof(Type) + 1);
+ };
+
+ template <>
+ struct reserve_size_impl<char> {
+ BOOST_STATIC_CONSTANT(std::size_t, value = 1);
+ };
+
+ template <>
+ struct reserve_size_impl<wchar_t> {
+ BOOST_STATIC_CONSTANT(std::size_t, value = 1);
+ };
+
+ template <typename Type>
+ struct reserve_size_impl_integral {
+ BOOST_STATIC_CONSTANT(std::size_t, value =
+ std::numeric_limits<Type>::is_signed +
+ 1 +
+ std::numeric_limits<Type>::digits10);
+ };
+
+ template <>
+ struct reserve_size_impl<int>
+ : reserve_size_impl_integral<int> { };
+
+ template <>
+ struct reserve_size_impl<short>
+ : reserve_size_impl_integral<short> { };
+
+ template <>
+ struct reserve_size_impl<long>
+ : reserve_size_impl_integral<long> { };
+
+ template <>
+ struct reserve_size_impl<unsigned int>
+ : reserve_size_impl_integral<unsigned int> { };
+
+ template <>
+ struct reserve_size_impl<unsigned short>
+ : reserve_size_impl_integral<unsigned short> { };
+
+ template <>
+ struct reserve_size_impl<unsigned long>
+ : reserve_size_impl_integral<unsigned long> { };
 
 #ifdef BOOST_HAS_LONG_LONG
 
- template <>
- struct reserve_size_impl<boost::long_long_type>
- : reserve_size_impl_integral<boost::long_long_type> { };
-
- template <>
- struct reserve_size_impl<boost::ulong_long_type>
- : reserve_size_impl_integral<boost::ulong_long_type> { };
+ template <>
+ struct reserve_size_impl<boost::long_long_type>
+ : reserve_size_impl_integral<boost::long_long_type> { };
+
+ template <>
+ struct reserve_size_impl<boost::ulong_long_type>
+ : reserve_size_impl_integral<boost::ulong_long_type> { };
 
 #endif // BOOST_HAS_LONG_LONG
 
- template <typename Type>
- struct reserve_size_impl_floating_point {
- BOOST_STATIC_CONSTANT(std::size_t, value =
- std::numeric_limits<Type>::is_signed +
- 8 +
- std::numeric_limits<Type>::digits10);
- };
-
- template <>
- struct reserve_size_impl<float>
- : reserve_size_impl_floating_point<float> { };
-
- template <>
- struct reserve_size_impl<double>
- : reserve_size_impl_floating_point<double> { };
-
- template <>
- struct reserve_size_impl<long double>
- : reserve_size_impl_floating_point<long double> { };
-
- template <>
- struct reserve_size_impl<bool> {
- BOOST_STATIC_CONSTANT(std::size_t, value = 5);
- };
-
- template <typename Type>
- struct reserve_size_impl<boost::optional<Type> >
- : reserve_size_impl<Type> { };
-
- template <typename Type, typename Enable = void>
- struct reserve_size {
- typedef std::size_t type;
-
- static inline type
- call(Type const &) {
- return reserve_size_impl<Type>::value;
- }
- };
-
- } // namespace traits
-
- namespace detail {
-
- template <typename Sequence>
- class has_reserve {
- template <typename U, void (U::*)(typename U::size_type) = &U::reserve>
- struct impl { };
-
- template <typename U>
- static type_traits::yes_type test(U*, impl<U>* = 0);
-
- template <typename U>
- static type_traits::no_type test(...);
-
- public:
- BOOST_STATIC_CONSTANT(bool, value =
- sizeof(test<Sequence>(0)) == sizeof(type_traits::yes_type));
- typedef mpl::bool_<value> type;
- };
-
- template <typename Sequence>
- inline void
- call_reserve_impl(
- Sequence & sequence,
- typename Sequence::size_type const size,
- mpl::true_ const
- ) {
- sequence.reserve(size);
- }
-
- template <typename Sequence>
- inline void
- call_reserve_impl(
- Sequence const &,
- typename Sequence::size_type const,
- mpl::false_ const
- ) {
- // Missing .reserve()
- }
-
- template <typename Sequence>
- inline void
- call_reserve(
- Sequence & sequence,
- typename Sequence::size_type const size
- ) {
- call_reserve_impl(
- sequence, size, typename has_reserve<Sequence>::type());
- }
-
- template <typename Sequence>
- inline void
- call_reserve(
- Sequence const &,
- std::size_t const
- ) {
- // Missing size_type
- }
-
- } // namespace detail
-
- } // namespace coerce
+ template <typename Type>
+ struct reserve_size_impl_floating_point {
+ BOOST_STATIC_CONSTANT(std::size_t, value =
+ std::numeric_limits<Type>::is_signed +
+ 8 +
+ std::numeric_limits<Type>::digits10);
+ };
+
+ template <>
+ struct reserve_size_impl<float>
+ : reserve_size_impl_floating_point<float> { };
+
+ template <>
+ struct reserve_size_impl<double>
+ : reserve_size_impl_floating_point<double> { };
+
+ template <>
+ struct reserve_size_impl<long double>
+ : reserve_size_impl_floating_point<long double> { };
+
+ template <>
+ struct reserve_size_impl<bool> {
+ BOOST_STATIC_CONSTANT(std::size_t, value = 5);
+ };
+
+ template <typename Type>
+ struct reserve_size_impl<boost::optional<Type> >
+ : reserve_size_impl<Type> { };
+
+ template <typename Type, typename Enable = void>
+ struct reserve_size {
+ typedef std::size_t type;
+
+ static inline type
+ call(Type const &) {
+ return reserve_size_impl<Type>::value;
+ }
+ };
+
+} } } // namespace boost::coerce::traits
+
+namespace boost { namespace coerce { namespace detail {
+
+ template <typename Sequence>
+ class has_reserve {
+ template <typename U, void (U::*)(typename U::size_type) = &U::reserve>
+ struct impl { };
+
+ template <typename U>
+ static type_traits::yes_type test(U*, impl<U>* = 0);
+
+ template <typename U>
+ static type_traits::no_type test(...);
+
+ public:
+ BOOST_STATIC_CONSTANT(bool, value =
+ sizeof(test<Sequence>(0)) == sizeof(type_traits::yes_type));
+ typedef mpl::bool_<value> type;
+ };
+
+ template <typename Sequence>
+ inline void
+ call_reserve_impl(
+ Sequence & sequence,
+ typename Sequence::size_type const size,
+ mpl::true_ const
+ ) {
+ sequence.reserve(size);
+ }
+
+ template <typename Sequence>
+ inline void
+ call_reserve_impl(
+ Sequence const &,
+ typename Sequence::size_type const,
+ mpl::false_ const
+ ) {
+ // Missing .reserve()
+ }
+
+ template <typename Sequence>
+ inline void
+ call_reserve(
+ Sequence & sequence,
+ typename Sequence::size_type const size
+ ) {
+ call_reserve_impl(
+ sequence, size, typename has_reserve<Sequence>::type());
+ }
+
+ template <typename Sequence>
+ inline void
+ call_reserve(
+ Sequence const &,
+ std::size_t const
+ ) {
+ // Missing size_type
+ }
 
-} // namespace boost
+} } } // namespace boost::coerce::detail
 
 #endif // BOOST_COERCE_RESERVE_HPP


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