hxcpp icon indicating copy to clipboard operation
hxcpp copied to clipboard

Feature request. Generics for externs

Open posxposy opened this issue 7 years ago • 2 comments

It is currently possible to use std::vector (in a little bit complicated way), but no ways to use std::array (or I just don't know how).

So would be nice to have something like:

@:native('std::array<T, S>')              // I think it is hard to put something like this,      
@:native('std::array<{0}, {1}>', T, S)  // so maybe it may be as this?
@:native('std::array')                 // or like this and T and S will be atomatically added as template values
extern class StdArray<T, @:const S> {
...
}

//and somewhere in code:
var arr:StdArray<Int, 10> = ....;

This may help a lot to work with C++ templates in Haxe.

posxposy avatar Jun 10 '18 10:06 posxposy

I need a solution like this too! I am stuck!!

darmie avatar Aug 06 '18 16:08 darmie

This is partially supported now since haxe 4.3.0: https://github.com/HaxeFoundation/haxe/pull/10415 (you'd use @:native('std::array'))

However, there is dodgy code generation when using the constant value template:

Error: ./src/Main.cpp:5:10: fatal error: I10.h: No such file or directory
    5 | #include <I10.h>
std::array< int, ::I10 > a =  std::array< int, ::I10 >();

tobil4sk avatar Oct 03 '25 13:10 tobil4sk