Bläddra i källkod

Add template helper tools to internal.hpp

Ole 9 år sedan
förälder
incheckning
855a598a57
1 ändrade filer med 61 tillägg och 0 borttagningar
  1. 61 0
      lib/luwra/internal.hpp

+ 61 - 0
lib/luwra/internal.hpp

@@ -0,0 +1,61 @@
+/* Luwra
+ * Minimal-overhead Lua wrapper for C++
+ *
+ * Copyright (C) 2016, Ole Krüger <ole@vprsm.de>
+ */
+
+#ifndef LUWRA_INTERNAL_H_
+#define LUWRA_INTERNAL_H_
+
+#include "common.hpp"
+
+LUWRA_NS_BEGIN
+
+namespace internal {
+	// Information about function objects
+	template <typename T>
+	struct CallableInfo: CallableInfo<decltype(&T::operator ())> {};
+
+	// Information about function signature
+	template <typename R, typename... A>
+	struct CallableInfo<R(A...)> {
+		using ReturnType = R;
+
+		template <template <typename...> class T>
+		using RelayArguments = T<A...>;
+	};
+
+	// Information about function pointers
+	template <typename R, typename... A>
+	struct CallableInfo<R (*)(A...)>: CallableInfo<R(A...)> {};
+
+	// Information about method pointers
+	template <typename T, typename R, typename... A>
+	struct CallableInfo<R (T::*)(A...)>: CallableInfo<R(A...)> {};
+
+	template <typename T, typename R, typename... A>
+	struct CallableInfo<R (T::*)(A...) const>: CallableInfo<R(A...)> {};
+
+	template <typename T, typename R, typename... A>
+	struct CallableInfo<R (T::*)(A...) volatile>: CallableInfo<R(A...)> {};
+
+	template <typename T, typename R, typename... A>
+	struct CallableInfo<R (T::*)(A...) const volatile>: CallableInfo<R(A...)> {};
+
+	// Useful aliases
+	template <typename T>
+	struct CallableInfo<const T>: CallableInfo<T> {};
+
+	template <typename T>
+	struct CallableInfo<volatile T>: CallableInfo<T> {};
+
+	template <typename T>
+	struct CallableInfo<T&>: CallableInfo<T> {};
+
+	template <typename T>
+	struct CallableInfo<T&&>: CallableInfo<T> {};
+}
+
+LUWRA_NS_END
+
+#endif