473,320 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Design of pointer_to<T> templates

Hi,
I have determined that replacing T* by pointer_to<T> is a good idea:

(a) If the template signature is actually

template < typename T, typename Alloc=some_standard_allocator<T> >
class pointer_to {
...
};

then the template makes it easy to play with allocators for performance
tuning or for implemeting container classes that conform to the allocator
conventions of the standard library.

(b) Using magic allocators or a different implementation of pointer_to<T>,
one can hunt for memory leaks.

(c) In code like

class B { ... };
class D : public B { ... };

pointer_to<B> b_ptr;
pointer_to<D> d_ptr;

b_ptr = d_ptr;

the compiler can issue an error if class B is not polymorphic.
It is the last point that gives me some design problems. I am considering
the following options:

I) Supply two templates:

typebound_ptr<T,Alloc>
polymorphic_ptr<T,Alloc>

where the first will not allow for polymorphic use and the second will not
compile if T is not polymorphic.

The consequence is that I will have to make up my mind every time as to
whether I intend to use a pointer type polymorphically or not. This may be
an advantage in that it probably improves code quality in most cases.
Sometimes, however, it might not be feasibile to decide beforehand -- I am
thinking of coding templates for instance.

II) Implement pointer_to<T> so that assignment, copy constructor, and
perhaps comparison operators will check whether T is polymorphic if their
polymorphic versions are used.

III) Provide all three pointer templates.

This might allow for maximum flexibilty or for maximum confusion. Moreover,
one might end up converting between these pointer types, which somewhat
defies the purpose.
I have working code for most of this, I am just about to decide which files
to ditch.
Any ideas and advice will be highly appreciated.
Best

Kai-Uwe Bux
Jul 22 '05 #1
1 1167
Kai-Uwe Bux <jk********@gmx.net> wrote:
I have determined that replacing T* by pointer_to<T> is a good idea:

Any ideas and advice will be highly appreciated.


Use loki::SmartPtr
<http://sourceforge.net/projects/loki-lib/>
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Dan | last post by:
Workshop {Flash <-> PHP <-> MYSQL} 1-4 December 2003 in Milan (Italy) 4 full immersion days in a Flash/php/MySQL project start-up. The workshop is a unique opportunity for partecipants to...
1
by: Paul | last post by:
Hi, I have encountered the following problem when using VB .net. Please help. I have created a button at design view. Then, I save the design. Reload it and view the " Windows Form Designer...
11
by: Scott Brady Drummonds | last post by:
Hi, everyone, I've checked a couple of on-line resources and am unable to determine how reinterpret_cast<> is different from static_cast<>. They both seem to perform a compile-time casting of...
3
by: Dave Booker | last post by:
Am I missing something here? It looks like the generic Queue<T> implements Enumerable<T> and ICollection but not ICollection<T>. (I want to use it in an interface that wants an ICollection<T>.) ...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
4
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for...
1
by: Ezmeralda | last post by:
Hello, I need to an TCP/IP Interface for communication with an embedded device. Since I have two different design ideas in mind, I am wondering whether you could give me some hints to decide:...
1
by: Ezmeralda | last post by:
Hello, I need to an TCP/IP Interface for communication with an embedded device. Since I have two different design ideas in mind, I am wondering whether you could give me some hints to decide:...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.