diff --git a/src/blackmisc/inheritance_traits.h b/src/blackmisc/inheritance_traits.h new file mode 100644 index 000000000..d432e93b9 --- /dev/null +++ b/src/blackmisc/inheritance_traits.h @@ -0,0 +1,61 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_INHERITANCE_TRAITS_H +#define BLACKMISC_INHERITANCE_TRAITS_H + +#include +#include + +namespace BlackMisc +{ + class CEmpty; + + /*! + * If T has a member typedef base_type, this trait will obtain it, otherwise void. + */ + template + class BaseOf + { + //template static typename U::base_type *test(int); + template static typename U::base_type *test(typename std::enable_if::value, int>::type); + template static void *test(...); + + public: + //! The declared base_type of T, or void if there is none. + typedef typename std::remove_pointer(0))>::type type; + }; + + /*! + * It T has a member typedef base_type which is a registered metatype, this trait will obtain it, otherwise void. + */ + template + class MetaBaseOf + { + public: + //! Type of T::base_type, or void if not declared. + typedef typename std::conditional::type>::Defined, typename BaseOf::type, void>::type type; + }; + + /*! + * Alias for typename BaseOf::type. + */ + template + using BaseOfT = typename BaseOf::type; + + /*! + * Alias for typename MetaBaseOf::type. + */ + template + using MetaBaseOfT = typename MetaBaseOf::type; +} + +#endif diff --git a/src/blackmisc/valueobject_private.h b/src/blackmisc/valueobject_private.h index 825ba1f26..c644f04fb 100644 --- a/src/blackmisc/valueobject_private.h +++ b/src/blackmisc/valueobject_private.h @@ -13,6 +13,7 @@ #define BLACKMISC_VALUEOBJECT_PRIVATE_H #include "blackmisc/blackmiscexport.h" +#include "blackmisc/inheritance_traits.h" #include #include #include @@ -28,44 +29,6 @@ namespace BlackMisc template void registerMetaValueType(); - /*! - * If T has a member typedef base_type, this trait will obtain it, otherwise void. - */ - template - class BaseOf - { - //template static typename U::base_type *test(int); - template static typename U::base_type *test(typename std::enable_if::value, int>::type); - template static void *test(...); - - public: - //! The declared base_type of T, or void if there is none. - typedef typename std::remove_pointer(0))>::type type; - }; - - /*! - * It T has a member typedef base_type which is a registered metatype, this trait will obtain it, otherwise void. - */ - template - class MetaBaseOf - { - public: - //! Type of T::base_type, or void if not declared. - typedef typename std::conditional::type>::Defined, typename BaseOf::type, void>::type type; - }; - - /*! - * Alias for typename BaseOf::type. - */ - template - using BaseOfT = typename BaseOf::type; - - /*! - * Alias for typename MetaBaseOf::type. - */ - template - using MetaBaseOfT = typename MetaBaseOf::type; - namespace Private { //! \private Needed so we can copy forward-declared CVariant.