Re: Workaround for partial specialization wanted
Success! :-) My guess was right, getting boost::remove_extent to run on my
compiler was indeed the solution to my problem! All I needed was to include
the following files in my project:
http://boost.org/boost/type_traits/msvc/remove_extent.hpp
http://boost.org/boost/type_traits/msvc/typeof.hpp
http://boost.org/boost/type_traits/is_array.hpp
Now my code looks like this:
#include <iostream>
#include "remove_extent.hpp"
template <class T>
T* TrackNew( T* ptr, const char* file, int line, int )
{
std::cout << "Tracking object allocation" << std::endl;
return ptr;
};
template <class T>
boost::remove_extent<T>::type* TrackNew( boost::remove_extent<T>::type* ptr,
const char* file, int line, ... )
{
std::cout << "Tracking array allocation" << std::endl;
return ptr;
}
#define NEW( T ) TrackNew<T>( new T, __FILE__, __LINE__, 0 )
int main()
{
int* p1 = NEW( int );
delete p1;
int* p2 = NEW( int[64] );
delete [] p2;
return 0;
}
Note that the object version of TrackNew has an int as it's fourth
parameter, while the fourth parameter of the array version is an ellipsis.
It used to be the other way round in the code example David Abrahams gave
me, but that would always call the array version.
I am now going to have a look at the three header files mentioned above to
learn how the workaround works, so I can better integrate everything into my
code.
--
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! ]