// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ #define MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ #include namespace mojo { namespace internal { template struct IntegralConstant { static const T value = v; }; template const T IntegralConstant::value; typedef IntegralConstant TrueType; typedef IntegralConstant FalseType; template struct IsConst : FalseType {}; template struct IsConst : TrueType {}; template struct IsPointer : FalseType {}; template struct IsPointer : TrueType {}; template struct EnableIf {}; template struct EnableIf { typedef T type; }; // Types YesType and NoType are guaranteed such that sizeof(YesType) < // sizeof(NoType). typedef char YesType; struct NoType { YesType dummy[2]; }; // A helper template to determine if given type is non-const move-only-type, // i.e. if a value of the given type should be passed via std::move() in a // destructive way. template struct IsMoveOnlyType { static const bool value = std::is_constructible::value && !std::is_constructible::value; }; // This goop is a trick used to implement a template that can be used to // determine if a given class is the base class of another given class. template struct IsSame { static bool const value = false; }; template struct IsSame { static bool const value = true; }; template 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 struct IsBaseOf { private: static Derived* CreateDerived(); static char(&Check(Base*))[1]; static char(&Check(...))[2]; EnsureTypeIsComplete check_base_; EnsureTypeIsComplete check_derived_; public: static bool const value = sizeof Check(CreateDerived()) == 1 && !IsSame::value; }; template struct RemovePointer { typedef T type; }; template struct RemovePointer { typedef T type; }; template