On 10/16/2016 7:16 AM, Vinnie Falco wrote:
I'd like to write a trait:
template<class T> struct has_content_length : std::integral_constant
{}; which detects whether or not a template static member function is present in T. Here's a typical T:
struct X { template
static std::uint64_t content_length( message const& m); }; How can I detect if X::content_length(m) is callable for any m of type message template?
It is not possible AFAIK. The tti library can detect whether a class template is a member of a type but it cannot detect whether a function template is a member of a type. The reason for this, within tti, is that class templates and function templates are not treated orthogonally in C++; a class template can be a template parameter but a function template cannot be a template parameter. If a function template could be a template parameter then tti could detect a function template as a member of a type, whether that function template were a static or a non-static member. I have felt that the lack of orthogonality in C++, where a class template can be a template parameter but a function template cannot be a template parameter, is a design weakness of C++. But I would have to convince the C++ standards committee of the practicality of allowing a function template to be a template parameter to possibly change this. I doubt whether saying that the change would allow the Boost tti library to detect function templates in the same way it can detect class templates, would be a good enough practical reason <g>.