[fusion][mpl][array] making boost array a conforming mpl sequence (through fusion)

Hi, I tried to make boost::array a conforming MPL sequence by including: #include <boost/fusion/adapted/array.hpp> // makes array a conforming fusion sequence #include <boost/fusion/mpl.hpp> // makes fusion sequences conforming MPL sequences but, typedef boost::array<int, 1> array; assert(boost::mpl::is_sequence<array>::type::value); // fails Am I misinterpreting the fusion documentation in expecting that this should work? Is there another way of making boost::array an mpl sequence? TIA, Stjepan

Stjepan Rajko wrote:
Hi,
I tried to make boost::array a conforming MPL sequence by including:
#include <boost/fusion/adapted/array.hpp> // makes array a conforming fusion sequence #include <boost/fusion/mpl.hpp> // makes fusion sequences conforming MPL sequences
but,
typedef boost::array<int, 1> array; assert(boost::mpl::is_sequence<array>::type::value); // fails
Am I misinterpreting the fusion documentation in expecting that this should work? Is there another way of making boost::array an mpl sequence?
I think the basic problem is that is_sequence is not really part of the requirements for an MPL sequence. You don't have to be a conforming MPL sequences. I am not sure how to best approach this. Perhaps the MPL authors have a better idea? Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net

On Tue, Feb 10, 2009 at 8:10 PM, Joel de Guzman <joel@boost-consulting.com> wrote:
Stjepan Rajko wrote:
Hi,
I tried to make boost::array a conforming MPL sequence by including:
#include <boost/fusion/adapted/array.hpp> // makes array a conforming fusion sequence #include <boost/fusion/mpl.hpp> // makes fusion sequences conforming MPL sequences
but,
typedef boost::array<int, 1> array; assert(boost::mpl::is_sequence<array>::type::value); // fails
Am I misinterpreting the fusion documentation in expecting that this should work? Is there another way of making boost::array an mpl sequence?
I think the basic problem is that is_sequence is not really part of the requirements for an MPL sequence. You don't have to be a conforming MPL sequences. I am not sure how to best approach this. Perhaps the MPL authors have a better idea?
Joel, thanks for your response. My original problem was with a simple application of mpl::transform, which produced an error stating: no class template named 'apply' in 'struct boost::mpl::clear_impl<boost::mpl::non_sequence_tag> The above code was just an attempt at a minimal example. Also, the same above code passes if boost::array<int, 1> is replaced with fusion::vector<int>, so my impression is that there is something happening for fusion-proper sequences that is not happening for the adapted array. I can provide a minimal example that involves mpl::transform if that is helpful, but I imagine (perhaps erroneously) that whatever fixes mpl::is_sequence would also fix my problem with mpl::transform. Stjepan

Joel, On Tue, Feb 10, 2009 at 8:10 PM, Joel de Guzman <joel@boost-consulting.com> wrote:
Stjepan Rajko wrote:
Hi,
I tried to make boost::array a conforming MPL sequence by including:
#include <boost/fusion/adapted/array.hpp> // makes array a conforming fusion sequence #include <boost/fusion/mpl.hpp> // makes fusion sequences conforming MPL sequences
but,
typedef boost::array<int, 1> array; assert(boost::mpl::is_sequence<array>::type::value); // fails
Am I misinterpreting the fusion documentation in expecting that this should work? Is there another way of making boost::array an mpl sequence?
I think the basic problem is that is_sequence is not really part of the requirements for an MPL sequence. You don't have to be a conforming MPL sequences. I am not sure how to best approach this. Perhaps the MPL authors have a better idea?
I was able to get the fusion-adapted boost::array to be a conforming mpl sequence by adding: namespace boost { namespace mpl { template<typename T, std::size_t N> struct tag<boost::array<T,N> > { typedef boost::fusion::fusion_sequence_tag type; }; template<typename T, std::size_t N> struct sequence_tag<boost::array<T,N> > { typedef boost::fusion::fusion_sequence_tag type; }; }} Best, Stjepan

On Thu, Feb 12, 2009 at 10:12 AM, Stjepan Rajko <stjepan.rajko@gmail.com> wrote:
I was able to get the fusion-adapted boost::array to be a conforming mpl sequence by adding:
namespace boost { namespace mpl {
template<typename T, std::size_t N> struct tag<boost::array<T,N> > { typedef boost::fusion::fusion_sequence_tag type; };
template<typename T, std::size_t N> struct sequence_tag<boost::array<T,N> > { typedef boost::fusion::fusion_sequence_tag type; };
}}
Furthermore, I am able to execute a transform on the array after adding this: http://pastebin.com/f40b33e1d This works perfectly, that is, minus the fact that adding it in gives me some really bizarre compilation errors (gcc 4.0.1, darwin): /Development/boost/boost/fusion/adapted/array/array_iterator.hpp: In instantiation of 'boost::fusion::array_iterator<boost::array<ame::patterns::normal_model_state, 12ul>, 0>': ... /Development/boost/boost/fusion/adapted/array/array_iterator.hpp:29: error: 'boost::array<ame::patterns::normal_model_state, 12ul>::<anonymous enum>' is/uses anonymous type /Development/boost/boost/fusion/adapted/array/array_iterator.hpp:29: error: trying to instantiate 'template<class Seq1, class Seq2> struct boost::fusion::detail::enable_comparison' The offending line in array_iterator is: BOOST_MPL_ASSERT_RELATION(Pos, <=, Array::static_size); Commenting out that line results in a successful compile, and the program runs as expected. I would really appreciate it if someone could help me out here, I am in total dark as to why the BOOST_MPL_ASSERT_RELATION is not working correctly, and what fusion::detail::enable_comparison has to do with anything. TIA, Stjepan

AMDG Stjepan Rajko wrote:
/Development/boost/boost/fusion/adapted/array/array_iterator.hpp:29: error: 'boost::array<ame::patterns::normal_model_state, 12ul>::<anonymous enum>' is/uses anonymous type /Development/boost/boost/fusion/adapted/array/array_iterator.hpp:29: error: trying to instantiate 'template<class Seq1, class Seq2> struct boost::fusion::detail::enable_comparison'
The offending line in array_iterator is: BOOST_MPL_ASSERT_RELATION(Pos, <=, Array::static_size);
Commenting out that line results in a successful compile, and the program runs as expected.
I would really appreciate it if someone could help me out here, I am in total dark as to why the BOOST_MPL_ASSERT_RELATION is not working correctly, and what fusion::detail::enable_comparison has to do with anything.
Wild guess: try casting Array::static_size to int? In Christ, Steven Watanabe

On Thu, Feb 12, 2009 at 7:52 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Stjepan Rajko wrote:
/Development/boost/boost/fusion/adapted/array/array_iterator.hpp:29: error: 'boost::array<ame::patterns::normal_model_state, 12ul>::<anonymous enum>' is/uses anonymous type /Development/boost/boost/fusion/adapted/array/array_iterator.hpp:29: error: trying to instantiate 'template<class Seq1, class Seq2> struct boost::fusion::detail::enable_comparison'
The offending line in array_iterator is: BOOST_MPL_ASSERT_RELATION(Pos, <=, Array::static_size);
Commenting out that line results in a successful compile, and the program runs as expected.
I would really appreciate it if someone could help me out here, I am in total dark as to why the BOOST_MPL_ASSERT_RELATION is not working correctly, and what fusion::detail::enable_comparison has to do with anything.
Wild guess: try casting Array::static_size to int?
That worked - thanks! Created ticket https://svn.boost.org/trac/boost/ticket/2761 Stjepan
participants (3)
-
Joel de Guzman
-
Steven Watanabe
-
Stjepan Rajko