/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Template-based metaprogramming and type-testing facilities. */ #ifndef mozilla_TypeTraits_h_ #define mozilla_TypeTraits_h_ namespace mozilla { /* * IsBaseOf allows to know whether a given class is derived from another. * * Consider the following class definitions: * * class A {}; * class B : public A {}; * class C {}; * * mozilla::IsBaseOf::value is true; * mozilla::IsBaseOf::value is false; */ template class IsBaseOf { private: static char test(Base* b); static int test(...); public: static const bool value = (sizeof(test(static_cast(0))) == sizeof(char)); }; /* * Conditional selects a class between two, depending on a given boolean value. * * mozilla::Conditional::Type is A; * mozilla::Conditional::Type is B; */ template struct Conditional { typedef A Type; }; template struct Conditional { typedef B Type; }; } /* namespace mozilla */ #endif /* mozilla_TypeTraits_h_ */