Re: tostring operator doesn't compile if argument is non const
Szymon Gatner <[email protected]> Thu, 18 Apr 2013 09:50:58 +0200
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <CALqx0+VkoHCtkf9kmeXEug-Ja4eD+rM1HT0niShxyHREho7-9A@mail.gmail.com> |
--===============7973288051008614511== Content-Type: multipart/alternative; boundary=047d7b5dbbe4fb7b4504da9ddcf5 --047d7b5dbbe4fb7b4504da9ddcf5 Content-Type: text/plain; charset=ISO-8859-1 Mutating streaming operator is not idiomatic anyway and will cause problems in other C++ code. Why do you need it to be mutating? 2013/4/10 Lorenzo Pistone <[email protected]> > Hello, > the example in the docs to bind the tostring operator > (http://www.rasterbar.com/products/luabind/docs.html#operators) doesn't > compile. I write it here for reference: > > #include <luabind/luabind.hpp> > #include <luabind/operator.hpp> > #include <ostream> > class number {}; > std::ostream& operator<<(std::ostream& o, number&){ return o; } > int main(){ > lua_State* L = NULL; > using namespace luabind; > module(L)[class_<number>("number").def(tostring(self))]; > } > > It compiles only if you put use this signature for <<: > > std::ostream& operator<<(std::ostream& out, const A&) > > Also, I would expect that const_self is required in the def, but it > seems that it doesn't matter. Is this intended behaviour or a bug? > > Cheers. > > > ------------------------------------------------------------------------------ > Precog is a next-generation analytics platform capable of advanced > analytics on semi-structured data. The platform includes APIs for building > apps and a phenomenal toolset for data science. Developers can use > our toolset for easy data analysis & visualization. Get a free account! > http://www2.precog.com/precogplatform/slashdotnewsletter > _______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user > -- Szymon Gatner The Lordz Games Studio www.thelordzgamesstudio.com --047d7b5dbbe4fb7b4504da9ddcf5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Mutating streaming operator is not idiomatic anyway and wi= ll cause problems in other C++ code. Why do you need it to be mutating?</di= v><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">2013/4/10 L= orenzo Pistone <span dir=3D"ltr"><<a href=3D"mailto:[email protected]= om" target=3D"_blank">[email protected]</a>></span><br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex">Hello,<br> the example in the docs to bind the tostring operator<br> (<a href=3D"http://www.rasterbar.com/products/luabind/docs.html#operators" = target=3D"_blank">http://www.rasterbar.com/products/luabind/docs.html#opera= tors</a>) doesn't<br> compile. I write it here for reference:<br> <br> =A0 =A0 =A0#include <luabind/luabind.hpp><br> =A0 =A0 =A0#include <luabind/operator.hpp><br> =A0 =A0 =A0#include <ostream><br> =A0 =A0 =A0class number {};<br> =A0 =A0 =A0std::ostream& operator<<(std::ostream& o, number&a= mp;){ return o; }<br> =A0 =A0 =A0int main(){<br> =A0 =A0 =A0 =A0 =A0lua_State* L =3D NULL;<br> =A0 =A0 =A0 =A0 =A0using namespace luabind;<br> module(L)[class_<number>("number").def(tostring(self))];<br= > =A0 =A0 =A0}<br> <br> It compiles only if you put use this signature for <<:<br> <br> std::ostream& operator<<(std::ostream& out, const A&)<br> <br> Also, I would expect that const_self is required in the def, but it<br> seems that it doesn't matter. Is this intended behaviour or a bug?<br> <br> Cheers.<br> <br> ---------------------------------------------------------------------------= ---<br> Precog is a next-generation analytics platform capable of advanced<br> analytics on semi-structured data. The platform includes APIs for building<= br> apps and a phenomenal toolset for data science. Developers can use<br> our toolset for easy data analysis & visualization. Get a free account!= <br> <a href=3D"http://www2.precog.com/precogplatform/slashdotnewsletter" target= =3D"_blank">http://www2.precog.com/precogplatform/slashdotnewsletter</a><br= > _______________________________________________<br> luabind-user mailing list<br> <a href=3D"mailto:[email protected]">[email protected]= urceforge.net</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/luabind-user" targe= t=3D"_blank">https://lists.sourceforge.net/lists/listinfo/luabind-user</a><= br> </blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>Szymon Gatne= r<br>The Lordz Games Studio<br><a href=3D"http://www.thelordzgamesstudio.co= m" target=3D"_blank">www.thelordzgamesstudio.com</a> </div> --047d7b5dbbe4fb7b4504da9ddcf5-- --===============7973288051008614511== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter --===============7973288051008614511== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ luabind-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/luabind-user --===============7973288051008614511==--