Re: tostring operator doesn't compile if argument is non const
Lorenzo Pistone <[email protected]> Thu, 18 Apr 2013 10:00:44 +0200
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --===============1101890220364606154== Content-Type: multipart/alternative; boundary="------------030004030007050800070403" This is a multi-part message in MIME format. --------------030004030007050800070403 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Well, the code I'm trying to build has them, and I agree that it's not a wise choice in the C++ side, but if I have to export that API I would like to do it correctly. On 04/18/2013 09:50 AM, Szymon Gatner wrote: > 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] > <mailto:[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] > <mailto:[email protected]> > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > -- > Szymon Gatner > The Lordz Games Studio > www.thelordzgamesstudio.com <http://www.thelordzgamesstudio.com> > > > ------------------------------------------------------------------------------ > 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 --------------030004030007050800070403 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#FFFFFF" text="#000000"> <div class="moz-cite-prefix"><tt>Well, the code I'm trying to build has them, and I agree that it's not a wise choice in the C++ side, but if I have to export that API I would like to do it correctly.</tt><br> <br> On 04/18/2013 09:50 AM, Szymon Gatner wrote:<br> </div> <blockquote cite="mid:CALqx0+VkoHCtkf9kmeXEug-Ja4eD+rM1HT0niShxyHREho7-9A@mail.gmail.com" type="cite"> <div dir="ltr">Mutating streaming operator is not idiomatic anyway and will cause problems in other C++ code. Why do you need it to be mutating?</div> <div class="gmail_extra"><br> <br> <div class="gmail_quote">2013/4/10 Lorenzo Pistone <span dir="ltr"><<a moz-do-not-send="true" href="mailto:[email protected]" target="_blank">[email protected]</a>></span><br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br> the example in the docs to bind the tostring operator<br> (<a moz-do-not-send="true" href="http://www.rasterbar.com/products/luabind/docs.html#operators" target="_blank">http://www.rasterbar.com/products/luabind/docs.html#operators</a>) doesn't<br> compile. I write it here for reference:<br> <br> #include <luabind/luabind.hpp><br> #include <luabind/operator.hpp><br> #include <ostream><br> class number {};<br> std::ostream& operator<<(std::ostream& o, number&){ return o; }<br> int main(){<br> lua_State* L = NULL;<br> using namespace luabind;<br> module(L)[class_<number>("number").def(tostring(self))];<br> }<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 moz-do-not-send="true" href="http://www2.precog.com/precogplatform/slashdotnewsletter" target="_blank">http://www2.precog.com/precogplatform/slashdotnewsletter</a><br> _______________________________________________<br> luabind-user mailing list<br> <a moz-do-not-send="true" href="mailto:[email protected]">[email protected]</a><br> <a moz-do-not-send="true" href="https://lists.sourceforge.net/lists/listinfo/luabind-user" target="_blank">https://lists.sourceforge.net/lists/listinfo/luabind-user</a><br> </blockquote> </div> <br> <br clear="all"> <div><br> </div> -- <br> Szymon Gatner<br> The Lordz Games Studio<br> <a moz-do-not-send="true" href="http://www.thelordzgamesstudio.com" target="_blank">www.thelordzgamesstudio.com</a> </div> <br> <fieldset class="mimeAttachmentHeader"></fieldset> <br> <pre wrap="">------------------------------------------------------------------------------ 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! <a class="moz-txt-link-freetext" href="http://www2.precog.com/precogplatform/slashdotnewsletter">http://www2.precog.com/precogplatform/slashdotnewsletter</a></pre> <br> <fieldset class="mimeAttachmentHeader"></fieldset> <br> <pre wrap="">_______________________________________________ luabind-user mailing list <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a> <a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/luabind-user">https://lists.sourceforge.net/lists/listinfo/luabind-user</a> </pre> </blockquote> <br> </body> </html> --------------030004030007050800070403-- --===============1101890220364606154== 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 --===============1101890220364606154== 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 --===============1101890220364606154==--