Boost C++ Libraries: Ticket #8360: Multiplication operator should allow non-commutative version https://svn.boost.org/trac10/ticket/8360 <p> The multipliable2 template in <code>boost/operators.hpp</code> is defined with the <code>BOOST_BINARY_OPERATOR_COMMUTATIVE</code> macro. This macro defines multiplication of types T and U in both orders in terms of <code>T *= U</code>. </p> <p> This assumes that multiplication is commutative, which is not generally true. For example when T is a nxn matrix type with double entries and U a nxn matrix with integer entries, then <code>T *= U</code> makes sense, but <code>operators.hpp</code> would define <code>U * T</code> using <code>T *= U</code>. Since matrix multiplication is not commutative, this would give wrong results. </p> <p> Suggested solution: make <code>multipliable2</code> use the NONCOMMUTATIVE macro, or add another <code>multipliable2_nc</code> template. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8360 Trac 1.4.3 Daniel Frey Tue, 02 Apr 2013 17:24:35 GMT <link>https://svn.boost.org/trac10/ticket/8360#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8360#comment:1</guid> <description> <p> Thanks for the report, but I think the problem is a bit larger than that. I started working on a successor for Boost.Operators which has explicit versions for commutative and non-commutative operators (for where is makes sense). This library also takes advantage of rvalue references, thus eliminating superfluous temporaries. If your compiler has support for rvalue references and this would be an option for you, have a look at <a class="ext-link" href="https://github.com/d-frey/operators/"><span class="icon">​</span>https://github.com/d-frey/operators/</a>. With rvalue references, there are additional optimization opportunities if the operator in question is indeed commutative, so yes, that property just got a priority bump. </p> <p> Any feedback on the library is welcome. I'll also post an announcement of this library on the Boost list shortly, with any luck (and probably some more work), I hope that this can become the base for Boost.Operators v2. </p> <p> If this is not a viable solution for you, please let me know. </p> </description> <category>Ticket</category> </item> <item> <author>Jaap Eldering <eldering@…></author> <pubDate>Wed, 03 Apr 2013 11:07:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8360#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8360#comment:2</guid> <description> <p> I haven't started using Boost.Operators yet, but it was useful to have a look at the implementation, and I've used some of its ideas. </p> <p> I'll have a look at your v2 library and let you know if I have any issues or comments (I'm using GCC versions 4.4 and higher btw.). </p> </description> <category>Ticket</category> </item> </channel> </rss>