How do you create a static function with a generic parameter in hxcpp externs? (Template Meta-Programming)



How do you create a static function in a hxcpp extern where the original C++ code has a template generic parameter for a class object that you pass into the function?

For example how to turn something like this (C++):

template<typename T, T Value, class Cls>
void funcName(){}

called like this (C++):

to something like this (haxe HXCPP extern):

static function funcName<T>(className:T) : Void;

If this isn’t implemented yet in HXCPP externs, then it is a major oversight because it appears to be a common C++11 feature used in many modern C++ libraries.

(Dmitry Hryppa) #2

No, you can’t do this.
But you can specify every type of T that you need manually. Something like:

class Main {
    public static function main():Void {
        var vec:IntVector = IntVector.create();
        cpp.Lib.println(; //10

extern class Vector<T> {
    @:native('push_back') public function pushBack(value:T):Void;
    public function at(index:Int):T;

extern class IntVector extends Vector<Int> {
    @:native('std::vector<int>') public static function create():IntVector;