The Artima Developer Community
Sponsored Link

Design Forum
Policy-Based Design

1 reply on 1 page. Most recent reply: Jul 15, 2005 7:00 PM by Maxim Noah Khailo

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Nick Allen

Posts: 1
Nickname: nwa
Registered: Apr, 2005

Policy-Based Design Posted: Apr 23, 2005 9:06 AM
Reply to this message Reply
Advertisement
Being half-way through Andrei Alexandrescu's book, Modern C++ Design, I am intrigued by his policy-based design. I am sure there are many in this forum who are competent with this design approach.

I am in a situation where I would like to pass the type of the host class as a template parameter to one of the host's policy classes. Is this possible?

Consider the following problem. I have a host class that I would like to overload the new and delete operators. A policy should define the characteristics of the creation and deletion of the object.


template < template <class> CreationPolicy >
class Host : public CreationPolicy< ??? >
{
void* operator new() { return CreationPolicy::create(); }
...
};

template <class Type>
class Pool
{
Type* create() { ... }
};

How could I make something like this work? And yes, I realize that the Pool class could just return void*. Let's avoid that solution. I would like to know if there is a general solution to this problem because I believe there are other situations in which it might serve.

Let me thank you in advance for any thoughts.

--Nick


Maxim Noah Khailo

Posts: 25
Nickname: mempko
Registered: Nov, 2004

Re: Policy-Based Design Posted: Jul 15, 2005 7:00 PM
Reply to this message Reply
If I am not mistaken you may be able to do

template < template <class> CreationPolicy >
class Host : public CreationPolicy< Host> { ... }

Because you are dealing with pointers and are not accessing any of the methods of Host within the CreationPolicy then doing so should not be a problem... I could be terribly wrong. Let me know because I am kind of answering this from C++ vacation.

Flat View: This topic has 1 reply on 1 page
Topic: ASP.NET Coding Standard Previous Topic   Next Topic Topic: Populating Tree and List Views

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use