
On Jan 24, 3:19 pm, Steven Watanabe <watanab...@gmail.com> wrote:
template<int M, int N, class Storage = boost::mpl::identity<> > class regular_grid { typedef boost::array< boost::array<double, M>, N > array_type; typedef typename boost::mpl::apply<Storage, array_type>::type storage_type; storage_type axis_; // use axis
}; typedef boost::add_reference<boost::add_const<boost::mpl::_1> > reference_policy; typedef boost::mpl::identity<> copy_policy;
regular_grid<2, 3, reference_policy> g; In Christ, Steven Watanabe
A followup if anyone else is using this code: Steven: Your code worked beautifully, but it turned out that I also needed an assignment operator (which fails due to the const on the ref). For now, I did the following: typedef boost::add_reference<boost::add_const<boost::mpl::_1> > > const_reference_policy; typedef boost::add_reference<<boost::mpl::_1 > > reference_policy; Things *kind of* work now for the default assignment operator generated by the compiler. I can now create a new item and then use the copy assignment(if they have the same storage policy). Things like... regular_grid <2,3> interp( f_values); //The default is the new non- const reference_policy. regular_grid <2,3> interp3 = interp; //Works! Also works for the copy_policy interp3 = interp; //Fails! Also fails for the copy_policy Lower priority for me, but assignment will only work for 2 grids of type ref or 2 of type value. What is the best way to write the assignment operator to allow assignment between the different policy types? (combinations except assignment to a const_reference_policy of course) (my apologies for misspelling your name previously) Thanks, Jesse