|
Boost : |
Subject: Re: [boost] [cpo-proposal] presentation of the idea
From: Larry Evans (cppljevans_at_[hidden])
Date: 2013-08-13 08:42:03
On 08/12/13 19:07, Santiago Tapia wrote:
> Hi everyone,
>
> I would like to make a proposal for a new library. I only have a draft
> without documentation but I would like to know peoples opinion
> about the idea before making a formal proposal.
>
> The library will be named CPO (containers for polymorphic objects)
> and it will provide containers to store dynamic allocated objects from
> a class hierarchy. I have drafted one container and I have two more
> in process. The cpo library could be an alternative solution for
> boost pointer container library or some other solutions that use pointers.
> In order to understand the idea, I think that the following example of the
> use of the library might be better than a long explanation:
>
> #include <boost/cpo/classifier.hpp>
> #include <iostream>
>
> using namespace boost::cpo;
>
> class base
> {
> public:
> virtual int do_something(int a) const = 0;
> };
>
> class derived_A : public base
> {
> public:
> derived_A(int b) : data(b) {}
> virtual int do_something(int a) const
> {
> return a + data;
> }
> protected:
> int data;
> };
>
> class derived_B : public base
> {
> public:
> derived_B(int b) : data(b) {}
> virtual int do_something(int a) const
> {
> return a - data;
> }
> protected:
> int data;
> };
>
> int main(int argc, char** argv)
> {
> classifier<base, std::allocator> collection;
>
> collection.insert( derived_A(21) );
> collection.insert( derived_B(40) );
>
> classifier<base, std::allocator>::iterator i, e = collection.end();
>
> for ( i = collection.begin(); i != e; ++i )
> {
> const base& x = *i;
> std::cout << x.do_something(6) << std::endl;
> }
>
> return 0;
> }
[snip]
Hi Santiago,
What if the class hierarchy is used to model a graph that
contains cycles. For example, something like a spirit grammar
where a non-terminal on the rhs of a non-terminals definition?
Wouldn't this require some sort of smart pointer or other
garbage collection method with the ability to collect cycles?
-regards,
Larry
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk