RE: [Boost-Users] pointer traints ?
Couldn't you do something along the lines of: template < typename PointerT, typeName RefereceT = &(*PointerT) > Only I think that's an address rather than a reference... How about: template < typename T > void f( T *ptr ) { T &ref = *ptr; // ... do something with ref ... } And what do you have against "->"? I don't think a reference's "." is any faster than a pointer's "->", so that shouldn't be a concern... just trying to save some knuckle grease? I don't get it. (I'm getting a lot of practice with that phrase since I started digging into STL & Boost) --Mark Storer Software Engineer Cardiff Software #include <disclaimer> typedef std::disclaimer<Cardiff> Discard; -----Original Message----- From: Bohdan [mailto:yg-boost-users@m.gmane.org] Sent: Monday, September 23, 2002 7:38 AM To: boost-users@yahoogroups.com Subject: [Boost-Users] pointer traints ? I have following code: template < typename PointerT > void f( PointerT ptr ) { ReferenceT ref = *ptr; // ... do something with ref ... } The problem is that ReferenceT is unknown inside f( ... ). If i had similar code for InteratorT instead of PointerT i was using iterator_traits. AFAIK there is no pointer traits for a raw and smart pointers and i can not use type_traits for smart pointers. So, the question is: "Is there some simple solution for this problem or this is just lack of pointer_traits in boost (std?) ?" regards, bohdan Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
"Mark Storer"
Couldn't you do something along the lines of:
template < typename PointerT, typeName RefereceT = &(*PointerT) >
Try to compile your code ...
Only I think that's an address rather than a reference...
How about:
template < typename T > void f( T *ptr ) { T &ref = *ptr; // ... do something with ref ... }
I didn't tell that PointerT is T*. You forgot about smart pointers and iterators.
And what do you have against "->"? I don't think a reference's "." is any faster than a pointer's "->", so that shouldn't be a concern... just
trying
to save some knuckle grease?
I hope it was not offensive.
I don't get it. (I'm getting a lot of practice with that phrase since I started digging into STL & Boost)
1) The problem is not related to raw pointers, but to smart ones. 2) I have nothing against "->". 3) ReferenceT is not always T&, it can also be some kind of proxy or simply value type, or even void (for input iterator). 4) The original problem (for me) was in creating generic "dereference" function: <code> template <typename PointerT > ReferenceT dereference( PointerT ptr ) { return *ptr; } <\code> Have you any ideas on how to distinguish ReferenceT in this case ? --------------------------------------- Take a look at boost.devel for more details.
participants (2)
-
Bohdan
-
Mark Storer