Boost logo

Boost Users :

Subject: [Boost-users] does boost has some traits for container inner types which doesn't instantiate the container.
From: Abir Basak (abirbasak_at_[hidden])
Date: 2010-06-20 22:52:16


I have the code given below

#include <boost/array.hpp>
#include <boost/foreach.hpp>
#include <vector>

struct parent;
struct child;
typedef boost::array<child,5> childs_t;
typedef std::vector<parent> parents_t;
//typedef boost::array<parent,6> parents_t; //1)

typedef parent* parent_pointer;
//typedef parents_t::pointer parent_pointer; //2)

struct child
{
    parent_pointer par;
};

struct parent
{
    childs_t childs;
};
int main()
{
    parents_t all(6);
    BOOST_FOREACH(parent& p,all)
    {
        childs_t& ch = p.childs;
        BOOST_FOREACH(child& c,ch )
        {
            c.par = &p;
        }
    }
}

I want to use the parent_pointer in a generic way as nested typedef of
parents_t so that if needed I can have a different pointer type than parent*
as the commented code shown in 2) .That is probably not permitted as vector
of incomplete type is illegal, though it actually might work. But the same
is not possible with boost::array as in 1) , as it needs complete type
parent. This is because compiler tries to instantiate boost::array while
accessing inner type pointer (Though actually boost::array doesn't have
pointer , I can replace it by iterator, probably c++0x has pointer typedef
). On the other hand my requirement is only pointer/iterator which may not
depend on complete type parent, and none of parent or child otherwise has
even problem with vector, array or any other container.
  Is it possible (or boost has) some portable wrapper over the inner typedef
of the containers which doesn't tries to instantiate the container which
might depend on completeness of the type, so that I can just change the
typedef of container / allocator in one location and rest will "just work".
Assumption is container nested types like value_type, pointer, reference,
size_type, difference_type, iterator and const counterparts doesn't depend
on completeness f the parametre T.
Though this question is not entirely boost related, it may not be entirely
uncorrelated.

Thanks
abir

-- 
Abir Basak
B. Tech , IIT KGP
Research Engineer & Technology Lead,
Read Ink Technologies


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net