Boost logo

Boost :

From: Peder Holt (peder.holt_at_[hidden])
Date: 2005-05-27 04:47:28


On 5/27/05, Alexander Nasonov <alnsn-boost_at_[hidden]> wrote:
> Arkadiy Vertleyb <vertleyb <at> hotmail.com> writes:
>
> > I think they are:
> >
> > template<class T>
> > char foo(vector<T>& v)[id1][id2][id3];
> >
> > But how would this work? This array type will stay inside the function.
>
> #include <boost/mpl/assert.hpp>
> #include <boost/mpl/equal.hpp>
> #include <boost/mpl/vector_c.hpp>
>
> char (&foo())[9][8][7][6];
>
> int main()
> {
> using namespace boost::mpl;
>
> typedef vector_c<
> int
> , sizeof(foo()) / sizeof(foo()[0])
> , sizeof(foo()[0]) / sizeof(foo()[0][0])
> , sizeof(foo()[0][0]) / sizeof(foo()[0][0][0])
> , sizeof(foo()[0][0][0]) / sizeof(foo()[0][0][0][0])
> > vec;
>
> BOOST_MPL_ASSERT(( equal< vec, vector_c<int,9,8,7,6> > ));
> }
>
> Sizes may become very huge, though.

If you replace your function with:
char (&foo())[900][800][700][600];
you will get an overflow when calculating e.g. sizeof(foo()) /
sizeof(foo()[0]),
and the result will be garbage.

>
> > We need a function to return the object of certain _size_
> > in order to pass it outside...
>
> I don't understand it.
>
> --
> Alexander Nasonov
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk