Hi to all,
when trying to compile the code below, VC7.1 does it, even if
GetSomeSpecialWin32TickCount is unknown.
However both GCC and Comeau (in strict mode) give an error.
What about compiling unused parst of template classes? We assumed compilers
NOT to look inside member function bodies (and in fact VC7.1 does not even
detect missing ;)
#include <ctime>
struct win32 {};
struct other {};
typedef other os_type;
template <typename timetraits_t, typename timer_t = typename
timetraits_t::value_type>
class basic_timer
{
timer_t start_;
timer_t stop_;
inline static timer_t now()
{
return timetraits_t::get_time(os_type());
}
public:
typedef timer_t value_type;
basic_timer()
: start_(0)
{
}
value_type start()
{
return start_ = now();
}
value_type stop()
{
return (stop_ = now())-start_;
}
};
//////////////////////////////////////////////////////////////////////////
template <typename platform_t>
struct clock_traits
{
typedef size_t value_type;
template <typename any_t>
inline static value_type get_time(any_t)
{
time_t t;
return std::time(&t);
}
inline static value_type get_time(win32)
{
return GetSomeSpecialWin32TickCount();
}
};
typedef basic_timer< clock_traits< os_type > > timer_chrono;
//////////////////////////////////////////////////////////////////////////
int main()
{
timer_chrono t;
t.start();
t.stop();
return 0;
}