Collection aus unterschiedlichen Klassentemplates

  • C++

    Collection aus unterschiedlichen Klassentemplates

    Hey,
    ich habe eine Klasse für Functionbindings. Die sieht so aus

    C-Quellcode

    1. // Für Memberfunktionen
    2. template <typename fun, typename cl, typename f_list>
    3. class gcl_binder
    4. {
    5. public:
    6. gcl_binder(fun fn, cl* inst_, const f_list& _lst);
    7. void operator()();
    8. template <typename a0>
    9. void operator()(const a0& _a0);
    10. template <typename a0, typename a1>
    11. void operator()(const a0& _a0, const a1& _a1);
    12. template <typename a0, typename a1, typename a2>
    13. void operator()(const a0& _a0, const a1& _a1, const a2& _a2);
    14. bool operator==(const gcl_binder<fun, cl, f_list>& _binder);
    15. template <typename _fun, typename _cl, typename _nlist>
    16. bool operator==(const gcl_binder<_fun, _cl, _nlist>& _binder);
    17. fun get_func() const;
    18. cl* get_instance() const;
    19. };
    20. // Für statische Funktionen
    21. template <typename fun, typename f_list>
    22. class gcl_binder<fun, void, f_list>
    23. {
    24. public:
    25. gcl_binder(fun fn, const f_list& _lst);
    26. void operator()();
    27. template <typename a0>
    28. void operator()(const a0& _a0);
    29. template <typename a0, typename a1>
    30. void operator()(const a0& _a0, const a1& _a1);
    31. template <typename a0, typename a1, typename a2>
    32. void operator()(const a0& _a0, const a1& _a1, const a2& _a2);
    33. bool operator==(const gcl_binder<fun, void, f_list>& _binder);
    34. template <typename _fun, typename _cl, typename _nlist>
    35. bool operator==(const gcl_binder<_fun, _cl, _nlist>& _binder);
    36. fun get_func() const;
    37. };

    Der Binder klappt wunderbar und wird natürlich noch 20 oder 30 mal überladen, aber jetzt steh ich vor einem Problem. Ich muss alle möglichen Binder in einer Collection (vorzugsweise nem vector) aufbewahren und brauche Zugriff auf Operator() und Operator== mit allen Überladungen. Einzig der Funktionstyp ist gleich, also fällt typename fun schonmal weg. Trotzdem habe ich noch 2 variable Vorlagen. Ich würde normalerweise eigentlich eine Wrapperklasse machen, aber ich weiß ehrlich gesagt nicht wie ich dann noch auf die Funktionen zugreifen soll. Da Funktionsvorlagen ja nicht virtuell sein können. Ich hoffe jemand kennt eine Lösung.

    Grüße