Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
has_print.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 02.07.2013 17:19:27 EDT
3 // File: has_print.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __HAS_PRINT_HEADER
12 #define __HAS_PRINT_HEADER
13 
14 namespace util {
15  //------------------- checks if T is a class and has a template method called print -------------------
16  template<typename T, bool is_a_class>
17  struct has_print_impl {
19  template<typename U> stream_proto_type & operator<<(U const & u);
20  };
21  template<void(T::*)(stream_proto_type &)const> struct helper {typedef char type;};
22 
23  template<typename U> static char check(typename helper<&U::template print<stream_proto_type>>::type);
24  template<typename U> static double check(...);
25 
26  enum { value = (sizeof(char) == sizeof(check<T>(0))) };
27  };
28  template<typename T>
29  struct has_print_impl<T, false> { //if T is not a class it cannot have print
30  enum { value = false };
31  };
32  template<typename T>
33  struct has_print {
35  };
36 }//end namespace util
37 
38 #endif //__HAS_PRINT_HEADER
Definition: has_print.hpp:17
Definition: has_print.hpp:26
static char check(typename helper<&U::template print< stream_proto_type >>::type)
Definition: has_print.hpp:34
stream_proto_type & operator<<(U const &u)
Definition: has_print.hpp:21
Definition: has_print.hpp:33
Definition: has_print.hpp:18
char type
Definition: has_print.hpp:21