From 18b862350ab6a3d9d6d5a7d8f33224ba5c6776fc Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 13 Apr 2012 11:30:22 +1000 Subject: [PATCH] Add traits helpers for dereferencable types --- types.hpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/types.hpp b/types.hpp index 5dd23e56..7a82da4c 100644 --- a/types.hpp +++ b/types.hpp @@ -75,7 +75,8 @@ struct sized_type : public bits_type template -std::string type_to_string (void); +std::string +type_to_string (void); namespace detail { @@ -142,6 +143,7 @@ template size_t elems(T (&)[N]) { return N; } + template std::unique_ptr make_unique(Args&&... args) { return std::unique_ptr (new T(std::forward(args)...)); @@ -161,6 +163,25 @@ struct fourcc { std::ostream& operator<< (std::ostream&, fourcc); +template struct is_dereferencable : std::false_type { }; +template struct is_dereferencable : std::true_type { }; +template struct is_dereferencable> : std::true_type { }; +template struct is_dereferencable> : std::true_type { }; +template struct is_dereferencable> : std::true_type { }; +template struct is_dereferencable> : std::true_type { }; + + +template struct dereferenced_type { + typedef typename std::enable_if< + std::is_pointer::value, + std::remove_pointer + >::type type; +}; + +template struct dereferenced_type> { typedef T type; }; +template struct dereferenced_type> { typedef T type; }; +template struct dereferenced_type> { typedef T type; }; +template struct dereferenced_type> { typedef T type; }; #endif // __TYPES_HPP