diff --git a/include/boost/fusion/adapted/adt/detail/extension.hpp b/include/boost/fusion/adapted/adt/detail/extension.hpp index 50c40cf3..0a43ffca 100644 --- a/include/boost/fusion/adapted/adt/detail/extension.hpp +++ b/include/boost/fusion/adapted/adt/detail/extension.hpp @@ -12,13 +12,28 @@ #include #include +#include +#include -namespace boost { namespace fusion { namespace detail -{ - template - struct get_identity - : remove_const::type> - {}; -}}} +namespace boost { namespace fusion +{ + namespace detail + { + template + struct get_identity + : remove_const::type> + {}; + } + + namespace extension + { + // Overload as_const() to unwrap adt_attribute_proxy. + template + typename adt_attribute_proxy::type as_const(const adt_attribute_proxy& proxy) + { + return proxy.get(); + } + } +}} #endif diff --git a/include/boost/fusion/sequence/comparison/detail/equal_to.hpp b/include/boost/fusion/sequence/comparison/detail/equal_to.hpp index 3e15e63a..56cfe1b2 100644 --- a/include/boost/fusion/sequence/comparison/detail/equal_to.hpp +++ b/include/boost/fusion/sequence/comparison/detail/equal_to.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace boost { namespace fusion { namespace detail { @@ -32,7 +33,7 @@ namespace boost { namespace fusion { namespace detail static bool call(I1 const& a, I2 const& b, mpl::false_) { - return *a == *b + return extension::as_const(*a) == extension::as_const(*b) && call(fusion::next(a), fusion::next(b)); } diff --git a/include/boost/fusion/sequence/comparison/detail/greater.hpp b/include/boost/fusion/sequence/comparison/detail/greater.hpp index b4c4b087..e6128776 100644 --- a/include/boost/fusion/sequence/comparison/detail/greater.hpp +++ b/include/boost/fusion/sequence/comparison/detail/greater.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace boost { namespace fusion { namespace detail { @@ -32,8 +33,9 @@ namespace boost { namespace fusion { namespace detail static bool call(I1 const& a, I2 const& b, mpl::false_) { - return *a > *b || - (!(*b > *a) && call(fusion::next(a), fusion::next(b))); + return extension::as_const(*a) > extension::as_const(*b) || + (!(extension::as_const(*b) > extension::as_const(*a)) && + call(fusion::next(a), fusion::next(b))); } template diff --git a/include/boost/fusion/sequence/comparison/detail/greater_equal.hpp b/include/boost/fusion/sequence/comparison/detail/greater_equal.hpp index f3eccd5d..6d91e27b 100644 --- a/include/boost/fusion/sequence/comparison/detail/greater_equal.hpp +++ b/include/boost/fusion/sequence/comparison/detail/greater_equal.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace boost { namespace fusion { namespace detail { @@ -32,8 +33,9 @@ namespace boost { namespace fusion { namespace detail static bool call(I1 const& a, I2 const& b, mpl::false_) { - return *a >= *b - && (!(*b >= *a) || call(fusion::next(a), fusion::next(b))); + return extension::as_const(*a) >= extension::as_const(*b) + && (!(extension::as_const(*b) >= extension::as_const(*a)) || + call(fusion::next(a), fusion::next(b))); } template diff --git a/include/boost/fusion/sequence/comparison/detail/less.hpp b/include/boost/fusion/sequence/comparison/detail/less.hpp index 4957d7bf..1342bb14 100644 --- a/include/boost/fusion/sequence/comparison/detail/less.hpp +++ b/include/boost/fusion/sequence/comparison/detail/less.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace boost { namespace fusion { namespace detail { @@ -32,8 +33,9 @@ namespace boost { namespace fusion { namespace detail static bool call(I1 const& a, I2 const& b, mpl::false_) { - return *a < *b || - (!(*b < *a) && call(fusion::next(a), fusion::next(b))); + return extension::as_const(*a) < extension::as_const(*b) || + (!(extension::as_const(*b) < extension::as_const(*a)) && + call(fusion::next(a), fusion::next(b))); } template diff --git a/include/boost/fusion/sequence/comparison/detail/less_equal.hpp b/include/boost/fusion/sequence/comparison/detail/less_equal.hpp index 08fe9ec3..5683849a 100644 --- a/include/boost/fusion/sequence/comparison/detail/less_equal.hpp +++ b/include/boost/fusion/sequence/comparison/detail/less_equal.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace boost { namespace fusion { namespace detail { @@ -32,8 +33,9 @@ namespace boost { namespace fusion { namespace detail static bool call(I1 const& a, I2 const& b, mpl::false_) { - return *a <= *b - && (!(*b <= *a) || call(fusion::next(a), fusion::next(b))); + return extension::as_const(*a) <= extension::as_const(*b) + && (!(extension::as_const(*b) <= extension::as_const(*a)) || + call(fusion::next(a), fusion::next(b))); } template diff --git a/include/boost/fusion/sequence/comparison/detail/not_equal_to.hpp b/include/boost/fusion/sequence/comparison/detail/not_equal_to.hpp index ac54dfb7..77c23508 100644 --- a/include/boost/fusion/sequence/comparison/detail/not_equal_to.hpp +++ b/include/boost/fusion/sequence/comparison/detail/not_equal_to.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace boost { namespace fusion { namespace detail { @@ -32,7 +33,7 @@ namespace boost { namespace fusion { namespace detail static bool call(I1 const& a, I2 const& b, mpl::false_) { - return *a != *b + return extension::as_const(*a) != extension::as_const(*b) || call(fusion::next(a), fusion::next(b)); } diff --git a/include/boost/fusion/support.hpp b/include/boost/fusion/support.hpp index 765b777d..50bf924f 100644 --- a/include/boost/fusion/support.hpp +++ b/include/boost/fusion/support.hpp @@ -19,5 +19,6 @@ #include #include #include +#include #endif diff --git a/include/boost/fusion/support/as_const.hpp b/include/boost/fusion/support/as_const.hpp new file mode 100644 index 00000000..bb2a96a6 --- /dev/null +++ b/include/boost/fusion/support/as_const.hpp @@ -0,0 +1,26 @@ +/*============================================================================= + Copyright (c) 2012 Nathan Ridge + + 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_FUSION_SUPPORT_AS_CONST_HPP +#define BOOST_FUSION_SUPPORT_AS_CONST_HPP + +namespace boost { namespace fusion { namespace extension +{ + // A customization point that allows certain wrappers around + // Fusion sequence elements (e.g. adt_attribute_proxy) to be + // unwrapped in contexts where the element only needs to be + // read. The library wraps accesses to Fusion elements in + // such contexts with calls to this function. Users can + // specialize this function for their own wrappers. + template + const T& as_const(const T& obj) + { + return obj; + } + +}}} + +#endif