I want to base a template on these types from the timespec struct
but to be portable I want to do it without explicitly naming them,
I have tried, and failed, like this:
1 2 3 4 5
template<typename T>
class nsecs {
T.tv_nsec value;
};
There's nothing in the syntax of timespec that says that tv_nsec is a nanosecond, it's a semantic definition. So I don't think you can pull timespec apart to get an enforcing syntax. You may have to just resort to a plan old typedef: typedeflong nanosec_t;
In Windows, there's a high resolution timer that takes type LARGE_INTEGER, essentially a uint64_t, but is in fact a union, allowing you to get to high/low parts. I have wrapper that typedefs it, but within the class:
1 2 3 4
class HRTimer
{
public:
typedef LARGE_INTEGER timer_t; /// High Resolution Timer integral time type
It defines it's own type, but clients alway use: HRTimer::timer_t, which is quite clear in code what kind of time type it is.
yes, that's what I wanted to avoid.
the timespec struct has a long on BSD but might be different on
linux or Solaris. Or may change with versions of gcc.
Nothing anal about it. As you can see, it's pretty much standard in STL to provide typedefs for the members so you can do exactly that. But with old C types, ...
Another alternative to still you some typedef, but put it in the platform specific section of your component; config.h or whatever you use.