|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r78463 - in trunk/boost/fusion: algorithm/auxiliary algorithm/iteration algorithm/query algorithm/transformation view/iterator_range/detail
From: joel_at_[hidden]
Date: 2012-05-13 20:37:23
Author: djowel
Date: 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
New Revision: 78463
URL: http://svn.boost.org/trac/boost/changeset/78463
Log:
Patches from Nathan Ridge using SFINAE to disable the Fusion algorithms for non-{Fusion sequence} types
Text files modified:
trunk/boost/fusion/algorithm/auxiliary/copy.hpp | 13 ++++++++++++-
trunk/boost/fusion/algorithm/iteration/accumulate.hpp | 16 ++++++++++++++--
trunk/boost/fusion/algorithm/iteration/accumulate_fwd.hpp | 15 +++++++++++++--
trunk/boost/fusion/algorithm/iteration/for_each.hpp | 16 ++++++++++++++--
trunk/boost/fusion/algorithm/iteration/for_each_fwd.hpp | 17 +++++++++++++++--
trunk/boost/fusion/algorithm/query/count.hpp | 9 ++++++++-
trunk/boost/fusion/algorithm/query/count_if.hpp | 9 ++++++++-
trunk/boost/fusion/algorithm/transformation/erase.hpp | 35 +++++++++++++++++++++++++++++++----
trunk/boost/fusion/algorithm/transformation/insert.hpp | 10 ++++++++--
trunk/boost/fusion/algorithm/transformation/push_back.hpp | 9 ++++++++-
trunk/boost/fusion/algorithm/transformation/push_front.hpp | 9 ++++++++-
trunk/boost/fusion/algorithm/transformation/replace.hpp | 9 ++++++++-
trunk/boost/fusion/algorithm/transformation/replace_if.hpp | 8 +++++++-
trunk/boost/fusion/algorithm/transformation/reverse.hpp | 9 ++++++++-
trunk/boost/fusion/view/iterator_range/detail/segmented_iterator_range.hpp | 14 ++++++++++++--
15 files changed, 174 insertions(+), 24 deletions(-)
Modified: trunk/boost/fusion/algorithm/auxiliary/copy.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/auxiliary/copy.hpp (original)
+++ trunk/boost/fusion/algorithm/auxiliary/copy.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -11,8 +11,11 @@
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/sequence/comparison/detail/equal_to.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
#include <boost/config.hpp>
#include <boost/static_assert.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/ice.hpp>
#if defined (BOOST_MSVC)
# pragma warning(push)
@@ -54,7 +57,15 @@
}
template <typename Seq1, typename Seq2>
- inline void
+ inline
+ typename
+ enable_if_c<
+ type_traits::ice_and<
+ traits::is_sequence<Seq1>::value
+ , traits::is_sequence<Seq2>::value
+ >::value,
+ void
+ >::type
copy(Seq1 const& src, Seq2& dest)
{
BOOST_STATIC_ASSERT(
Modified: trunk/boost/fusion/algorithm/iteration/accumulate.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/iteration/accumulate.hpp (original)
+++ trunk/boost/fusion/algorithm/iteration/accumulate.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -9,6 +9,8 @@
#include <boost/fusion/algorithm/iteration/accumulate_fwd.hpp>
#include <boost/fusion/algorithm/iteration/fold.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
namespace boost { namespace fusion
{
@@ -23,14 +25,24 @@
}
template <typename Sequence, typename State, typename F>
- inline typename result_of::accumulate<Sequence, State const, F>::type
+ inline
+ typename
+ lazy_enable_if<
+ traits::is_sequence<Sequence>
+ , result_of::accumulate<Sequence, State const, F>
+ >::type
accumulate(Sequence& seq, State const& state, F f)
{
return fusion::fold(seq, state, f);
}
template <typename Sequence, typename State, typename F>
- inline typename result_of::accumulate<Sequence const, State const, F>::type
+ inline
+ typename
+ lazy_enable_if<
+ traits::is_sequence<Sequence>
+ , result_of::accumulate<Sequence const, State const, F>
+ >::type
accumulate(Sequence const& seq, State const& state, F f)
{
return fusion::fold(seq, state, f);
Modified: trunk/boost/fusion/algorithm/iteration/accumulate_fwd.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/iteration/accumulate_fwd.hpp (original)
+++ trunk/boost/fusion/algorithm/iteration/accumulate_fwd.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -7,6 +7,9 @@
#if !defined(BOOST_FUSION_ACCUMULATE_FWD_HPP_INCLUDED)
#define BOOST_FUSION_ACCUMULATE_FWD_HPP_INCLUDED
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
+
namespace boost { namespace fusion
{
namespace result_of
@@ -16,11 +19,19 @@
}
template <typename Sequence, typename State, typename F>
- typename result_of::accumulate<Sequence, State const, F>::type
+ typename
+ lazy_enable_if<
+ traits::is_sequence<Sequence>
+ , result_of::accumulate<Sequence, State const, F>
+ >::type
accumulate(Sequence& seq, State const& state, F f);
template <typename Sequence, typename State, typename F>
- typename result_of::accumulate<Sequence const, State const, F>::type
+ typename
+ lazy_enable_if<
+ traits::is_sequence<Sequence>
+ , result_of::accumulate<Sequence const, State const, F>
+ >::type
accumulate(Sequence const& seq, State const& state, F f);
}}
Modified: trunk/boost/fusion/algorithm/iteration/for_each.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/iteration/for_each.hpp (original)
+++ trunk/boost/fusion/algorithm/iteration/for_each.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -11,6 +11,8 @@
#include <boost/fusion/algorithm/iteration/detail/for_each.hpp>
#include <boost/fusion/algorithm/iteration/detail/segmented_for_each.hpp>
#include <boost/fusion/support/is_segmented.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
namespace boost { namespace fusion
{
@@ -24,14 +26,24 @@
}
template <typename Sequence, typename F>
- inline void
+ inline
+ typename
+ enable_if<
+ traits::is_sequence<Sequence>
+ , void
+ >::type
for_each(Sequence& seq, F const& f)
{
detail::for_each(seq, f, typename traits::is_segmented<Sequence>::type());
}
template <typename Sequence, typename F>
- inline void
+ inline
+ typename
+ enable_if<
+ traits::is_sequence<Sequence>
+ , void
+ >::type
for_each(Sequence const& seq, F const& f)
{
detail::for_each(seq, f, typename traits::is_segmented<Sequence>::type());
Modified: trunk/boost/fusion/algorithm/iteration/for_each_fwd.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/iteration/for_each_fwd.hpp (original)
+++ trunk/boost/fusion/algorithm/iteration/for_each_fwd.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -7,6 +7,9 @@
#if !defined(BOOST_FUSION_FOR_EACH_FWD_HPP_INCLUDED)
#define BOOST_FUSION_FOR_EACH_FWD_HPP_INCLUDED
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
+
namespace boost { namespace fusion
{
namespace result_of
@@ -16,11 +19,21 @@
}
template <typename Sequence, typename F>
- void
+ inline
+ typename
+ enable_if<
+ traits::is_sequence<Sequence>
+ , void
+ >::type
for_each(Sequence& seq, F const& f);
template <typename Sequence, typename F>
- void
+ inline
+ typename
+ enable_if<
+ traits::is_sequence<Sequence>
+ , void
+ >::type
for_each(Sequence const& seq, F const& f);
}}
Modified: trunk/boost/fusion/algorithm/query/count.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/query/count.hpp (original)
+++ trunk/boost/fusion/algorithm/query/count.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -10,6 +10,8 @@
#include <boost/fusion/algorithm/query/count_if.hpp>
#include <boost/fusion/algorithm/query/detail/count.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
namespace boost { namespace fusion
{
@@ -23,7 +25,12 @@
}
template <typename Sequence, typename T>
- inline int
+ inline
+ typename
+ enable_if<
+ traits::is_sequence<Sequence>
+ , int
+ >::type
count(Sequence const& seq, T const& x)
{
detail::count_compare<T> f(x);
Modified: trunk/boost/fusion/algorithm/query/count_if.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/query/count_if.hpp (original)
+++ trunk/boost/fusion/algorithm/query/count_if.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -10,6 +10,8 @@
#include <boost/fusion/algorithm/query/detail/count_if.hpp>
#include <boost/fusion/support/category_of.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
namespace boost { namespace fusion
{
@@ -23,7 +25,12 @@
}
template <typename Sequence, typename F>
- inline int
+ inline
+ typename
+ enable_if<
+ traits::is_sequence<Sequence>
+ , int
+ >::type
count_if(Sequence const& seq, F f)
{
return detail::count_if(
Modified: trunk/boost/fusion/algorithm/transformation/erase.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/transformation/erase.hpp (original)
+++ trunk/boost/fusion/algorithm/transformation/erase.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -16,6 +16,9 @@
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/adapted/mpl/mpl_iterator.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/mpl/if.hpp>
namespace boost { namespace fusion
{
@@ -53,18 +56,38 @@
}
};
+ struct use_default;
+
+ template <class T, class Default>
+ struct fusion_default_help
+ : mpl::if_<
+ is_same<T, use_default>
+ , Default
+ , T
+ >
+ {
+ };
+
template <
typename Sequence
, typename First
- , typename Last = typename compute_erase_last<Sequence, First>::type>
+ , typename Last = use_default>
struct erase
{
typedef typename result_of::begin<Sequence>::type seq_first_type;
typedef typename result_of::end<Sequence>::type seq_last_type;
BOOST_STATIC_ASSERT((!result_of::equal_to<seq_first_type, seq_last_type>::value));
- typedef typename convert_iterator<First>::type first_type;
- typedef typename convert_iterator<Last>::type last_type;
+ typedef First FirstType;
+ typedef typename
+ fusion_default_help<
+ Last
+ , typename compute_erase_last<Sequence, First>::type
+ >::type
+ LastType;
+
+ typedef typename convert_iterator<FirstType>::type first_type;
+ typedef typename convert_iterator<LastType>::type last_type;
typedef iterator_range<seq_first_type, first_type> left_type;
typedef iterator_range<last_type, seq_last_type> right_type;
typedef joint_view<left_type, right_type> type;
@@ -72,7 +95,11 @@
}
template <typename Sequence, typename First>
- typename result_of::erase<Sequence const, First>::type
+ typename
+ lazy_enable_if<
+ traits::is_sequence<Sequence>
+ , typename result_of::erase<Sequence const, First>
+ >::type
erase(Sequence const& seq, First const& first)
{
typedef result_of::erase<Sequence const, First> result_of;
Modified: trunk/boost/fusion/algorithm/transformation/insert.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/transformation/insert.hpp (original)
+++ trunk/boost/fusion/algorithm/transformation/insert.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -16,6 +16,8 @@
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/adapted/mpl/mpl_iterator.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
namespace boost { namespace fusion
{
@@ -38,8 +40,12 @@
}
template <typename Sequence, typename Position, typename T>
- inline typename result_of::insert<
- Sequence const, Position, T>::type
+ inline
+ typename
+ lazy_enable_if<
+ traits::is_sequence<Sequence>
+ , result_of::insert<Sequence const, Position, T>
+ >::type
insert(Sequence const& seq, Position const& pos, T const& x)
{
typedef result_of::insert<
Modified: trunk/boost/fusion/algorithm/transformation/push_back.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/transformation/push_back.hpp (original)
+++ trunk/boost/fusion/algorithm/transformation/push_back.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -10,6 +10,8 @@
#include <boost/fusion/support/detail/as_fusion_element.hpp>
#include <boost/fusion/view/joint_view/joint_view.hpp>
#include <boost/fusion/view/single_view/single_view.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
namespace boost { namespace fusion
{
@@ -24,7 +26,12 @@
}
template <typename Sequence, typename T>
- inline typename result_of::push_back<Sequence const, T>::type
+ inline
+ typename
+ lazy_enable_if<
+ traits::is_sequence<Sequence>
+ , result_of::push_back<Sequence const, T>
+ >::type
push_back(Sequence const& seq, T const& x)
{
typedef typename result_of::push_back<Sequence const, T> push_back;
Modified: trunk/boost/fusion/algorithm/transformation/push_front.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/transformation/push_front.hpp (original)
+++ trunk/boost/fusion/algorithm/transformation/push_front.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -10,6 +10,8 @@
#include <boost/fusion/support/detail/as_fusion_element.hpp>
#include <boost/fusion/view/joint_view/joint_view.hpp>
#include <boost/fusion/view/single_view/single_view.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
namespace boost { namespace fusion
{
@@ -24,7 +26,12 @@
}
template <typename Sequence, typename T>
- inline typename result_of::push_front<Sequence const, T>::type
+ inline
+ typename
+ lazy_enable_if<
+ traits::is_sequence<Sequence>
+ , result_of::push_front<Sequence const, T>
+ >::type
push_front(Sequence const& seq, T const& x)
{
typedef typename result_of::push_front<Sequence const, T> push_front;
Modified: trunk/boost/fusion/algorithm/transformation/replace.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/transformation/replace.hpp (original)
+++ trunk/boost/fusion/algorithm/transformation/replace.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -9,6 +9,8 @@
#include <boost/fusion/view/transform_view/transform_view.hpp>
#include <boost/fusion/algorithm/transformation/detail/replace.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
namespace boost { namespace fusion
{
@@ -22,7 +24,12 @@
}
template <typename Sequence, typename T>
- inline typename result_of::replace<Sequence const, T>::type
+ inline
+ typename
+ enable_if<
+ traits::is_sequence<Sequence>
+ , typename result_of::replace<Sequence const, T>::type
+ >::type
replace(Sequence const& seq, T const& old_value, T const& new_value)
{
typedef typename result_of::replace<Sequence const, T>::type result;
Modified: trunk/boost/fusion/algorithm/transformation/replace_if.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/transformation/replace_if.hpp (original)
+++ trunk/boost/fusion/algorithm/transformation/replace_if.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -9,6 +9,7 @@
#include <boost/fusion/view/transform_view/transform_view.hpp>
#include <boost/fusion/algorithm/transformation/detail/replace_if.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
@@ -24,7 +25,12 @@
}
template <typename Sequence, typename F, typename T>
- inline typename result_of::replace_if<Sequence const, F, T>::type
+ inline
+ typename
+ enable_if<
+ traits::is_sequence<Sequence>
+ , typename result_of::replace_if<Sequence const, F, T>::type
+ >::type
replace_if(Sequence const& seq, F pred, T const& new_value)
{
typedef typename result_of::replace_if<Sequence const, F, T>::type result;
Modified: trunk/boost/fusion/algorithm/transformation/reverse.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/transformation/reverse.hpp (original)
+++ trunk/boost/fusion/algorithm/transformation/reverse.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -8,6 +8,8 @@
#define FUSION_REVERSE_07212005_1230
#include <boost/fusion/view/reverse_view/reverse_view.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
namespace boost { namespace fusion
{
@@ -21,7 +23,12 @@
}
template <typename Sequence>
- inline reverse_view<Sequence const>
+ inline
+ typename
+ enable_if<
+ traits::is_sequence<Sequence>
+ , reverse_view<Sequence const>
+ >::type
reverse(Sequence const& view)
{
return reverse_view<Sequence const>(view);
Modified: trunk/boost/fusion/view/iterator_range/detail/segmented_iterator_range.hpp
==============================================================================
--- trunk/boost/fusion/view/iterator_range/detail/segmented_iterator_range.hpp (original)
+++ trunk/boost/fusion/view/iterator_range/detail/segmented_iterator_range.hpp 2012-05-13 20:37:21 EDT (Sun, 13 May 2012)
@@ -21,6 +21,8 @@
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/fusion/container/list/detail/reverse_cons.hpp>
#include <boost/fusion/iterator/detail/segment_sequence.hpp>
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/utility/enable_if.hpp>
// Invariants:
// - Each segmented iterator has a stack
@@ -45,11 +47,19 @@
}
template <typename Sequence, typename T>
- typename result_of::push_back<Sequence const, T>::type
+ typename
+ lazy_enable_if<
+ traits::is_sequence<Sequence>
+ , result_of::push_back<Sequence const, T>
+ >::type
push_back(Sequence const& seq, T const& x);
template <typename Sequence, typename T>
- typename result_of::push_front<Sequence const, T>::type
+ typename
+ lazy_enable_if<
+ traits::is_sequence<Sequence>
+ , result_of::push_front<Sequence const, T>
+ >::type
push_front(Sequence const& seq, T const& x);
}}
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