Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor pattern limited to at most 4 arguments? #65

Open
forflo opened this issue Jul 3, 2016 · 2 comments
Open

Constructor pattern limited to at most 4 arguments? #65

forflo opened this issue Jul 3, 2016 · 2 comments

Comments

@forflo
Copy link

forflo commented Jul 3, 2016

If I call the function Template C as follows

Match(foo){
    Case(C<SomeType>(arg0, arg1, arg2, arg3)){
        /* ... */
    }
    Otherwise(){/*...*/}
} EndMatch

everything works as expected. However, if I write,

Match(foo){
    Case(C<SomeType>(arg0, arg1, arg2, arg3, arg4)){
        /* ... */
    }
    Otherwise(){/*...*/}
} EndMatch

the compiler complains about no matching function for call to 'C'.
I already looked at constructor.hpp and the implementations of the class templates constr{0,1,2,3,4}. I assume those to be the underlying base of C which almost certainly itself is a macro (is that right?), which would explain the limitation to 4 arguments of the call operator. But then I looked more closely and realized that only the number of template arguments changes. The call operator overloads (more or less) stay the same throughout the different versions of constr.

    template <typename U> const T* operator()(const U* u) const noexcept { return dynamic_cast<const T*>(u); }
    template <typename U>       T* operator()(      U* u) const noexcept { return dynamic_cast<      T*>(u); }
    template <typename U> const T* operator()(const U& u) const noexcept { return operator()(&u); }
    template <typename U>       T* operator()(      U& u) const noexcept { return operator()(&u); }
                          const T* operator()(const T* t) const noexcept { return t; }
                                T* operator()(      T* t) const noexcept { return t; }
                          const T* operator()(const T& t) const noexcept { return &t; }
                                T* operator()(      T& t) const noexcept { return &t; }

Why is that? I'm probably missing something obvious here...
Could you elaborate the expansion of C a little further. Somehow I can't find the macro definition. I also tried to compile with gcc -E in order to view the expansions, without much success (however, the output did hurt my eyes).

Best regards
Florian

@solodon4
Copy link
Owner

solodon4 commented Jul 3, 2016

Yes, that code was written prior to variadic arguments making into the language, so i only bothered to put specializations of up to as many arguments as the examples i've been working with at the time. I'd add a variadic implementation to handle the general case for the compilers that support it.

Note that with Members macro the issue can't be solved with variadic templates, so you'd have to tell me how many arguments would be sufficient for your use cases.

@forflo
Copy link
Author

forflo commented Jul 4, 2016

have to tell me how many arguments would be sufficient for your use cases.

I already resolved it using normal member access, but thank you very much for the support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants