I wrote an operator<< specialization that handles boost::multi_array and uses ConstMultiArrayConcept to work with both an external array and subarrays. However, I wonder why the concepts of multi_array have the template argument std::size_t NumDims , since it can simply be extracted from multi_array . The only use of NumDims in ConstMultiArrayConcept is the recursion depth argument for idgen_helper , which checks slicing.
For reference, here is the header for multi_array : http://www.boost.org/doc/libs/1_51_0/boost/multi_array/concept_checks.hpp
And here is my overloaded operator<<
template <typename CharT, typename Traits, typename MultiArrayT> BOOST_CONCEPT_REQUIRES( ((boost::multi_array_concepts::ConstMultiArrayConcept<MultiArrayT, MultiArrayT::dimensionality>)), (std::basic_ostream<CharT, Traits>&)) // return type operator <<( std::basic_ostream<CharT, Traits>& os, MultiArrayT const& ary ) { typename std::basic_ostream<CharT, Traits>::sentry opfx( os ); if ( opfx ) { boost::multi_array_types::size_type const* sizes = ary.shape(); // using Mathematica array notation os << "{"; for ( int i = 0; i < sizes[0]; ++i ) { if ( i > 0 ) os << ", "; // verbose just to keep the types apparent typedef typename MultiArrayT::const_reference subType; subType item = ary[i]; os << item; } os << "}\n"; } return os; }
This specialization works, but I have to miss something in my understanding. Any clues would be appreciated.
c ++ boost c ++ - concepts boost-multi-array
Stonewall ballard
source share