Re: Workaround for partial specialization wanted
"David Abrahams" <dave@boost-consulting.com> schrieb im Newsbeitrag
news:87hck4f0vd.fsf@grogan.peloton...
// Extracts the type of an object.
template <class T>
struct extract { typedef T type; };
// Extracts the type of an array.
template <class T, std::size_t N>
struct extract<T[N]> { typedef T type; };
If your target is an old version of MSVC (6 or 7), then you can use
the Boost type traits for these kinds of things. They take advantage
of a bugfeature in the compiler that allows them to do this stuff.
I just had a look at the boost website, but all I found was the
"remove_all_extents" class template, which does not exactly offer the
behaviour as my "extract" class template.
T* TrackNew( T* ptr, const char* file, int line, ...)
{
std::cout << "Tracking object allocation" << std::endl;
return ptr;
};
template <class T, std::size_t N>
T(*)[N] TrackNew( T(*ptr)[N], const char* file, int line, int)
{
std::cout << "Tracking array allocation " << std::endl;
return ptr;
}
#define NEW( T ) TrackNew( new T, __FILE__, __LINE__, 0 )
Of course, I haven't tested this, so it may be buggy. And I haven't
tested it with your compiler, which is definitely not conforming, so
I don't know how well it will handle the above. If you have trouble
you might change the return type of the 2nd overload to T*.
I'm afraid it doesn't work. My compiler keeps calling the object version of
the function, even when an array is allocated. The return type of the
second
overload doesn't seem to make a difference. Well, maybe I am trying to
achieve something that's just not possible...
--
Matthias Hofmann
Anvil-Soft, CEO
http://www.anvil-soft.com - The Creators of Toilet Tycoon
http://www.anvil-soft.de - Die Macher des Klomanagers
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]