Re: [C#] Discarding overloads using typecheck
William S Fulton <[email protected]> Mon, 2 Sep 2024 23:39:40 +0100
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CANGqftBKZJBsOSNR=y2V91Ms8VVWKQEQAP0Zvg1tDCNJ+y9pEg@mail.gmail.com> |
--===============6132394959644296642== Content-Type: multipart/alternative; boundary="000000000000fd6fd406212a9f59" --000000000000fd6fd406212a9f59 Content-Type: text/plain; charset="UTF-8" On Sat, 31 Aug 2024 at 07:13, Rokas Kupstys via Swig-user < [email protected]> wrote: > Hi, > > Does anyone know how to have SWIG automatically discard overloads of > compatible types? For example, we get this behavior for "const char*" > and "std::string", where functions differing only with these types of > corresponding parameters are treated as same. std_string.i has > "%typemap(typecheck) string = char *;" which i thought is responsible > for discarding overloads. I added typemaps for string_view, but > "%typemap(typecheck) std::string_view = char *;" does not work. I also > am dealing with two STL libraries - standard one and EASTL, so i need to > treat types from both libraries as equal as well. All these types should > be considered as strings: std::string, std::string_view, eastl::string, > eastl::string_view, const char* (and corresponding const-ref variants, > omitted for brevity). I know i can ignore those functions, but this > would be very tedious, i would rather use a built in mechanism to > discard these overloads. Please advice. > The typecheck typemaps should work as you expect. Maybe you've done something unexpected like not declaring the typemaps before the types are parsed or there is a namespace issue. Try the -debug-tmsearch option, eg you should see something like this for simple usage: %include <std_string.i> %inline %{ void abc(const std::string& s) {} void abc(const char* s) {} %} example.i:6: Searching for a suitable 'typecheck' typemap for: std::string const &s Looking for: std::string const &s Looking for: std::string const & Using: %typemap(typecheck) std::string const & = char * and the automated ignore you want with a warning (this is the C# output, I'm not sure what language(s) you are using)... example.i:7: Warning 516: Overloaded method abc(char const *) ignored, example.i:6: Warning 516: using abc(std::string const &) instead. William --000000000000fd6fd406212a9f59 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">= <div dir=3D"ltr" class=3D"gmail_attr">On Sat, 31 Aug 2024 at 07:13, Rokas K= upstys via Swig-user <<a href=3D"mailto:[email protected]"= >[email protected]</a>> wrote:<br></div><blockquote class= =3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg= b(204,204,204);padding-left:1ex">Hi,<br> <br> Does anyone know how to have SWIG automatically discard overloads of <br> compatible types? For example, we get this behavior for "const char*&q= uot; <br> and "std::string", where functions differing only with these type= s of <br> corresponding parameters are treated as same. std_string.i has <br> "%typemap(typecheck) string =3D char *;" which i thought is respo= nsible <br> for discarding overloads. I added typemaps for string_view, but <br> "%typemap(typecheck) std::string_view =3D char *;" does not work.= I also <br> am dealing with two STL libraries - standard one and EASTL, so i need to <b= r> treat types from both libraries as equal as well. All these types should <b= r> be considered as strings: std::string, std::string_view, eastl::string, <br= > eastl::string_view, const char* (and corresponding const-ref variants, <br> omitted for brevity). I know i can ignore those functions, but this <br> would be very tedious, i would rather use a built in mechanism to <br> discard these overloads. Please advice.<br></blockquote><div><br></div><div= >=C2=A0The typecheck typemaps should work as you expect. Maybe you've d= one something unexpected like not declaring the typemaps before the types a= re parsed or there is a namespace issue.</div><div><br></div><div>Try the -= debug-tmsearch option, eg you should see something like this for simple usa= ge:<br></div><div><br></div><div>%include <std_string.i><br>%inline %= {<br>void abc(const std::string& s) {}<br>void abc(const char* s) {}<br= >%}<br></div><div><br></div><div>example.i:6: Searching for a suitable '= ;typecheck' typemap for: std::string const &s<br>=C2=A0 Looking for= : std::string const &s<br>=C2=A0 Looking for: std::string const &<b= r>=C2=A0 Using: %typemap(typecheck) std::string const & =3D char *</div= ><div><br></div><div>and the automated ignore you want with a warning (this= is the C# output, I'm not sure what language(s) you are using)...<br><= /div><div><br></div><div>example.i:7: Warning 516: Overloaded method abc(ch= ar const *) ignored,<br>example.i:6: Warning 516: using abc(std::string con= st &) instead.</div><div><br></div><div>William<br></div></div></div> --000000000000fd6fd406212a9f59-- --===============6132394959644296642== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============6132394959644296642== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user --===============6132394959644296642==--