Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class T, template <class> class Manager = DefaultManager> class Data
- {
- private:
- T *data_;
- public:
- void Dispatch()
- {
- if(SUPERSUBCLASS(Container, T))
- {
- data_->IKnowThisIsHere();
- }
- else
- {
- Manager<T>::SomeGenericFunction(data_);
- }
- }
- }
- private:
- int *data_;
- public:
- void Dispatch()
- {
- if(false)
- {
- data_->IKnowThisIsHere();
- void Dispatch()
- {
- if(false)
- {
- dynamic_cast<Container*>(data_)->IKnowThisIsHere();
- error: cannot dynamic_cast '((const Data<double, DefaultManager>*)this)->Data<double, DefaultManager>::data_' (of type 'double* const') to type 'class Container*' (source is not a pointer to class)
- error: cannot dynamic_cast '((const Data<std::string, DefaultManager>*)this)->Da<sttad::string, DefaultManager>::data_' (of type 'struct std::string* const') to type 'class Container*' (source type is not polymorphic)
- template <bool n>
- struct int2type
- { enum { value = n}; };
- #include <iostream>
- #define MACRO() true // <- macro used to dispatch
- template <bool n>
- struct int2type
- { enum { value = n }; };
- void method(int2type<false>)
- { std::cout << __PRETTY_FUNCTION__ << std::endl; }
- void method(int2type<true>)
- { std::cout << __PRETTY_FUNCTION__ << std::endl; }
- int
- main(int argc, char *argv[])
- {
- // MACRO() determines which function to call
- //
- method( int2type<MACRO()>());
- return 0;
- }
- void Dispatch()
- {
- myfunc(data_);
- }
- private:
- // EDIT: disabled the default case where the specialisation matched
- template <typename U>
- typename enable_if_c<is_base_of<Container, U>::value, U>::type myfunc(U& data_) {
- data_->IKnowThisIsHere();
- }
- template <typename U>
- typename disable_if_c<is_base_of<Container, U>::value, U>::type myfunc(U& data_) { // default case
- Manager<U>::SomeGenericFunction(data_);
- }
- error: cannot dynamic_cast '((const Data<double, DefaultManager>*)this)->Data<double, RawManager>::data_' (of type 'double* const') to type 'class Container*' (source is not a pointer to class)
- error: cannot dynamic_cast '((const Data<std::string, DefaultRawManager>*)this)->Data<std::string, DefaultManager>::data_' (of type 'struct std::string* const') to type 'class Container*' (source type is not polymorphic)
Add Comment
Please, Sign In to add comment