Reputation: 85
How can i check, that some class, passed as a template argument, have some static property on it? Like ::size
template<class Header>
class Reader {
// e.g. Header::size
};
My concept is that each Header
class must implement a size
property that will be read by the Reader
class. The Reader class, in turn, will read the number (size
) of bytes from the file, and then pass the buffer to the Header
ctor.
Upvotes: 1
Views: 956
Reputation: 4735
Simply use a concept:
template <class T>
concept HasSize = requires(T) {
T::size;
};
template <HasSize Header>
struct Reader {
// Use Header::size
};
Upvotes: 3