Mirror reflection library 0.5.13
|
00001 00010 #ifndef MIRROR_CONCEPT_CHECK_UTILS_1011291729_HPP 00011 #define MIRROR_CONCEPT_CHECK_UTILS_1011291729_HPP 00012 00013 #include <mirror/config.hpp> 00014 #include <mirror/mirror_fwd.hpp> 00015 #include <mirror/meta_object_tags.hpp> 00016 #include <mirror/meta_prog/is_a.hpp> 00017 #include <mirror/meta_prog/and.hpp> 00018 #include <mirror/preprocessor.hpp> 00019 00020 00021 MIRROR_NAMESPACE_BEGIN 00022 00023 // helper template use in implementation of conforms_to 00024 // Specializations of this template check the conformance 00025 // of the Tested type with various concepts 00026 // 00027 // Don't use or specialize this template directly use 00028 // the MIRROR_CONCEPT_TESTER_* macros 00029 template <typename Tested, typename ConceptTag> 00030 class conforms_to_helper; 00031 00032 00033 #define MIRROR_CONCEPT_TESTER_BEGIN(CONCEPT_TAG) \ 00034 template <typename Tested> \ 00035 class conforms_to_helper<Tested, CONCEPT_TAG> \ 00036 { \ 00037 private: \ 00038 template <typename X> \ 00039 static typename mirror::mp::is_a< \ 00040 X, \ 00041 CONCEPT_TAG \ 00042 >::type category_test(X*); \ 00043 static std::false_type category_test(...); \ 00044 static std::false_type test(...); \ 00045 template <class X> \ 00046 static std::true_type test 00047 00048 #define MIRROR_CONCEPT_TESTER_END \ 00049 public: \ 00050 typedef typename mirror::mp::and_< \ 00051 other_constraints, \ 00052 decltype(category_test((Tested*)nullptr)), \ 00053 decltype(test((Tested*)nullptr)) \ 00054 >::type type; \ 00055 }; 00056 00057 #define MIRROR_CONCEPT_TESTER_CONSTRAINTS(PARAM) \ 00058 typedef typename MIRROR_PP_EXPAND_ARGS PARAM :: type \ 00059 other_constraints; 00060 00062 00069 template <typename Tested, typename ConceptTag> 00070 struct conforms_to 00071 : public conforms_to_helper<Tested, ConceptTag>::type 00072 { }; 00073 00075 00082 #define MIRROR_ASSERT_CONCEPT(TESTED, CONCEPT_TAG) \ 00083 static_assert( \ 00084 mirror::conforms_to< \ 00085 TESTED, \ 00086 mirror::CONCEPT_TAG \ 00087 >::value, \ 00088 #TESTED " does not conform to " #CONCEPT_TAG \ 00089 ) 00090 00091 MIRROR_NAMESPACE_END 00092 00093 #endif //include guard 00094