map_mat_mat.hpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  1. #ifndef BOOST_QVM_MAP_MAT_MAT_HPP_INCLUDED
  2. #define BOOST_QVM_MAP_MAT_MAT_HPP_INCLUDED
  3. // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #include <boost/qvm/config.hpp>
  7. #include <boost/qvm/deduce_mat.hpp>
  8. #include <boost/qvm/assert.hpp>
  9. #include <boost/qvm/enable_if.hpp>
  10. #include <boost/qvm/detail/transp_impl.hpp>
  11. namespace boost { namespace qvm {
  12. namespace
  13. qvm_detail
  14. {
  15. template <int Row,class OriginalMatrix>
  16. class
  17. del_row_
  18. {
  19. del_row_( del_row_ const & );
  20. del_row_ & operator=( del_row_ const & );
  21. ~del_row_();
  22. public:
  23. template <class T>
  24. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  25. del_row_ &
  26. operator=( T const & x )
  27. {
  28. assign(*this,x);
  29. return *this;
  30. }
  31. template <class R
  32. #if __cplusplus >= 201103L
  33. , class = typename enable_if<is_mat<R> >::type
  34. #endif
  35. >
  36. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  37. operator R() const
  38. {
  39. R r;
  40. assign(r,*this);
  41. return r;
  42. }
  43. };
  44. template <int I,class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value>
  45. struct del_row_write_traits;
  46. template <int I,class OriginalMatrix>
  47. struct
  48. del_row_write_traits<I,OriginalMatrix,true>
  49. {
  50. typedef del_row_<I,OriginalMatrix> this_matrix;
  51. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  52. static int const rows=mat_traits<OriginalMatrix>::rows-1;
  53. static int const cols=mat_traits<OriginalMatrix>::cols;
  54. template <int Row,int Col>
  55. static
  56. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  57. scalar_type &
  58. write_element( this_matrix & x )
  59. {
  60. BOOST_QVM_STATIC_ASSERT(Row>=0);
  61. BOOST_QVM_STATIC_ASSERT(Row<rows);
  62. BOOST_QVM_STATIC_ASSERT(Col>=0);
  63. BOOST_QVM_STATIC_ASSERT(Col<cols);
  64. return mat_traits<OriginalMatrix>::template write_element<Row+(Row>=I),Col>(reinterpret_cast<OriginalMatrix &>(x));
  65. }
  66. static
  67. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  68. scalar_type &
  69. write_element_idx( int row, int col, this_matrix & x )
  70. {
  71. BOOST_QVM_ASSERT(row>=0);
  72. BOOST_QVM_ASSERT(row<rows);
  73. BOOST_QVM_ASSERT(col>=0);
  74. BOOST_QVM_ASSERT(col<cols);
  75. return mat_traits<OriginalMatrix>::write_element_idx(row+(row>=I),col,reinterpret_cast<OriginalMatrix &>(x));
  76. }
  77. };
  78. template <int I,class OriginalMatrix>
  79. struct
  80. del_row_write_traits<I,OriginalMatrix,false>
  81. {
  82. typedef del_row_<I,OriginalMatrix> this_matrix;
  83. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  84. static int const rows=mat_traits<OriginalMatrix>::rows-1;
  85. static int const cols=mat_traits<OriginalMatrix>::cols;
  86. template <int Row,int Col>
  87. static
  88. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  89. void
  90. write_element( this_matrix & x, scalar_type s )
  91. {
  92. BOOST_QVM_STATIC_ASSERT(Row>=0);
  93. BOOST_QVM_STATIC_ASSERT(Row<rows);
  94. BOOST_QVM_STATIC_ASSERT(Col>=0);
  95. BOOST_QVM_STATIC_ASSERT(Col<cols);
  96. mat_traits<OriginalMatrix>::template write_element<Row+(Row>=I),Col>(reinterpret_cast<OriginalMatrix &>(x), s);
  97. }
  98. static
  99. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  100. void
  101. write_element_idx( int row, int col, this_matrix & x, scalar_type s )
  102. {
  103. BOOST_QVM_ASSERT(row>=0);
  104. BOOST_QVM_ASSERT(row<rows);
  105. BOOST_QVM_ASSERT(col>=0);
  106. BOOST_QVM_ASSERT(col<cols);
  107. mat_traits<OriginalMatrix>::write_element_idx(row+(row>=I),col,reinterpret_cast<OriginalMatrix &>(x), s);
  108. }
  109. };
  110. }
  111. template <int I,class OriginalMatrix>
  112. struct
  113. mat_traits<qvm_detail::del_row_<I,OriginalMatrix> >:
  114. qvm_detail::del_row_write_traits<I,OriginalMatrix>
  115. {
  116. typedef qvm_detail::del_row_<I,OriginalMatrix> this_matrix;
  117. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  118. static int const rows=mat_traits<OriginalMatrix>::rows-1;
  119. static int const cols=mat_traits<OriginalMatrix>::cols;
  120. template <int Row,int Col>
  121. static
  122. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  123. scalar_type
  124. read_element( this_matrix const & x )
  125. {
  126. BOOST_QVM_STATIC_ASSERT(Row>=0);
  127. BOOST_QVM_STATIC_ASSERT(Row<rows);
  128. BOOST_QVM_STATIC_ASSERT(Col>=0);
  129. BOOST_QVM_STATIC_ASSERT(Col<cols);
  130. return mat_traits<OriginalMatrix>::template read_element<Row+(Row>=I),Col>(reinterpret_cast<OriginalMatrix const &>(x));
  131. }
  132. static
  133. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  134. scalar_type
  135. read_element_idx( int row, int col, this_matrix const & x )
  136. {
  137. BOOST_QVM_ASSERT(row>=0);
  138. BOOST_QVM_ASSERT(row<rows);
  139. BOOST_QVM_ASSERT(col>=0);
  140. BOOST_QVM_ASSERT(col<cols);
  141. return mat_traits<OriginalMatrix>::read_element_idx(row+(row>=I),col,reinterpret_cast<OriginalMatrix const &>(x));
  142. }
  143. };
  144. template <int J,class OriginalMatrix,int R,int C>
  145. struct
  146. deduce_mat<qvm_detail::del_row_<J,OriginalMatrix>,R,C>
  147. {
  148. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  149. };
  150. template <int J,class OriginalMatrix,int R,int C>
  151. struct
  152. deduce_mat2<qvm_detail::del_row_<J,OriginalMatrix>,qvm_detail::del_row_<J,OriginalMatrix>,R,C>
  153. {
  154. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  155. };
  156. template <int Row,class A>
  157. typename enable_if_c<
  158. is_mat<A>::value,
  159. qvm_detail::del_row_<Row,A> const &>::type
  160. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  161. del_row( A const & a )
  162. {
  163. return reinterpret_cast<typename qvm_detail::del_row_<Row,A> const &>(a);
  164. }
  165. template <int Row,class A>
  166. typename enable_if_c<
  167. is_mat<A>::value,
  168. qvm_detail::del_row_<Row,A> &>::type
  169. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  170. del_row( A & a )
  171. {
  172. return reinterpret_cast<typename qvm_detail::del_row_<Row,A> &>(a);
  173. }
  174. ////////////////////////////////////////////////
  175. namespace
  176. qvm_detail
  177. {
  178. template <int Col,class OriginalMatrix>
  179. class
  180. del_col_
  181. {
  182. del_col_( del_col_ const & );
  183. del_col_ & operator=( del_col_ const & );
  184. ~del_col_();
  185. public:
  186. template <class T>
  187. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  188. del_col_ &
  189. operator=( T const & x )
  190. {
  191. assign(*this,x);
  192. return *this;
  193. }
  194. template <class R
  195. #if __cplusplus >= 201103L
  196. , class = typename enable_if<is_mat<R> >::type
  197. #endif
  198. >
  199. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  200. operator R() const
  201. {
  202. R r;
  203. assign(r,*this);
  204. return r;
  205. }
  206. };
  207. template <int J,class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value>
  208. struct del_col_write_traits;
  209. template <int J,class OriginalMatrix>
  210. struct
  211. del_col_write_traits<J,OriginalMatrix,true>
  212. {
  213. typedef del_col_<J,OriginalMatrix> this_matrix;
  214. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  215. static int const rows=mat_traits<OriginalMatrix>::rows;
  216. static int const cols=mat_traits<OriginalMatrix>::cols-1;
  217. template <int Row,int Col>
  218. static
  219. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  220. scalar_type &
  221. write_element( this_matrix & x )
  222. {
  223. BOOST_QVM_STATIC_ASSERT(Row>=0);
  224. BOOST_QVM_STATIC_ASSERT(Row<rows);
  225. BOOST_QVM_STATIC_ASSERT(Col>=0);
  226. BOOST_QVM_STATIC_ASSERT(Col<cols);
  227. return mat_traits<OriginalMatrix>::template write_element<Row,Col+(Col>=J)>(reinterpret_cast<OriginalMatrix &>(x));
  228. }
  229. static
  230. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  231. scalar_type &
  232. write_element_idx( int row, int col, this_matrix & x )
  233. {
  234. BOOST_QVM_ASSERT(row>=0);
  235. BOOST_QVM_ASSERT(row<rows);
  236. BOOST_QVM_ASSERT(col>=0);
  237. BOOST_QVM_ASSERT(col<cols);
  238. return mat_traits<OriginalMatrix>::write_element_idx(row,col+(col>=J),reinterpret_cast<OriginalMatrix &>(x));
  239. }
  240. };
  241. template <int J,class OriginalMatrix>
  242. struct
  243. del_col_write_traits<J,OriginalMatrix,false>
  244. {
  245. typedef del_col_<J,OriginalMatrix> this_matrix;
  246. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  247. static int const rows=mat_traits<OriginalMatrix>::rows;
  248. static int const cols=mat_traits<OriginalMatrix>::cols-1;
  249. template <int Row,int Col>
  250. static
  251. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  252. void
  253. write_element( this_matrix & x, scalar_type s )
  254. {
  255. BOOST_QVM_STATIC_ASSERT(Row>=0);
  256. BOOST_QVM_STATIC_ASSERT(Row<rows);
  257. BOOST_QVM_STATIC_ASSERT(Col>=0);
  258. BOOST_QVM_STATIC_ASSERT(Col<cols);
  259. mat_traits<OriginalMatrix>::template write_element<Row,Col+(Col>=J)>(reinterpret_cast<OriginalMatrix &>(x), s);
  260. }
  261. static
  262. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  263. void
  264. write_element_idx( int row, int col, this_matrix & x, scalar_type s )
  265. {
  266. BOOST_QVM_ASSERT(row>=0);
  267. BOOST_QVM_ASSERT(row<rows);
  268. BOOST_QVM_ASSERT(col>=0);
  269. BOOST_QVM_ASSERT(col<cols);
  270. mat_traits<OriginalMatrix>::write_element_idx(row,col+(col>=J),reinterpret_cast<OriginalMatrix &>(x), s);
  271. }
  272. };
  273. }
  274. template <int J,class OriginalMatrix>
  275. struct
  276. mat_traits<qvm_detail::del_col_<J,OriginalMatrix> >:
  277. qvm_detail::del_col_write_traits<J,OriginalMatrix>
  278. {
  279. typedef qvm_detail::del_col_<J,OriginalMatrix> this_matrix;
  280. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  281. static int const rows=mat_traits<OriginalMatrix>::rows;
  282. static int const cols=mat_traits<OriginalMatrix>::cols-1;
  283. template <int Row,int Col>
  284. static
  285. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  286. scalar_type
  287. read_element( this_matrix const & x )
  288. {
  289. BOOST_QVM_STATIC_ASSERT(Row>=0);
  290. BOOST_QVM_STATIC_ASSERT(Row<rows);
  291. BOOST_QVM_STATIC_ASSERT(Col>=0);
  292. BOOST_QVM_STATIC_ASSERT(Col<cols);
  293. return mat_traits<OriginalMatrix>::template read_element<Row,Col+(Col>=J)>(reinterpret_cast<OriginalMatrix const &>(x));
  294. }
  295. static
  296. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  297. scalar_type
  298. read_element_idx( int row, int col, this_matrix const & x )
  299. {
  300. BOOST_QVM_ASSERT(row>=0);
  301. BOOST_QVM_ASSERT(row<rows);
  302. BOOST_QVM_ASSERT(col>=0);
  303. BOOST_QVM_ASSERT(col<cols);
  304. return mat_traits<OriginalMatrix>::read_element_idx(row,col+(col>=J),reinterpret_cast<OriginalMatrix const &>(x));
  305. }
  306. };
  307. template <int J,class OriginalMatrix,int R,int C>
  308. struct
  309. deduce_mat<qvm_detail::del_col_<J,OriginalMatrix>,R,C>
  310. {
  311. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  312. };
  313. template <int J,class OriginalMatrix,int R,int C>
  314. struct
  315. deduce_mat2<qvm_detail::del_col_<J,OriginalMatrix>,qvm_detail::del_col_<J,OriginalMatrix>,R,C>
  316. {
  317. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  318. };
  319. template <int Col,class A>
  320. typename enable_if_c<
  321. is_mat<A>::value,
  322. qvm_detail::del_col_<Col,A> const &>::type
  323. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  324. del_col( A const & a )
  325. {
  326. return reinterpret_cast<typename qvm_detail::del_col_<Col,A> const &>(a);
  327. }
  328. template <int Col,class A>
  329. typename enable_if_c<
  330. is_mat<A>::value,
  331. qvm_detail::del_col_<Col,A> &>::type
  332. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  333. del_col( A & a )
  334. {
  335. return reinterpret_cast<typename qvm_detail::del_col_<Col,A> &>(a);
  336. }
  337. ////////////////////////////////////////////////
  338. namespace
  339. qvm_detail
  340. {
  341. template <int Row,int Col,class OriginalMatrix>
  342. class
  343. del_row_col_
  344. {
  345. del_row_col_( del_row_col_ const & );
  346. ~del_row_col_();
  347. public:
  348. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  349. del_row_col_ &
  350. operator=( del_row_col_ const & x )
  351. {
  352. assign(*this,x);
  353. return *this;
  354. }
  355. template <class T>
  356. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  357. del_row_col_ &
  358. operator=( T const & x )
  359. {
  360. assign(*this,x);
  361. return *this;
  362. }
  363. template <class R
  364. #if __cplusplus >= 201103L
  365. , class = typename enable_if<is_mat<R> >::type
  366. #endif
  367. >
  368. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  369. operator R() const
  370. {
  371. R r;
  372. assign(r,*this);
  373. return r;
  374. }
  375. };
  376. template <int I,int J,class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value>
  377. struct del_row_col_write_traits;
  378. template <int I,int J,class OriginalMatrix>
  379. struct
  380. del_row_col_write_traits<I,J,OriginalMatrix,true>
  381. {
  382. typedef del_row_col_<I,J,OriginalMatrix> this_matrix;
  383. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  384. static int const rows=mat_traits<OriginalMatrix>::rows-1;
  385. static int const cols=mat_traits<OriginalMatrix>::cols-1;
  386. template <int Row,int Col>
  387. static
  388. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  389. scalar_type &
  390. write_element( this_matrix & x )
  391. {
  392. BOOST_QVM_STATIC_ASSERT(Row>=0);
  393. BOOST_QVM_STATIC_ASSERT(Row<rows);
  394. BOOST_QVM_STATIC_ASSERT(Col>=0);
  395. BOOST_QVM_STATIC_ASSERT(Col<cols);
  396. return mat_traits<OriginalMatrix>::template write_element<Row+(Row>=I),Col+(Col>=J)>(reinterpret_cast<OriginalMatrix &>(x));
  397. }
  398. static
  399. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  400. scalar_type &
  401. write_element_idx( int row, int col, this_matrix & x )
  402. {
  403. BOOST_QVM_ASSERT(row>=0);
  404. BOOST_QVM_ASSERT(row<rows);
  405. BOOST_QVM_ASSERT(col>=0);
  406. BOOST_QVM_ASSERT(col<cols);
  407. return mat_traits<OriginalMatrix>::write_element_idx(row+(row>=I),col+(col>=J),reinterpret_cast<OriginalMatrix &>(x));
  408. }
  409. };
  410. template <int I,int J,class OriginalMatrix>
  411. struct
  412. del_row_col_write_traits<I,J,OriginalMatrix,false>
  413. {
  414. typedef del_row_col_<I,J,OriginalMatrix> this_matrix;
  415. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  416. static int const rows=mat_traits<OriginalMatrix>::rows-1;
  417. static int const cols=mat_traits<OriginalMatrix>::cols-1;
  418. template <int Row,int Col>
  419. static
  420. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  421. void
  422. write_element( this_matrix & x, scalar_type s )
  423. {
  424. BOOST_QVM_STATIC_ASSERT(Row>=0);
  425. BOOST_QVM_STATIC_ASSERT(Row<rows);
  426. BOOST_QVM_STATIC_ASSERT(Col>=0);
  427. BOOST_QVM_STATIC_ASSERT(Col<cols);
  428. mat_traits<OriginalMatrix>::template write_element<Row+(Row>=I),Col+(Col>=J)>(reinterpret_cast<OriginalMatrix &>(x), s);
  429. }
  430. static
  431. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  432. void
  433. write_element_idx( int row, int col, this_matrix & x, scalar_type s )
  434. {
  435. BOOST_QVM_ASSERT(row>=0);
  436. BOOST_QVM_ASSERT(row<rows);
  437. BOOST_QVM_ASSERT(col>=0);
  438. BOOST_QVM_ASSERT(col<cols);
  439. mat_traits<OriginalMatrix>::write_element_idx(row+(row>=I),col+(col>=J),reinterpret_cast<OriginalMatrix &>(x), s);
  440. }
  441. };
  442. }
  443. template <int I,int J,class OriginalMatrix>
  444. struct
  445. mat_traits<qvm_detail::del_row_col_<I,J,OriginalMatrix> >:
  446. qvm_detail::del_row_col_write_traits<I,J,OriginalMatrix>
  447. {
  448. typedef qvm_detail::del_row_col_<I,J,OriginalMatrix> this_matrix;
  449. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  450. static int const rows=mat_traits<OriginalMatrix>::rows-1;
  451. static int const cols=mat_traits<OriginalMatrix>::cols-1;
  452. template <int Row,int Col>
  453. static
  454. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  455. scalar_type
  456. read_element( this_matrix const & x )
  457. {
  458. BOOST_QVM_STATIC_ASSERT(Row>=0);
  459. BOOST_QVM_STATIC_ASSERT(Row<rows);
  460. BOOST_QVM_STATIC_ASSERT(Col>=0);
  461. BOOST_QVM_STATIC_ASSERT(Col<cols);
  462. return mat_traits<OriginalMatrix>::template read_element<Row+(Row>=I),Col+(Col>=J)>(reinterpret_cast<OriginalMatrix const &>(x));
  463. }
  464. static
  465. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  466. scalar_type
  467. read_element_idx( int row, int col, this_matrix const & x )
  468. {
  469. BOOST_QVM_ASSERT(row>=0);
  470. BOOST_QVM_ASSERT(row<rows);
  471. BOOST_QVM_ASSERT(col>=0);
  472. BOOST_QVM_ASSERT(col<cols);
  473. return mat_traits<OriginalMatrix>::read_element_idx(row+(row>=I),col+(col>=J),reinterpret_cast<OriginalMatrix const &>(x));
  474. }
  475. };
  476. template <int I,int J,class OriginalMatrix,int R,int C>
  477. struct
  478. deduce_mat<qvm_detail::del_row_col_<I,J,OriginalMatrix>,R,C>
  479. {
  480. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  481. };
  482. template <int I,int J,class OriginalMatrix,int R,int C>
  483. struct
  484. deduce_mat2<qvm_detail::del_row_col_<I,J,OriginalMatrix>,qvm_detail::del_row_col_<I,J,OriginalMatrix>,R,C>
  485. {
  486. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  487. };
  488. template <int Row,int Col,class A>
  489. typename enable_if_c<
  490. is_mat<A>::value,
  491. qvm_detail::del_row_col_<Row,Col,A> const &>::type
  492. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  493. del_row_col( A const & a )
  494. {
  495. return reinterpret_cast<typename qvm_detail::del_row_col_<Row,Col,A> const &>(a);
  496. }
  497. template <int Row,int Col,class A>
  498. typename enable_if_c<
  499. is_mat<A>::value,
  500. qvm_detail::del_row_col_<Row,Col,A> &>::type
  501. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  502. del_row_col( A & a )
  503. {
  504. return reinterpret_cast<typename qvm_detail::del_row_col_<Row,Col,A> &>(a);
  505. }
  506. ////////////////////////////////////////////////
  507. namespace
  508. qvm_detail
  509. {
  510. template <int Row,class OriginalMatrix>
  511. class
  512. neg_row_
  513. {
  514. neg_row_( neg_row_ const & );
  515. neg_row_ & operator=( neg_row_ const & );
  516. ~neg_row_();
  517. public:
  518. template <class T>
  519. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  520. neg_row_ &
  521. operator=( T const & x )
  522. {
  523. assign(*this,x);
  524. return *this;
  525. }
  526. template <class R
  527. #if __cplusplus >= 201103L
  528. , class = typename enable_if<is_mat<R> >::type
  529. #endif
  530. >
  531. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  532. operator R() const
  533. {
  534. R r;
  535. assign(r,*this);
  536. return r;
  537. }
  538. };
  539. }
  540. template <int I,class OriginalMatrix>
  541. struct
  542. mat_traits<qvm_detail::neg_row_<I,OriginalMatrix> >
  543. {
  544. typedef qvm_detail::neg_row_<I,OriginalMatrix> this_matrix;
  545. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  546. static int const rows=mat_traits<OriginalMatrix>::rows;
  547. static int const cols=mat_traits<OriginalMatrix>::cols;
  548. template <int Row,int Col>
  549. static
  550. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  551. scalar_type
  552. read_element( this_matrix const & x )
  553. {
  554. BOOST_QVM_STATIC_ASSERT(Row>=0);
  555. BOOST_QVM_STATIC_ASSERT(Row<rows);
  556. BOOST_QVM_STATIC_ASSERT(Col>=0);
  557. BOOST_QVM_STATIC_ASSERT(Col<cols);
  558. return Row==I ?
  559. -mat_traits<OriginalMatrix>::template read_element<Row,Col>(reinterpret_cast<OriginalMatrix const &>(x)) :
  560. mat_traits<OriginalMatrix>::template read_element<Row,Col>(reinterpret_cast<OriginalMatrix const &>(x));
  561. }
  562. static
  563. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  564. scalar_type
  565. read_element_idx( int row, int col, this_matrix const & x )
  566. {
  567. BOOST_QVM_ASSERT(row>=0);
  568. BOOST_QVM_ASSERT(row<rows);
  569. BOOST_QVM_ASSERT(col>=0);
  570. BOOST_QVM_ASSERT(col<cols);
  571. return row==I?
  572. -mat_traits<OriginalMatrix>::read_element_idx(row,col,reinterpret_cast<OriginalMatrix const &>(x)) :
  573. mat_traits<OriginalMatrix>::read_element_idx(row,col,reinterpret_cast<OriginalMatrix const &>(x));
  574. }
  575. };
  576. template <int J,class OriginalMatrix,int R,int C>
  577. struct
  578. deduce_mat<qvm_detail::neg_row_<J,OriginalMatrix>,R,C>
  579. {
  580. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  581. };
  582. template <int J,class OriginalMatrix,int R,int C>
  583. struct
  584. deduce_mat2<qvm_detail::neg_row_<J,OriginalMatrix>,qvm_detail::neg_row_<J,OriginalMatrix>,R,C>
  585. {
  586. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  587. };
  588. template <int Row,class A>
  589. typename enable_if_c<
  590. is_mat<A>::value,
  591. qvm_detail::neg_row_<Row,A> const &>::type
  592. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  593. neg_row( A const & a )
  594. {
  595. return reinterpret_cast<typename qvm_detail::neg_row_<Row,A> const &>(a);
  596. }
  597. ////////////////////////////////////////////////
  598. namespace
  599. qvm_detail
  600. {
  601. template <int Col,class OriginalMatrix>
  602. class
  603. neg_col_
  604. {
  605. neg_col_( neg_col_ const & );
  606. neg_col_ & operator=( neg_col_ const & );
  607. ~neg_col_();
  608. public:
  609. template <class T>
  610. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  611. neg_col_ &
  612. operator=( T const & x )
  613. {
  614. assign(*this,x);
  615. return *this;
  616. }
  617. template <class R
  618. #if __cplusplus >= 201103L
  619. , class = typename enable_if<is_mat<R> >::type
  620. #endif
  621. >
  622. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  623. operator R() const
  624. {
  625. R r;
  626. assign(r,*this);
  627. return r;
  628. }
  629. };
  630. }
  631. template <int J,class OriginalMatrix>
  632. struct
  633. mat_traits<qvm_detail::neg_col_<J,OriginalMatrix> >
  634. {
  635. typedef qvm_detail::neg_col_<J,OriginalMatrix> this_matrix;
  636. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  637. static int const rows=mat_traits<OriginalMatrix>::rows;
  638. static int const cols=mat_traits<OriginalMatrix>::cols;
  639. template <int Row,int Col>
  640. static
  641. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  642. scalar_type
  643. read_element( this_matrix const & x )
  644. {
  645. BOOST_QVM_STATIC_ASSERT(Row>=0);
  646. BOOST_QVM_STATIC_ASSERT(Row<rows);
  647. BOOST_QVM_STATIC_ASSERT(Col>=0);
  648. BOOST_QVM_STATIC_ASSERT(Col<cols);
  649. return Col==J?
  650. -mat_traits<OriginalMatrix>::template read_element<Row,Col>(reinterpret_cast<OriginalMatrix const &>(x)) :
  651. mat_traits<OriginalMatrix>::template read_element<Row,Col>(reinterpret_cast<OriginalMatrix const &>(x));
  652. }
  653. static
  654. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  655. scalar_type
  656. read_element_idx( int row, int col, this_matrix const & x )
  657. {
  658. BOOST_QVM_ASSERT(row>=0);
  659. BOOST_QVM_ASSERT(row<rows);
  660. BOOST_QVM_ASSERT(col>=0);
  661. BOOST_QVM_ASSERT(col<cols);
  662. return col==J?
  663. -mat_traits<OriginalMatrix>::read_element_idx(row,col,reinterpret_cast<OriginalMatrix const &>(x)) :
  664. mat_traits<OriginalMatrix>::read_element_idx(row,col,reinterpret_cast<OriginalMatrix const &>(x));
  665. }
  666. };
  667. template <int J,class OriginalMatrix,int R,int C>
  668. struct
  669. deduce_mat<qvm_detail::neg_col_<J,OriginalMatrix>,R,C>
  670. {
  671. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  672. };
  673. template <int J,class OriginalMatrix,int R,int C>
  674. struct
  675. deduce_mat2<qvm_detail::neg_col_<J,OriginalMatrix>,qvm_detail::neg_col_<J,OriginalMatrix>,R,C>
  676. {
  677. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  678. };
  679. template <int Col,class A>
  680. typename enable_if_c<
  681. is_mat<A>::value,
  682. qvm_detail::neg_col_<Col,A> const &>::type
  683. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  684. neg_col( A const & a )
  685. {
  686. return reinterpret_cast<typename qvm_detail::neg_col_<Col,A> const &>(a);
  687. }
  688. ////////////////////////////////////////////////
  689. template <class A>
  690. typename enable_if_c<
  691. is_mat<A>::value,
  692. qvm_detail::transposed_<A> const &>::type
  693. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  694. transposed( A const & a )
  695. {
  696. return reinterpret_cast<typename qvm_detail::transposed_<A> const &>(a);
  697. }
  698. template <class A>
  699. typename enable_if_c<
  700. is_mat<A>::value,
  701. qvm_detail::transposed_<A> &>::type
  702. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  703. transposed( A & a )
  704. {
  705. return reinterpret_cast<typename qvm_detail::transposed_<A> &>(a);
  706. }
  707. ////////////////////////////////////////////////
  708. namespace
  709. qvm_detail
  710. {
  711. template <int Row1,int Row2,class OriginalMatrix>
  712. class
  713. swap_rows_
  714. {
  715. swap_rows_( swap_rows_ const & );
  716. swap_rows_ & operator=( swap_rows_ const & );
  717. ~swap_rows_();
  718. public:
  719. template <class T>
  720. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  721. swap_rows_ &
  722. operator=( T const & x )
  723. {
  724. assign(*this,x);
  725. return *this;
  726. }
  727. template <class R
  728. #if __cplusplus >= 201103L
  729. , class = typename enable_if<is_mat<R> >::type
  730. #endif
  731. >
  732. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  733. operator R() const
  734. {
  735. R r;
  736. assign(r,*this);
  737. return r;
  738. }
  739. };
  740. template <int R1,int R2,class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value>
  741. struct swap_rows_write_traits;
  742. template <int R1,int R2,class OriginalMatrix>
  743. struct
  744. swap_rows_write_traits<R1,R2,OriginalMatrix,true>
  745. {
  746. typedef swap_rows_<R1,R2,OriginalMatrix> this_matrix;
  747. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  748. static int const rows=mat_traits<OriginalMatrix>::rows;
  749. static int const cols=mat_traits<OriginalMatrix>::cols;
  750. template <int Row,int Col>
  751. static
  752. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  753. scalar_type &
  754. write_element( this_matrix & x )
  755. {
  756. BOOST_QVM_STATIC_ASSERT(Row>=0);
  757. BOOST_QVM_STATIC_ASSERT(Row<rows);
  758. BOOST_QVM_STATIC_ASSERT(Col>=0);
  759. BOOST_QVM_STATIC_ASSERT(Col<cols);
  760. return mat_traits<OriginalMatrix>::template write_element<(Row==R1 && R1!=R2)*R2+(Row==R2 && R1!=R2)*R1+((Row!=R1 && Row!=R2) || R1==R2)*Row,Col>(reinterpret_cast<OriginalMatrix &>(x));
  761. }
  762. static
  763. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  764. scalar_type &
  765. write_element_idx( int row, int col, this_matrix & x )
  766. {
  767. BOOST_QVM_ASSERT(row>=0);
  768. BOOST_QVM_ASSERT(row<rows);
  769. BOOST_QVM_ASSERT(col>=0);
  770. BOOST_QVM_ASSERT(col<cols);
  771. return mat_traits<OriginalMatrix>::write_element_idx(row==R1?R2:row==R2?R1:row,col,reinterpret_cast<OriginalMatrix &>(x));
  772. }
  773. };
  774. template <int R1,int R2,class OriginalMatrix>
  775. struct
  776. swap_rows_write_traits<R1,R2,OriginalMatrix,false>
  777. {
  778. typedef swap_rows_<R1,R2,OriginalMatrix> this_matrix;
  779. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  780. static int const rows=mat_traits<OriginalMatrix>::rows;
  781. static int const cols=mat_traits<OriginalMatrix>::cols;
  782. template <int Row,int Col>
  783. static
  784. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  785. void
  786. write_element( this_matrix & x, scalar_type s )
  787. {
  788. BOOST_QVM_STATIC_ASSERT(Row>=0);
  789. BOOST_QVM_STATIC_ASSERT(Row<rows);
  790. BOOST_QVM_STATIC_ASSERT(Col>=0);
  791. BOOST_QVM_STATIC_ASSERT(Col<cols);
  792. mat_traits<OriginalMatrix>::template write_element<(Row==R1 && R1!=R2)*R2+(Row==R2 && R1!=R2)*R1+((Row!=R1 && Row!=R2) || R1==R2)*Row,Col>(reinterpret_cast<OriginalMatrix &>(x), s);
  793. }
  794. static
  795. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  796. void
  797. write_element_idx( int row, int col, this_matrix & x, scalar_type s )
  798. {
  799. BOOST_QVM_ASSERT(row>=0);
  800. BOOST_QVM_ASSERT(row<rows);
  801. BOOST_QVM_ASSERT(col>=0);
  802. BOOST_QVM_ASSERT(col<cols);
  803. mat_traits<OriginalMatrix>::write_element_idx(row==R1?R2:row==R2?R1:row,col,reinterpret_cast<OriginalMatrix &>(x), s);
  804. }
  805. };
  806. }
  807. template <int R1,int R2,class OriginalMatrix>
  808. struct
  809. mat_traits<qvm_detail::swap_rows_<R1,R2,OriginalMatrix> >:
  810. qvm_detail::swap_rows_write_traits<R1,R2,OriginalMatrix>
  811. {
  812. typedef qvm_detail::swap_rows_<R1,R2,OriginalMatrix> this_matrix;
  813. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  814. static int const rows=mat_traits<OriginalMatrix>::rows;
  815. static int const cols=mat_traits<OriginalMatrix>::cols;
  816. template <int Row,int Col>
  817. static
  818. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  819. scalar_type
  820. read_element( this_matrix const & x )
  821. {
  822. BOOST_QVM_STATIC_ASSERT(Row>=0);
  823. BOOST_QVM_STATIC_ASSERT(Row<rows);
  824. BOOST_QVM_STATIC_ASSERT(Col>=0);
  825. BOOST_QVM_STATIC_ASSERT(Col<cols);
  826. return mat_traits<OriginalMatrix>::template read_element<(Row==R1 && R1!=R2)*R2+(Row==R2 && R1!=R2)*R1+((Row!=R1 && Row!=R2) || R1==R2)*Row,Col>(reinterpret_cast<OriginalMatrix const &>(x));
  827. }
  828. static
  829. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  830. scalar_type
  831. read_element_idx( int row, int col, this_matrix const & x )
  832. {
  833. BOOST_QVM_ASSERT(row>=0);
  834. BOOST_QVM_ASSERT(row<rows);
  835. BOOST_QVM_ASSERT(col>=0);
  836. BOOST_QVM_ASSERT(col<cols);
  837. return mat_traits<OriginalMatrix>::read_element_idx(row==R1?R2:row==R2?R1:row,col,reinterpret_cast<OriginalMatrix const &>(x));
  838. }
  839. };
  840. template <int R1,int R2,class OriginalMatrix,int R,int C>
  841. struct
  842. deduce_mat<qvm_detail::swap_rows_<R1,R2,OriginalMatrix>,R,C>
  843. {
  844. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  845. };
  846. template <int R1,int R2,class OriginalMatrix,int R,int C>
  847. struct
  848. deduce_mat2<qvm_detail::swap_rows_<R1,R2,OriginalMatrix>,qvm_detail::swap_rows_<R1,R2,OriginalMatrix>,R,C>
  849. {
  850. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  851. };
  852. template <int R1,int R2,class A>
  853. typename enable_if_c<
  854. is_mat<A>::value,
  855. qvm_detail::swap_rows_<R1,R2,A> const &>::type
  856. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  857. swap_rows( A const & a )
  858. {
  859. return reinterpret_cast<typename qvm_detail::swap_rows_<R1,R2,A> const &>(a);
  860. }
  861. template <int R1,int R2,class A>
  862. typename enable_if_c<
  863. is_mat<A>::value,
  864. qvm_detail::swap_rows_<R1,R2,A> &>::type
  865. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  866. swap_rows( A & a )
  867. {
  868. return reinterpret_cast<typename qvm_detail::swap_rows_<R1,R2,A> &>(a);
  869. }
  870. ////////////////////////////////////////////////
  871. namespace
  872. qvm_detail
  873. {
  874. template <int Row1,int Row2,class OriginalMatrix>
  875. class
  876. swap_cols_
  877. {
  878. swap_cols_( swap_cols_ const & );
  879. swap_cols_ & operator=( swap_cols_ const & );
  880. ~swap_cols_();
  881. public:
  882. template <class T>
  883. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  884. swap_cols_ &
  885. operator=( T const & x )
  886. {
  887. assign(*this,x);
  888. return *this;
  889. }
  890. template <class R
  891. #if __cplusplus >= 201103L
  892. , class = typename enable_if<is_mat<R> >::type
  893. #endif
  894. >
  895. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  896. operator R() const
  897. {
  898. R r;
  899. assign(r,*this);
  900. return r;
  901. }
  902. };
  903. template <int C1,int C2,class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value>
  904. struct swap_cols_write_traits;
  905. template <int C1,int C2,class OriginalMatrix>
  906. struct
  907. swap_cols_write_traits<C1,C2,OriginalMatrix,true>
  908. {
  909. typedef swap_cols_<C1,C2,OriginalMatrix> this_matrix;
  910. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  911. static int const rows=mat_traits<OriginalMatrix>::rows;
  912. static int const cols=mat_traits<OriginalMatrix>::cols;
  913. template <int Row,int Col>
  914. static
  915. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  916. scalar_type &
  917. write_element( this_matrix & x )
  918. {
  919. BOOST_QVM_STATIC_ASSERT(Row>=0);
  920. BOOST_QVM_STATIC_ASSERT(Row<rows);
  921. BOOST_QVM_STATIC_ASSERT(Col>=0);
  922. BOOST_QVM_STATIC_ASSERT(Col<cols);
  923. return mat_traits<OriginalMatrix>::template write_element<Row,(Col==C1 && C1!=C2)*C2+(Col==C2 && C1!=C2)*C1+((Col!=C1 && Col!=C2) || C1==C2)*Col>(reinterpret_cast<OriginalMatrix &>(x));
  924. }
  925. static
  926. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  927. scalar_type &
  928. write_element_idx( int row, int col, this_matrix & x )
  929. {
  930. BOOST_QVM_ASSERT(row>=0);
  931. BOOST_QVM_ASSERT(row<rows);
  932. BOOST_QVM_ASSERT(col>=0);
  933. BOOST_QVM_ASSERT(col<cols);
  934. return mat_traits<OriginalMatrix>::write_element_idx(row,col==C1?C2:col==C2?C1:col,reinterpret_cast<OriginalMatrix &>(x));
  935. }
  936. };
  937. template <int C1,int C2,class OriginalMatrix>
  938. struct
  939. swap_cols_write_traits<C1,C2,OriginalMatrix,false>
  940. {
  941. typedef swap_cols_<C1,C2,OriginalMatrix> this_matrix;
  942. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  943. static int const rows=mat_traits<OriginalMatrix>::rows;
  944. static int const cols=mat_traits<OriginalMatrix>::cols;
  945. template <int Row,int Col>
  946. static
  947. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  948. void
  949. write_element( this_matrix & x, scalar_type s )
  950. {
  951. BOOST_QVM_STATIC_ASSERT(Row>=0);
  952. BOOST_QVM_STATIC_ASSERT(Row<rows);
  953. BOOST_QVM_STATIC_ASSERT(Col>=0);
  954. BOOST_QVM_STATIC_ASSERT(Col<cols);
  955. mat_traits<OriginalMatrix>::template write_element<Row,(Col==C1 && C1!=C2)*C2+(Col==C2 && C1!=C2)*C1+((Col!=C1 && Col!=C2) || C1==C2)*Col>(reinterpret_cast<OriginalMatrix &>(x), s);
  956. }
  957. static
  958. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  959. void
  960. write_element_idx( int row, int col, this_matrix & x, scalar_type s )
  961. {
  962. BOOST_QVM_ASSERT(row>=0);
  963. BOOST_QVM_ASSERT(row<rows);
  964. BOOST_QVM_ASSERT(col>=0);
  965. BOOST_QVM_ASSERT(col<cols);
  966. mat_traits<OriginalMatrix>::write_element_idx(row,col==C1?C2:col==C2?C1:col,reinterpret_cast<OriginalMatrix &>(x), s);
  967. }
  968. };
  969. }
  970. template <int C1,int C2,class OriginalMatrix>
  971. struct
  972. mat_traits<qvm_detail::swap_cols_<C1,C2,OriginalMatrix> >:
  973. qvm_detail::swap_cols_write_traits<C1,C2,OriginalMatrix>
  974. {
  975. typedef qvm_detail::swap_cols_<C1,C2,OriginalMatrix> this_matrix;
  976. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  977. static int const rows=mat_traits<OriginalMatrix>::rows;
  978. static int const cols=mat_traits<OriginalMatrix>::cols;
  979. template <int Row,int Col>
  980. static
  981. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  982. scalar_type
  983. read_element( this_matrix const & x )
  984. {
  985. BOOST_QVM_STATIC_ASSERT(Row>=0);
  986. BOOST_QVM_STATIC_ASSERT(Row<rows);
  987. BOOST_QVM_STATIC_ASSERT(Col>=0);
  988. BOOST_QVM_STATIC_ASSERT(Col<cols);
  989. return mat_traits<OriginalMatrix>::template read_element<Row,(Col==C1 && C1!=C2)*C2+(Col==C2 && C1!=C2)*C1+((Col!=C1 && Col!=C2) || C1==C2)*Col>(reinterpret_cast<OriginalMatrix const &>(x));
  990. }
  991. static
  992. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  993. scalar_type
  994. read_element_idx( int row, int col, this_matrix const & x )
  995. {
  996. BOOST_QVM_ASSERT(row>=0);
  997. BOOST_QVM_ASSERT(row<rows);
  998. BOOST_QVM_ASSERT(col>=0);
  999. BOOST_QVM_ASSERT(col<cols);
  1000. return mat_traits<OriginalMatrix>::read_element_idx(row,col==C1?C2:col==C2?C1:col,reinterpret_cast<OriginalMatrix const &>(x));
  1001. }
  1002. };
  1003. template <int C1,int C2,class OriginalMatrix,int R,int C>
  1004. struct
  1005. deduce_mat<qvm_detail::swap_cols_<C1,C2,OriginalMatrix>,R,C>
  1006. {
  1007. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  1008. };
  1009. template <int C1,int C2,class OriginalMatrix,int R,int C>
  1010. struct
  1011. deduce_mat2<qvm_detail::swap_cols_<C1,C2,OriginalMatrix>,qvm_detail::swap_cols_<C1,C2,OriginalMatrix>,R,C>
  1012. {
  1013. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  1014. };
  1015. template <int C1,int C2,class A>
  1016. typename enable_if_c<
  1017. is_mat<A>::value,
  1018. qvm_detail::swap_cols_<C1,C2,A> const &>::type
  1019. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  1020. swap_cols( A const & a )
  1021. {
  1022. return reinterpret_cast<typename qvm_detail::swap_cols_<C1,C2,A> const &>(a);
  1023. }
  1024. template <int C1,int C2,class A>
  1025. typename enable_if_c<
  1026. is_mat<A>::value,
  1027. qvm_detail::swap_cols_<C1,C2,A> &>::type
  1028. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  1029. swap_cols( A & a )
  1030. {
  1031. return reinterpret_cast<typename qvm_detail::swap_cols_<C1,C2,A> &>(a);
  1032. }
  1033. } }
  1034. #endif