Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Unified Diff: mojo/public/cpp/bindings/lib/template_util.h

Issue 1618963006: Mojo C++ bindings: support enum validation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/bindings_internal.h ('k') | mojo/public/cpp/bindings/lib/validation_errors.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/template_util.h
diff --git a/mojo/public/cpp/bindings/lib/template_util.h b/mojo/public/cpp/bindings/lib/template_util.h
index ceaf8e08e2bcad2973cc51c9d186964135f534ce..68390c124d395312de1c24eb77c4a3e1ac15189e 100644
--- a/mojo/public/cpp/bindings/lib/template_util.h
+++ b/mojo/public/cpp/bindings/lib/template_util.h
@@ -70,18 +70,24 @@ template <typename A>
struct IsSame<A, A> {
static bool const value = true;
};
+
+template <typename T>
+struct EnsureTypeIsComplete {
+ // sizeof() cannot be applied to incomplete types, this line will fail
+ // compilation if T is forward declaration.
+ using CheckSize = char (*)[sizeof(T)];
+};
+
template <typename Base, typename Derived>
struct IsBaseOf {
private:
- // This class doesn't work correctly with forward declarations.
- // Because sizeof cannot be applied to incomplete types, this line prevents us
- // from passing in forward declarations.
- typedef char (*EnsureTypesAreComplete)[sizeof(Base) + sizeof(Derived)];
-
static Derived* CreateDerived();
static char(&Check(Base*))[1];
static char(&Check(...))[2];
+ EnsureTypeIsComplete<Base> check_base_;
+ EnsureTypeIsComplete<Derived> check_derived_;
+
public:
static bool const value = sizeof Check(CreateDerived()) == 1 &&
!IsSame<Base const, void const>::value;
« no previous file with comments | « mojo/public/cpp/bindings/lib/bindings_internal.h ('k') | mojo/public/cpp/bindings/lib/validation_errors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698