From: Phil Bouchard on
Greetings:

I think it should be possible to override all fundamental pointers with a
given class. This is very important and can save a lot of trouble. How
about:

template <typename T>
struct *
{
...
};

// Specialization
template <>
struct int *
{
...
};

The same goes on with "C" arrays. Maybe function pointers also, this way
they can be used with STL algorithm:

template <typename T, typename... A>
struct T (*)(A...)
{
T operator () (A... a)
{ return p_(a); }
...
};


Thanks,
-Phil



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: maninalift on
If you are suggesting that a programmer should be able to write a
class to be used in place of the pointer for some type then no no no
no. C++ differs from C in its lack of guarantees about type
representation but this would be a nightmare.

If you want a mechanism for fetching an appropriate iterator for a
class then you can build your own:

// default
template <class T>
default_iterator
{
typedef type T*;
};


// write your specializations....


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Alberto Ganesh Barbati on
Phil Bouchard ha scritto:
> Greetings:
>
> I think it should be possible to override all fundamental pointers with a
> given class. This is very important and can save a lot of trouble. How
> about:
>
> template <typename T>
> struct *
> {
> ...
> };
>
> // Specialization
> template <>
> struct int *
> {
> ...
> };
>

The natural question is: why would you want to do so? "Very important
and can save a lot of trouble" is quite a weak rationale and one that
it's very easy to disagree with.

Ganesh

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: red floyd on
Phil Bouchard wrote:
> Greetings:
>
> I think it should be possible to override all fundamental pointers with a
> given class. This is very important and can save a lot of trouble. How
> about:
>
> template <typename T>
> struct *
> {
> ...
> };
>
> // Specialization
> template <>
> struct int *
> {
> ...
> };
>
> The same goes on with "C" arrays. Maybe function pointers also, this way
> they can be used with STL algorithm:
>
Your wish has been granted.

TR1 has multiple smart pointer class templates, as well as an array
class template.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Phil Bouchard on

"Alberto Ganesh Barbati" <AlbertoBarbati(a)libero.it> wrote in message
news:D_rJj.282188$%k.399446(a)twister2.libero.it...

[...]

> The natural question is: why would you want to do so? "Very important
> and can save a lot of trouble" is quite a weak rationale and one that
> it's very easy to disagree with.

Well consider this. Suppose you want to rewrite the memory management
inside a huge project but you can't overload in any way operators and
destructors on existing pointers. You can't manually rewrite the entire
code either with smart pointer. So you're out of options in that scenario.


-Phil



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]