test_assign.cpp 130 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381
  1. // Boost.TypeErasure library
  2. //
  3. // Copyright 2011 Steven Watanabe
  4. //
  5. // Distributed under the Boost Software License Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // $Id$
  10. #include <boost/config.hpp>
  11. #ifdef BOOST_MSVC
  12. #pragma warning(disable:4244) // conversion from double to int
  13. #endif
  14. #include <boost/type_erasure/any.hpp>
  15. #include <boost/type_erasure/tuple.hpp>
  16. #include <boost/type_erasure/builtin.hpp>
  17. #include <boost/type_erasure/operators.hpp>
  18. #include <boost/type_erasure/any_cast.hpp>
  19. #include <boost/type_erasure/relaxed.hpp>
  20. #include <boost/mpl/vector.hpp>
  21. #define BOOST_TEST_MAIN
  22. #include <boost/test/unit_test.hpp>
  23. using namespace boost::type_erasure;
  24. using boost::core::demangle;
  25. template<class T = _self>
  26. struct common : ::boost::mpl::vector<
  27. copy_constructible<T>,
  28. typeid_<T>
  29. > {};
  30. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  31. template<class T = _self>
  32. struct movable_common : ::boost::mpl::vector<
  33. destructible<T>,
  34. constructible<T(T&&)>,
  35. typeid_<T>
  36. > {};
  37. template<class T = _self, class U = T>
  38. struct move_assignable : ::boost::mpl::vector<
  39. assignable<T, U&&>
  40. > {};
  41. #endif
  42. template<class T, bool CCtor, bool MoveCtor, bool CAssign, bool MoveAssign>
  43. struct test_class
  44. {
  45. explicit test_class(T n) : value(n) {}
  46. test_class(const test_class& src) : value(src.value)
  47. {
  48. BOOST_STATIC_ASSERT_MSG(CCtor, "Copy constructor not allowed.");
  49. }
  50. test_class& operator=(const test_class& src)
  51. {
  52. BOOST_STATIC_ASSERT_MSG(CAssign, "Copy assignment not allowed.");
  53. value = src.value;
  54. return *this;
  55. }
  56. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  57. test_class(test_class&& src) : value(src.value)
  58. {
  59. BOOST_STATIC_ASSERT_MSG(MoveCtor, "Move constructor not allowed.");
  60. src.value = 0;
  61. }
  62. test_class& operator=(test_class&& src)
  63. {
  64. BOOST_STATIC_ASSERT_MSG(MoveAssign, "Move assignment not allowed.");
  65. value = src.value;
  66. src.value = 0;
  67. return *this;
  68. }
  69. #endif
  70. bool operator==(T n) const { return value == n; }
  71. T value;
  72. };
  73. template<class T, bool CCtor, bool MoveCtor, bool CAssign, bool MoveAssign>
  74. std::ostream& operator<<(std::ostream& os, const test_class<T, CCtor, MoveCtor, CAssign, MoveAssign>& t)
  75. {
  76. return os << t.value;
  77. }
  78. enum copy_info {
  79. id_lvalue = 1,
  80. id_const_lvalue = 2,
  81. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  82. id_rvalue = 3,
  83. id_maybe_const_lvalue = id_lvalue, // used for the id of construction from a raw value
  84. #else
  85. id_rvalue = id_const_lvalue,
  86. id_maybe_const_lvalue = id_const_lvalue,
  87. #endif
  88. id_construct = 4,
  89. id_assign = 8,
  90. id_copy = 16,
  91. id_int = 32
  92. };
  93. #ifdef BOOST_MSVC
  94. #pragma warning(disable:4521) // multiple copy constructors specified
  95. #pragma warning(disable:4522) // multiple assignment operators specified
  96. #endif
  97. template<class T>
  98. struct copy_tracker
  99. {
  100. copy_tracker(const copy_tracker& src) : value(src.value), info(id_const_lvalue | id_construct | id_copy), moved_from(false) {}
  101. copy_tracker(copy_tracker& src) : value(src.value), info(id_lvalue | id_construct | id_copy), moved_from(false) {}
  102. copy_tracker& operator=(const copy_tracker& src) { value = (src.value); info = (id_const_lvalue | id_assign | id_copy); moved_from = false; return *this; }
  103. copy_tracker& operator=(copy_tracker& src) { value = (src.value); info = (id_lvalue | id_assign | id_copy); moved_from = false; return *this; }
  104. copy_tracker(const T& src) : value(src), info(id_const_lvalue | id_construct | id_int), moved_from(false) {}
  105. copy_tracker(T& src) : value(src), info(id_lvalue | id_construct | id_int), moved_from(false) {}
  106. copy_tracker& operator=(const T& src) { value = (src); info = (id_const_lvalue | id_assign | id_int); moved_from = false; return *this; }
  107. copy_tracker& operator=(T& src) { value = (src); info = (id_lvalue | id_assign | id_int); moved_from = false; return *this; }
  108. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  109. copy_tracker(copy_tracker&& src) : value(std::move(src.value)), info(id_rvalue | id_construct | id_copy), moved_from(false) { src.moved_from = true; }
  110. copy_tracker& operator=(copy_tracker&& src) { value = std::move(src.value); info = (id_rvalue | id_assign | id_copy); moved_from = false; src.moved_from = true; return *this; }
  111. copy_tracker(T&& src) : value(std::move(src)), info(id_rvalue | id_construct | id_int), moved_from(false) {}
  112. copy_tracker& operator=(T&& src) { value = std::move(src); info = (id_rvalue | id_assign | id_int); moved_from = false; return *this; }
  113. #endif
  114. template<class U>
  115. explicit copy_tracker(const U& src) : value(src), info(id_const_lvalue | id_construct | id_int), moved_from(false) {}
  116. T value;
  117. int info;
  118. bool moved_from;
  119. };
  120. template<class T>
  121. struct value_holder
  122. {
  123. typedef copy_tracker<T> type;
  124. typedef copy_tracker<T> unwrapped_type;
  125. template<class U>
  126. value_holder(const U& u) : value(u) {}
  127. type value;
  128. type get() { return value; }
  129. const unwrapped_type& unwrap() { return value; }
  130. template<class U>
  131. const U& unwrap() { return value; }
  132. };
  133. template<class C, class P>
  134. struct value_holder<any<C, P> >
  135. {
  136. typedef any<C, P> type;
  137. typedef any<C, P> unwrapped_type;
  138. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  139. template<class U>
  140. value_holder(U&& u) : value(std::forward<U>(u)) {}
  141. #else
  142. template<class U>
  143. value_holder(U& u) : value(u) {}
  144. template<class U>
  145. value_holder(const U& u) : value(u) {}
  146. #endif
  147. type value;
  148. type get() { return value; }
  149. const unwrapped_type& unwrap() { return value; }
  150. template<class U>
  151. const U& unwrap() { return any_cast<const U&>(value); }
  152. };
  153. template<class T>
  154. struct value_holder<T&>
  155. {
  156. typedef typename value_holder<T>::type& type;
  157. typedef typename value_holder<T>::unwrapped_type unwrapped_type;
  158. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  159. template<class U>
  160. value_holder(U&& u) : impl(std::forward<U>(u)) {}
  161. #else
  162. template<class U>
  163. value_holder(U& u) : impl(u) {}
  164. template<class U>
  165. value_holder(const U& u) : impl(u) {}
  166. #endif
  167. value_holder<T> impl;
  168. type get() { return impl.value; }
  169. const unwrapped_type& unwrap() { return unwrap<unwrapped_type>(); }
  170. template<class U>
  171. const U& unwrap() { return impl.template unwrap<unwrapped_type>(); }
  172. };
  173. template<class T>
  174. struct value_holder<const T&>
  175. {
  176. typedef const typename value_holder<T>::type& type;
  177. typedef typename value_holder<T>::unwrapped_type unwrapped_type;
  178. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  179. template<class U>
  180. value_holder(U&& u) : impl(std::forward<U>(u)) {}
  181. #else
  182. template<class U>
  183. value_holder(U& u) : impl(u) {}
  184. template<class U>
  185. value_holder(const U& u) : impl(u) {}
  186. #endif
  187. value_holder<T> impl;
  188. type get() { return impl.value; }
  189. const unwrapped_type& unwrap() { return unwrap<unwrapped_type>(); }
  190. template<class U>
  191. const U& unwrap() { return impl.template unwrap<unwrapped_type>(); }
  192. };
  193. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  194. template<class T>
  195. struct value_holder<T&&>
  196. {
  197. typedef typename value_holder<T>::type&& type;
  198. typedef typename value_holder<T>::unwrapped_type unwrapped_type;
  199. template<class U>
  200. value_holder(U&& u) : impl(std::forward<U>(u)) {}
  201. value_holder<T> impl;
  202. type get() { return std::move(impl.value); }
  203. const unwrapped_type& unwrap() { return unwrap<unwrapped_type>(); }
  204. template<class U>
  205. const U& unwrap() { return impl.template unwrap<unwrapped_type>(); }
  206. };
  207. #endif
  208. template<class T, class A>
  209. struct value_holder<T(A)>
  210. {
  211. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  212. template<class U>
  213. value_holder(U&& u) : init(std::forward<U>(u)), impl(init.get()) {}
  214. #else
  215. template<class U>
  216. value_holder(U& u) : init(u), impl(init.get()) {}
  217. template<class U>
  218. value_holder(const U& u) : init(u), impl(init.get()) {}
  219. #endif
  220. value_holder<A> init;
  221. value_holder<T> impl;
  222. typedef typename value_holder<T>::type type;
  223. typedef typename value_holder<A>::unwrapped_type unwrapped_type;
  224. type get() { return impl.get(); }
  225. const unwrapped_type& unwrap() { return unwrap<unwrapped_type>(); }
  226. template<class U>
  227. const U& unwrap() { return impl.template unwrap<unwrapped_type>(); }
  228. };
  229. #define TEST_ASSIGNMENT_I(LHS, RHS, result, ptr_op, R) \
  230. try \
  231. { \
  232. value_holder<LHS> lhs(17); \
  233. value_holder<RHS> rhs(23); \
  234. const void * original = any_cast<const void*>(&lhs.get()); \
  235. lhs.get() = rhs.get(); \
  236. typedef value_holder<R>::unwrapped_type expected_type; \
  237. if(const expected_type* ptr = \
  238. any_cast<const expected_type*>(&lhs.get())) \
  239. { \
  240. BOOST_TEST(ptr->value == 23); \
  241. BOOST_TEST(ptr->info == (result)); \
  242. BOOST_TEST(ptr ptr_op original); \
  243. } \
  244. else \
  245. { \
  246. BOOST_ERROR("Wrong type: Expected " \
  247. << boost::core::demangle(typeid(expected_type).name()) \
  248. << " but got " \
  249. << boost::core::demangle(typeid_of(lhs.get()).name())); \
  250. } \
  251. } \
  252. catch(bad_function_call&) \
  253. { \
  254. BOOST_ERROR("bad_function_call in " \
  255. << demangle(typeid(value_holder<LHS>::type).name()) \
  256. << " = " \
  257. << demangle(typeid(value_holder<RHS>::type).name())); \
  258. }
  259. #define TEST_ASSIGNMENT_id_dispatch(LHS, RHS, result) \
  260. TEST_ASSIGNMENT_I(LHS, RHS, result, ==, LHS)
  261. #define TEST_ASSIGNMENT_id_fallback(LHS, RHS, result) \
  262. TEST_ASSIGNMENT_I(LHS, RHS, result, !=, RHS)
  263. #define TEST_ASSIGNMENT_id_throw(LHS, RHS, result) \
  264. { \
  265. value_holder<LHS> lhs(17); \
  266. value_holder<RHS> rhs(23); \
  267. BOOST_CHECK_THROW(lhs.get() = rhs.get(), bad_function_call); \
  268. }
  269. #define TEST_ASSIGNMENT(LHS, RHS, tag, result) \
  270. BOOST_PP_CAT(TEST_ASSIGNMENT_, tag)(LHS, RHS, result)
  271. BOOST_AUTO_TEST_CASE(test_nothing)
  272. {
  273. // Nothing to test. Assignment is entirely illegal
  274. }
  275. BOOST_AUTO_TEST_CASE(test_nothing_relaxed)
  276. {
  277. typedef ::boost::mpl::vector<
  278. destructible<>,
  279. typeid_<>,
  280. constructible<_self(int)>,
  281. relaxed
  282. > test_concept;
  283. typedef test_class<int, false, false, false, false> test_type;
  284. typedef any<test_concept> any_val;
  285. typedef any<test_concept, _self&> any_ref;
  286. // Compile-time check.
  287. binding<test_concept> test_binding = make_binding< ::boost::mpl::map< ::boost::mpl::pair<_self, test_type> > >();
  288. any_val v1(test_binding, 1);
  289. // assignment of same type
  290. // different stored type
  291. // raw value
  292. // assignment to a reference
  293. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_fallback, id_rvalue | id_construct | id_copy);
  294. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  295. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  296. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  297. // reference with a different type
  298. TEST_ASSIGNMENT(any_ref&(int&), any_val&(long), id_fallback, id_rvalue | id_construct | id_copy);
  299. TEST_ASSIGNMENT(any_ref&(int&), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  300. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  301. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  302. // reference with raw value
  303. TEST_ASSIGNMENT(any_ref&(int&), int&, id_fallback, id_const_lvalue | id_construct | id_int);
  304. TEST_ASSIGNMENT(any_ref&(int&), long&, id_fallback, id_const_lvalue | id_construct | id_int);
  305. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  306. typedef any<test_concept, _self&&> any_rref;
  307. // rvalue reference as the rhs
  308. // assignment to an rvalue reference
  309. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(int), id_fallback, id_rvalue | id_construct | id_copy);
  310. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_fallback, id_const_lvalue | id_construct | id_int);
  311. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_fallback, id_const_lvalue | id_construct | id_int);
  312. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_fallback, id_const_lvalue | id_construct | id_int);
  313. // rvalue reference with a different type
  314. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(long), id_fallback, id_rvalue | id_construct | id_copy);
  315. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  316. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  317. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  318. // rvalue reference with raw value
  319. TEST_ASSIGNMENT(any_rref&(int&&), int&&, id_fallback, id_const_lvalue | id_construct | id_int);
  320. TEST_ASSIGNMENT(any_rref&(int&&), long&&, id_fallback, id_const_lvalue | id_construct | id_int);
  321. #endif
  322. }
  323. BOOST_AUTO_TEST_CASE(test_copy_assignable)
  324. {
  325. typedef ::boost::mpl::vector<
  326. destructible<>,
  327. typeid_<>,
  328. assignable<>,
  329. constructible<_self(int)>
  330. > test_concept;
  331. typedef test_class<int, false, false, true, false> test_type;
  332. typedef any<test_concept> any_val;
  333. typedef any<test_concept, _self&> any_ref;
  334. typedef any<test_concept, const _self&> any_cref;
  335. // Compile-time check.
  336. binding<test_concept> test_binding = make_binding< ::boost::mpl::map< ::boost::mpl::pair<_self, test_type> > >();
  337. any_val v1(test_binding, 1);
  338. // assignment of same type
  339. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  340. TEST_ASSIGNMENT(any_val&(int), any_val&&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  341. #endif
  342. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  343. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  344. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  345. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  346. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  347. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  348. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  349. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  350. // different stored type (undefined behavior)
  351. // raw value (compile error)
  352. // assignment to a reference
  353. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  354. TEST_ASSIGNMENT(any_ref&(int&), any_val&&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  355. #endif
  356. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  357. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  358. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  359. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  360. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  361. TEST_ASSIGNMENT(any_ref&(int&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  362. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  363. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  364. // reference with a different type (undefined behavior)
  365. // reference with raw value (compile error)
  366. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  367. typedef any<test_concept, _self&&> any_rref;
  368. // rvalue reference as the rhs
  369. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  370. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  371. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  372. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  373. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  374. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  375. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  376. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  377. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  378. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  379. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  380. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  381. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  382. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  383. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  384. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  385. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  386. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  387. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  388. // rvalue reference with a different type (undefined behavior)
  389. // rvalue reference with raw value (compile error)
  390. #endif
  391. }
  392. BOOST_AUTO_TEST_CASE(test_copy_assignable_relaxed)
  393. {
  394. typedef ::boost::mpl::vector<
  395. destructible<>,
  396. typeid_<>,
  397. assignable<>,
  398. constructible<_self(int)>,
  399. relaxed
  400. > test_concept;
  401. typedef test_class<int, false, false, true, false> test_type;
  402. typedef any<test_concept> any_val;
  403. typedef any<test_concept, _self&> any_ref;
  404. typedef any<test_concept, const _self&> any_cref;
  405. // Compile-time check.
  406. binding<test_concept> test_binding = make_binding< ::boost::mpl::map< ::boost::mpl::pair<_self, test_type> > >();
  407. any_val v1(test_binding, 1);
  408. // assignment of same type
  409. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  410. TEST_ASSIGNMENT(any_val&(int), any_val&&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  411. #endif
  412. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  413. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  414. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  415. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  416. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  417. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  418. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  419. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  420. // different stored type
  421. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  422. TEST_ASSIGNMENT(any_val&(int), any_val&&(long), id_throw, 0);
  423. #endif
  424. TEST_ASSIGNMENT(any_val&(int), any_val&(long), id_throw, 0);
  425. TEST_ASSIGNMENT(any_val&(int), any_val const&(long), id_throw, 0);
  426. TEST_ASSIGNMENT(any_val&(int), any_ref(long&), id_throw, 0);
  427. TEST_ASSIGNMENT(any_val&(int), any_ref&(long&), id_throw, 0);
  428. TEST_ASSIGNMENT(any_val&(int), any_ref const&(long&), id_throw, 0);
  429. TEST_ASSIGNMENT(any_val&(int), any_cref(long&), id_throw, 0);
  430. TEST_ASSIGNMENT(any_val&(int), any_cref&(long&), id_throw, 0);
  431. TEST_ASSIGNMENT(any_val&(int), any_cref const&(long&), id_throw, 0);
  432. // raw value
  433. TEST_ASSIGNMENT(any_val&(int), int, id_fallback, id_rvalue | id_construct | id_copy);
  434. TEST_ASSIGNMENT(any_val&(int), int&, id_fallback, id_maybe_const_lvalue | id_construct | id_copy);
  435. TEST_ASSIGNMENT(any_val&(int), int const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  436. TEST_ASSIGNMENT(any_val&(int), long, id_fallback, id_rvalue | id_construct | id_copy);
  437. TEST_ASSIGNMENT(any_val&(int), long&, id_fallback, id_maybe_const_lvalue | id_construct | id_copy);
  438. TEST_ASSIGNMENT(any_val&(int), long const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  439. // assignment to a reference
  440. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  441. TEST_ASSIGNMENT(any_ref&(int&), any_val&&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  442. #endif
  443. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  444. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  445. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  446. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  447. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  448. TEST_ASSIGNMENT(any_ref&(int&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  449. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  450. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  451. // reference with a different type
  452. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  453. TEST_ASSIGNMENT(any_ref&(int&), any_val&&(long), id_throw, 0);
  454. #endif
  455. TEST_ASSIGNMENT(any_ref&(int&), any_val&(long), id_fallback, id_rvalue | id_construct | id_copy);
  456. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(long), id_throw, 0);
  457. TEST_ASSIGNMENT(any_ref&(int&), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  458. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  459. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  460. TEST_ASSIGNMENT(any_ref&(int&), any_cref(long&), id_throw, 0);
  461. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(long&), id_throw, 0);
  462. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(long&), id_throw, 0);
  463. // reference with raw value
  464. TEST_ASSIGNMENT(any_ref&(int&), int&, id_fallback, id_const_lvalue | id_construct | id_int);
  465. TEST_ASSIGNMENT(any_ref&(int&), long&, id_fallback, id_const_lvalue | id_construct | id_int);
  466. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  467. typedef any<test_concept, _self&&> any_rref;
  468. // rvalue reference as the rhs
  469. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  470. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  471. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  472. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_throw, 0);
  473. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_throw, 0);
  474. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_throw, );
  475. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  476. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  477. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  478. TEST_ASSIGNMENT(any_ref&(int&), any_rref(long&&), id_throw, 0);
  479. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(long&&), id_throw, 0);
  480. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(long&&), id_throw, 0);
  481. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  482. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  483. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  484. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  485. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  486. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  487. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  488. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  489. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  490. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  491. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  492. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  493. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  494. // rvalue reference with a different type
  495. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(long), id_fallback, id_rvalue | id_construct | id_copy);
  496. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(long), id_throw, 0);
  497. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(long), id_throw, 0);
  498. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(long&), id_throw, 0);
  499. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(long&), id_throw, 0);
  500. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(long&), id_throw, 0);
  501. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(long&), id_throw, 0);
  502. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(long&), id_throw, 0);
  503. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(long&), id_throw, 0);
  504. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  505. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  506. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  507. // rvalue reference with raw value
  508. TEST_ASSIGNMENT(any_rref&(int&&), int&&, id_fallback, id_const_lvalue | id_construct | id_int);
  509. TEST_ASSIGNMENT(any_rref&(int&&), long&&, id_fallback, id_const_lvalue | id_construct | id_int);
  510. #endif
  511. }
  512. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  513. BOOST_AUTO_TEST_CASE(test_move_assignable)
  514. {
  515. typedef ::boost::mpl::vector<
  516. destructible<>,
  517. typeid_<>,
  518. move_assignable<>,
  519. constructible<_self(int)>
  520. > test_concept;
  521. typedef test_class<int, false, false, false, true> test_type;
  522. typedef any<test_concept> any_val;
  523. typedef any<test_concept, _self&> any_ref;
  524. // Compile-time check.
  525. binding<test_concept> test_binding = make_binding< ::boost::mpl::map< ::boost::mpl::pair<_self, test_type> > >();
  526. any_val v1(test_binding, 1);
  527. // assignment of same type
  528. TEST_ASSIGNMENT(any_val&(int), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  529. // different stored type
  530. // raw value
  531. // assignment to a reference
  532. TEST_ASSIGNMENT(any_ref&(int&), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  533. // reference with a different type
  534. // reference with raw value
  535. typedef any<test_concept, _self&&> any_rref;
  536. // rvalue reference as the rhs
  537. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  538. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  539. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  540. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  541. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  542. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);;
  543. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  544. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  545. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  546. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  547. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  548. // rvalue reference with a different type
  549. // rvalue reference with raw value
  550. }
  551. BOOST_AUTO_TEST_CASE(test_move_assignable_relaxed)
  552. {
  553. typedef ::boost::mpl::vector<
  554. destructible<>,
  555. typeid_<>,
  556. move_assignable<>,
  557. constructible<_self(int)>,
  558. relaxed
  559. > test_concept;
  560. typedef test_class<int, false, false, false, true> test_type;
  561. typedef any<test_concept> any_val;
  562. typedef any<test_concept, _self&> any_ref;
  563. // Compile-time check.
  564. binding<test_concept> test_binding = make_binding< ::boost::mpl::map< ::boost::mpl::pair<_self, test_type> > >();
  565. any_val v1(test_binding, 1);
  566. // assignment of same type
  567. TEST_ASSIGNMENT(any_val&(int), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  568. // different stored type
  569. TEST_ASSIGNMENT(any_val&(int), any_val&&(long), id_throw, 0);
  570. // raw value
  571. // assignment to a reference
  572. TEST_ASSIGNMENT(any_ref&(int&), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  573. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_fallback, id_rvalue | id_construct | id_copy);
  574. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  575. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  576. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  577. // reference with a different type
  578. TEST_ASSIGNMENT(any_ref&(int&), any_val&&(long), id_throw, 0);
  579. TEST_ASSIGNMENT(any_ref&(int&), any_val&(long), id_fallback, id_rvalue | id_construct | id_copy);
  580. TEST_ASSIGNMENT(any_ref&(int&), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  581. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  582. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  583. // reference with raw value
  584. TEST_ASSIGNMENT(any_ref&(int&), int&, id_fallback, id_const_lvalue | id_construct | id_int);
  585. TEST_ASSIGNMENT(any_ref&(int&), long&, id_fallback, id_const_lvalue | id_construct | id_int);
  586. typedef any<test_concept, _self&&> any_rref;
  587. // rvalue reference as the rhs
  588. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  589. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  590. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  591. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_throw, 0);
  592. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_throw, 0);
  593. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_throw, 0);
  594. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  595. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  596. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  597. TEST_ASSIGNMENT(any_ref&(int&), any_rref(long&&), id_throw, 0);
  598. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(long&&), id_throw, 0);
  599. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(long&&), id_throw, 0);
  600. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  601. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  602. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  603. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  604. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  605. // rvalue reference with a different type
  606. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(long), id_fallback, id_rvalue | id_construct | id_copy);
  607. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  608. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  609. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  610. // rvalue reference with raw value
  611. TEST_ASSIGNMENT(any_rref&(int&&), int&&, id_fallback, id_const_lvalue | id_construct | id_int);
  612. TEST_ASSIGNMENT(any_rref&(int&&), long&&, id_fallback, id_const_lvalue | id_construct | id_int);
  613. }
  614. #ifndef BOOST_NO_CXX11_REF_QUALIFIERS
  615. BOOST_AUTO_TEST_CASE(test_move_and_copy_assignable)
  616. {
  617. typedef ::boost::mpl::vector<
  618. destructible<>,
  619. typeid_<>,
  620. assignable<>,
  621. move_assignable<>,
  622. constructible<_self(int)>
  623. > test_concept;
  624. typedef test_class<int, false, false, true, true> test_type;
  625. typedef any<test_concept> any_val;
  626. typedef any<test_concept, _self&> any_ref;
  627. typedef any<test_concept, const _self&> any_cref;
  628. // Compile-time check.
  629. binding<test_concept> test_binding = make_binding< ::boost::mpl::map< ::boost::mpl::pair<_self, test_type> > >();
  630. any_val v1(test_binding, 1);
  631. // assignment of same type
  632. TEST_ASSIGNMENT(any_val&(int), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  633. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  634. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  635. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  636. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  637. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  638. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  639. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  640. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  641. // different stored type (undefined behavior)
  642. // raw value (compile error)
  643. // assignment to a reference
  644. TEST_ASSIGNMENT(any_ref&(int&), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  645. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  646. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  647. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  648. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  649. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  650. TEST_ASSIGNMENT(any_ref&(int&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  651. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  652. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  653. // reference with a different type (undefined behavior)
  654. // reference with raw value (compile error)
  655. typedef any<test_concept, _self&&> any_rref;
  656. // rvalue reference as the rhs
  657. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  658. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  659. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  660. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  661. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  662. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  663. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  664. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  665. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  666. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  667. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  668. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  669. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  670. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  671. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  672. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  673. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  674. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  675. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  676. // rvalue reference with a different type (undefined behavior)
  677. // rvalue reference with raw value (compile error)
  678. }
  679. BOOST_AUTO_TEST_CASE(test_move_and_copy_assignable_relaxed)
  680. {
  681. typedef ::boost::mpl::vector<
  682. destructible<>,
  683. typeid_<>,
  684. assignable<>,
  685. move_assignable<>,
  686. constructible<_self(int)>,
  687. relaxed
  688. > test_concept;
  689. typedef test_class<int, false, false, true, true> test_type;
  690. typedef any<test_concept> any_val;
  691. typedef any<test_concept, _self&> any_ref;
  692. typedef any<test_concept, const _self&> any_cref;
  693. // Compile-time check.
  694. binding<test_concept> test_binding = make_binding< ::boost::mpl::map< ::boost::mpl::pair<_self, test_type> > >();
  695. any_val v1(test_binding, 1);
  696. // assignment of same type
  697. TEST_ASSIGNMENT(any_val&(int), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  698. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  699. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  700. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  701. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  702. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  703. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  704. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  705. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  706. // different stored type
  707. TEST_ASSIGNMENT(any_val&(int), any_val&&(long), id_throw, 0);
  708. TEST_ASSIGNMENT(any_val&(int), any_val&(long), id_throw, 0);
  709. TEST_ASSIGNMENT(any_val&(int), any_val const&(long), id_throw, 0);
  710. TEST_ASSIGNMENT(any_val&(int), any_ref(long&), id_throw, 0);
  711. TEST_ASSIGNMENT(any_val&(int), any_ref&(long&), id_throw, 0);
  712. TEST_ASSIGNMENT(any_val&(int), any_ref const&(long&), id_throw, 0);
  713. TEST_ASSIGNMENT(any_val&(int), any_cref(long&), id_throw, 0);
  714. TEST_ASSIGNMENT(any_val&(int), any_cref&(long&), id_throw, 0);
  715. TEST_ASSIGNMENT(any_val&(int), any_cref const&(long&), id_throw, 0);
  716. // raw value
  717. TEST_ASSIGNMENT(any_val&(int), int, id_fallback, id_rvalue | id_construct | id_copy);
  718. TEST_ASSIGNMENT(any_val&(int), int&, id_fallback, id_lvalue | id_construct | id_copy);
  719. TEST_ASSIGNMENT(any_val&(int), int const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  720. TEST_ASSIGNMENT(any_val&(int), long, id_fallback, id_rvalue | id_construct | id_copy);
  721. TEST_ASSIGNMENT(any_val&(int), long&, id_fallback, id_lvalue | id_construct | id_copy);
  722. TEST_ASSIGNMENT(any_val&(int), long const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  723. // assignment to a reference
  724. TEST_ASSIGNMENT(any_ref&(int&), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  725. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  726. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  727. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  728. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  729. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  730. TEST_ASSIGNMENT(any_ref&(int&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  731. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  732. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  733. // reference with a different type
  734. TEST_ASSIGNMENT(any_ref&(int&), any_val&&(long), id_throw, 0);
  735. TEST_ASSIGNMENT(any_ref&(int&), any_val&(long), id_fallback, id_rvalue | id_construct | id_copy);
  736. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(long), id_throw, 0);
  737. TEST_ASSIGNMENT(any_ref&(int&), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  738. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  739. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  740. TEST_ASSIGNMENT(any_ref&(int&), any_cref(long&), id_throw, 0);
  741. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(long&), id_throw, 0);
  742. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(long&), id_throw, 0);
  743. // reference with raw value
  744. TEST_ASSIGNMENT(any_ref&(int&), int&, id_fallback, id_const_lvalue | id_construct | id_int);
  745. TEST_ASSIGNMENT(any_ref&(int&), long&, id_fallback, id_const_lvalue | id_construct | id_int);
  746. typedef any<test_concept, _self&&> any_rref;
  747. // rvalue reference as the rhs
  748. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  749. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  750. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  751. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_throw, 0);
  752. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_throw, 0);
  753. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_throw, 0);
  754. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  755. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  756. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  757. TEST_ASSIGNMENT(any_ref&(int&), any_rref(long&&), id_throw, 0);
  758. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(long&&), id_throw, 0);
  759. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(long&&), id_throw, 0);
  760. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  761. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(int), id_dispatch, id_rvalue | id_assign | id_copy);
  762. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  763. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  764. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  765. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  766. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  767. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  768. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  769. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  770. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  771. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  772. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  773. // rvalue reference with a different type
  774. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(long), id_fallback, id_rvalue | id_construct | id_copy);
  775. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(long), id_throw, 0);
  776. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(long), id_throw, 0);
  777. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(long&), id_throw, 0);
  778. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(long&), id_throw, 0);
  779. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(long&), id_throw, 0);
  780. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(long&), id_throw, 0);
  781. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(long&), id_throw, 0);
  782. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(long&), id_throw, 0);
  783. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  784. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  785. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  786. // rvalue reference with raw value
  787. TEST_ASSIGNMENT(any_rref&(int&&), int&&, id_fallback, id_const_lvalue | id_construct | id_int);
  788. TEST_ASSIGNMENT(any_rref&(int&&), long&&, id_fallback, id_const_lvalue | id_construct | id_int);
  789. }
  790. #endif // BOOST_NO_CXX11_REF_QUALIFIERS
  791. #endif // BOOST_NO_CXX11_RVALUE_REFERENCES
  792. BOOST_AUTO_TEST_CASE(test_copy_constructible_only)
  793. {
  794. // Nothing to test. Assignment is entirely illegal
  795. }
  796. BOOST_AUTO_TEST_CASE(test_copy_constructible_only_relaxed)
  797. {
  798. typedef ::boost::mpl::vector<
  799. common<>,
  800. relaxed
  801. > test_concept;
  802. typedef test_class<int, true, false, false, false> test_type;
  803. typedef any<test_concept> any_val;
  804. typedef any<test_concept, _self&> any_ref;
  805. typedef any<test_concept, const _self&> any_cref;
  806. // Compile-time check.
  807. TEST_ASSIGNMENT(any_val&(int), test_type&, id_fallback, id_maybe_const_lvalue | id_construct | id_copy);
  808. TEST_ASSIGNMENT(any_val&(int), test_type const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  809. // assignment of same type
  810. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_fallback, id_const_lvalue | id_construct | id_copy);
  811. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_fallback, id_const_lvalue | id_construct | id_copy);
  812. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_fallback, id_const_lvalue | id_construct | id_copy);
  813. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  814. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  815. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  816. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  817. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  818. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  819. // different stored type
  820. TEST_ASSIGNMENT(any_val&(int), any_val(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  821. TEST_ASSIGNMENT(any_val&(int), any_val&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  822. TEST_ASSIGNMENT(any_val&(int), any_val const&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  823. TEST_ASSIGNMENT(any_val&(int), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  824. TEST_ASSIGNMENT(any_val&(int), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  825. TEST_ASSIGNMENT(any_val&(int), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  826. TEST_ASSIGNMENT(any_val&(int), any_cref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  827. TEST_ASSIGNMENT(any_val&(int), any_cref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  828. TEST_ASSIGNMENT(any_val&(int), any_cref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  829. // raw value
  830. TEST_ASSIGNMENT(any_val&(int), int, id_fallback, id_rvalue | id_construct | id_copy);
  831. TEST_ASSIGNMENT(any_val&(int), int&, id_fallback, id_maybe_const_lvalue | id_construct | id_copy);
  832. TEST_ASSIGNMENT(any_val&(int), int const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  833. TEST_ASSIGNMENT(any_val&(int), long, id_fallback, id_rvalue | id_construct | id_copy);
  834. TEST_ASSIGNMENT(any_val&(int), long&, id_fallback, id_maybe_const_lvalue | id_construct | id_copy);
  835. TEST_ASSIGNMENT(any_val&(int), long const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  836. // assignment to a reference
  837. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_fallback, id_rvalue | id_construct | id_copy);
  838. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  839. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  840. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  841. // reference with a different type
  842. TEST_ASSIGNMENT(any_ref&(int&), any_val&(long), id_fallback, id_rvalue | id_construct | id_copy);
  843. TEST_ASSIGNMENT(any_ref&(int&), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  844. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  845. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  846. // reference with raw value
  847. TEST_ASSIGNMENT(any_ref&(int&), int&, id_fallback, id_const_lvalue | id_construct | id_int);
  848. TEST_ASSIGNMENT(any_ref&(int&), long&, id_fallback, id_const_lvalue | id_construct | id_int);
  849. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  850. typedef any<test_concept, _self&&> any_rref;
  851. // rvalue reference as the rhs
  852. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  853. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  854. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  855. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  856. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  857. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  858. // assignment to an rvalue reference
  859. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(int), id_fallback, id_rvalue | id_construct | id_copy);
  860. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_fallback, id_const_lvalue | id_construct | id_int);
  861. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_fallback, id_const_lvalue | id_construct | id_int);
  862. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_fallback, id_const_lvalue | id_construct | id_int);
  863. // rvalue reference with a different type
  864. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(long), id_fallback, id_rvalue | id_construct | id_copy);
  865. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  866. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  867. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  868. // rvalue reference with raw value
  869. TEST_ASSIGNMENT(any_rref&(int&&), int&&, id_fallback, id_const_lvalue | id_construct | id_int);
  870. TEST_ASSIGNMENT(any_rref&(int&&), long&&, id_fallback, id_const_lvalue | id_construct | id_int);
  871. #endif
  872. }
  873. BOOST_AUTO_TEST_CASE(test_copy)
  874. {
  875. typedef ::boost::mpl::vector<
  876. common<>,
  877. assignable<>
  878. > test_concept;
  879. typedef test_class<int, true, false, true, false> test_type;
  880. typedef any<test_concept> any_val;
  881. typedef any<test_concept, _self&> any_ref;
  882. typedef any<test_concept, const _self&> any_cref;
  883. // Compile-time check.
  884. TEST_ASSIGNMENT(any_val&(test_type&), any_val&(test_type&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  885. TEST_ASSIGNMENT(any_val&(test_type&), any_val&(const test_type&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  886. // assignment of same type
  887. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  888. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  889. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  890. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  891. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  892. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  893. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  894. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  895. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  896. // different stored type (undefined behavior)
  897. // raw value (compile error)
  898. // assignment to a reference
  899. TEST_ASSIGNMENT(any_ref&(int&), any_val(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  900. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  901. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  902. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  903. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  904. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  905. TEST_ASSIGNMENT(any_ref&(int&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  906. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  907. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  908. // reference with a different type (undefined behavior)
  909. // reference with raw value (compile error)
  910. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  911. typedef any<test_concept, _self&&> any_rref;
  912. // rvalue reference as the rhs
  913. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  914. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  915. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  916. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  917. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  918. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  919. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  920. TEST_ASSIGNMENT(any_rref&(int&&), any_val(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  921. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  922. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  923. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  924. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  925. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  926. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  927. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  928. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  929. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  930. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  931. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  932. // rvalue reference with a different type (undefined behavior)
  933. // rvalue reference with raw value (compile error)
  934. #endif
  935. }
  936. BOOST_AUTO_TEST_CASE(test_copy_relaxed)
  937. {
  938. typedef ::boost::mpl::vector<
  939. common<>,
  940. assignable<>,
  941. relaxed
  942. > test_concept;
  943. typedef test_class<int, true, false, true, false> test_type;
  944. typedef any<test_concept> any_val;
  945. typedef any<test_concept, _self&> any_ref;
  946. typedef any<test_concept, const _self&> any_cref;
  947. // Compile-time check.
  948. TEST_ASSIGNMENT(any_val&(int), test_type&, id_fallback, id_maybe_const_lvalue | id_construct | id_copy);
  949. TEST_ASSIGNMENT(any_val&(int), test_type const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  950. // assignment of same type
  951. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  952. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  953. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  954. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  955. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  956. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  957. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  958. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  959. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  960. // different stored type
  961. TEST_ASSIGNMENT(any_val&(int), any_val(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  962. TEST_ASSIGNMENT(any_val&(int), any_val&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  963. TEST_ASSIGNMENT(any_val&(int), any_val const&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  964. TEST_ASSIGNMENT(any_val&(int), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  965. TEST_ASSIGNMENT(any_val&(int), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  966. TEST_ASSIGNMENT(any_val&(int), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  967. TEST_ASSIGNMENT(any_val&(int), any_cref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  968. TEST_ASSIGNMENT(any_val&(int), any_cref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  969. TEST_ASSIGNMENT(any_val&(int), any_cref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  970. // raw value
  971. TEST_ASSIGNMENT(any_val&(int), int, id_fallback, id_rvalue | id_construct | id_copy);
  972. TEST_ASSIGNMENT(any_val&(int), int&, id_fallback, id_maybe_const_lvalue | id_construct | id_copy);
  973. TEST_ASSIGNMENT(any_val&(int), int const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  974. TEST_ASSIGNMENT(any_val&(int), long, id_fallback, id_rvalue | id_construct | id_copy);
  975. TEST_ASSIGNMENT(any_val&(int), long&, id_fallback, id_maybe_const_lvalue | id_construct | id_copy);
  976. TEST_ASSIGNMENT(any_val&(int), long const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  977. // assignment to a reference
  978. TEST_ASSIGNMENT(any_ref&(int&), any_val(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  979. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  980. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  981. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  982. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  983. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  984. TEST_ASSIGNMENT(any_ref&(int&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  985. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  986. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  987. // reference with a different type
  988. TEST_ASSIGNMENT(any_ref&(int&), any_val(long), id_throw, 0);
  989. TEST_ASSIGNMENT(any_ref&(int&), any_val&(long), id_fallback, id_rvalue | id_construct | id_copy);
  990. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(long), id_throw, 0);
  991. TEST_ASSIGNMENT(any_ref&(int&), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  992. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  993. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  994. TEST_ASSIGNMENT(any_ref&(int&), any_cref(long&), id_throw, 0);
  995. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(long&), id_throw, 0);
  996. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(long&), id_throw, 0);
  997. // reference with raw value
  998. TEST_ASSIGNMENT(any_ref&(int&), int&, id_fallback, id_const_lvalue | id_construct | id_int);
  999. TEST_ASSIGNMENT(any_ref&(int&), long&, id_fallback, id_const_lvalue | id_construct | id_int);
  1000. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1001. typedef any<test_concept, _self&&> any_rref;
  1002. // rvalue reference as the rhs
  1003. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1004. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1005. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1006. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1007. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1008. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1009. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1010. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1011. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1012. TEST_ASSIGNMENT(any_ref&(int&), any_rref(long&&), id_throw, 0);
  1013. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(long&&), id_throw, 0);
  1014. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(long&&), id_throw, 0);
  1015. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  1016. TEST_ASSIGNMENT(any_rref&(int&&), any_val(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1017. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1018. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1019. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1020. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1021. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1022. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1023. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1024. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1025. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1026. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1027. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1028. // rvalue reference with a different type
  1029. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(long), id_fallback, id_rvalue | id_construct | id_copy);
  1030. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(long), id_throw, 0);
  1031. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(long), id_throw, 0);
  1032. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(long&), id_throw, 0);
  1033. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(long&), id_throw, 0);
  1034. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(long&), id_throw, 0);
  1035. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(long&), id_throw, 0);
  1036. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(long&), id_throw, 0);
  1037. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(long&), id_throw, 0);
  1038. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  1039. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  1040. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  1041. // rvalue reference with raw value
  1042. TEST_ASSIGNMENT(any_rref&(int&&), int&&, id_fallback, id_const_lvalue | id_construct | id_int);
  1043. TEST_ASSIGNMENT(any_rref&(int&&), long&&, id_fallback, id_const_lvalue | id_construct | id_int);
  1044. #endif
  1045. }
  1046. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1047. BOOST_AUTO_TEST_CASE(test_copy_constructable_move_assignable)
  1048. {
  1049. typedef ::boost::mpl::vector<
  1050. common<>,
  1051. move_assignable<>
  1052. > test_concept;
  1053. typedef test_class<int, true, false, false, true> test_type;
  1054. typedef any<test_concept> any_val;
  1055. typedef any<test_concept, _self&> any_ref;
  1056. // Compile-time check.
  1057. TEST_ASSIGNMENT(any_val&(test_type&), any_val(test_type&), id_dispatch, id_rvalue | id_assign | id_copy);
  1058. TEST_ASSIGNMENT(any_val&(test_type&), any_val(test_type const&), id_dispatch, id_rvalue | id_assign | id_copy);
  1059. // assignment of same type
  1060. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1061. // different stored type
  1062. // raw value
  1063. // assignment to a reference
  1064. TEST_ASSIGNMENT(any_ref&(int&), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1065. // reference with a different type
  1066. // reference with raw value
  1067. typedef any<test_concept, _self&&> any_rref;
  1068. // rvalue reference as the rhs
  1069. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1070. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1071. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1072. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1073. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1074. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);;
  1075. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  1076. TEST_ASSIGNMENT(any_rref&(int&&), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1077. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1078. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1079. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1080. // rvalue reference with a different type
  1081. // rvalue reference with raw value
  1082. }
  1083. BOOST_AUTO_TEST_CASE(test_copy_constructable_move_assignable_relaxed)
  1084. {
  1085. typedef ::boost::mpl::vector<
  1086. common<>,
  1087. move_assignable<>,
  1088. relaxed
  1089. > test_concept;
  1090. typedef test_class<int, true, false, false, true> test_type;
  1091. typedef any<test_concept> any_val;
  1092. typedef any<test_concept, _self&> any_ref;
  1093. typedef any<test_concept, const _self&> any_cref;
  1094. // Compile-time check.
  1095. TEST_ASSIGNMENT(any_val&(int), test_type&, id_fallback, id_lvalue | id_construct | id_copy);
  1096. TEST_ASSIGNMENT(any_val&(int), test_type const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1097. // assignment of same type
  1098. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1099. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_fallback, id_const_lvalue | id_construct | id_copy);
  1100. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_fallback, id_const_lvalue | id_construct | id_copy);
  1101. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1102. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1103. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1104. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1105. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1106. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1107. // different stored type
  1108. TEST_ASSIGNMENT(any_val&(int), any_val(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1109. TEST_ASSIGNMENT(any_val&(int), any_val&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1110. TEST_ASSIGNMENT(any_val&(int), any_val const&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1111. TEST_ASSIGNMENT(any_val&(int), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1112. TEST_ASSIGNMENT(any_val&(int), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1113. TEST_ASSIGNMENT(any_val&(int), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1114. TEST_ASSIGNMENT(any_val&(int), any_cref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1115. TEST_ASSIGNMENT(any_val&(int), any_cref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1116. TEST_ASSIGNMENT(any_val&(int), any_cref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1117. // raw value
  1118. TEST_ASSIGNMENT(any_val&(int), int, id_fallback, id_rvalue | id_construct | id_copy);
  1119. TEST_ASSIGNMENT(any_val&(int), int&, id_fallback, id_lvalue | id_construct | id_copy);
  1120. TEST_ASSIGNMENT(any_val&(int), int const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1121. TEST_ASSIGNMENT(any_val&(int), long, id_fallback, id_rvalue | id_construct | id_copy);
  1122. TEST_ASSIGNMENT(any_val&(int), long&, id_fallback, id_lvalue | id_construct | id_copy);
  1123. TEST_ASSIGNMENT(any_val&(int), long const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1124. // assignment to a reference
  1125. TEST_ASSIGNMENT(any_ref&(int&), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1126. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_fallback, id_rvalue | id_construct | id_copy);
  1127. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  1128. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  1129. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_fallback, id_const_lvalue | id_construct | id_int);
  1130. // reference with a different type
  1131. TEST_ASSIGNMENT(any_ref&(int&), any_val(long), id_throw, 0);
  1132. TEST_ASSIGNMENT(any_ref&(int&), any_val&(long), id_fallback, id_rvalue | id_construct | id_copy);
  1133. TEST_ASSIGNMENT(any_ref&(int&), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  1134. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  1135. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  1136. // reference with raw value
  1137. TEST_ASSIGNMENT(any_ref&(int&), int&, id_fallback, id_const_lvalue | id_construct | id_int);
  1138. TEST_ASSIGNMENT(any_ref&(int&), long&, id_fallback, id_const_lvalue | id_construct | id_int);
  1139. typedef any<test_concept, _self&&> any_rref;
  1140. // rvalue reference as the rhs
  1141. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1142. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1143. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1144. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1145. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1146. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1147. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1148. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1149. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1150. TEST_ASSIGNMENT(any_ref&(int&), any_rref(long&&), id_throw, 0);
  1151. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(long&&), id_throw, 0);
  1152. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(long&&), id_throw, 0);
  1153. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  1154. TEST_ASSIGNMENT(any_rref&(int&&), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1155. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1156. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1157. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1158. // rvalue reference with a different type
  1159. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(long), id_fallback, id_rvalue | id_construct | id_copy);
  1160. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  1161. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  1162. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  1163. // rvalue reference with raw value
  1164. TEST_ASSIGNMENT(any_rref&(int&&), int&&, id_fallback, id_const_lvalue | id_construct | id_int);
  1165. TEST_ASSIGNMENT(any_rref&(int&&), long&&, id_fallback, id_const_lvalue | id_construct | id_int);
  1166. }
  1167. #ifndef BOOST_NO_CXX11_REF_QUALIFIERS
  1168. BOOST_AUTO_TEST_CASE(test_copy_constructible_move_and_copy_assignable)
  1169. {
  1170. typedef ::boost::mpl::vector<
  1171. common<>,
  1172. assignable<>,
  1173. move_assignable<>
  1174. > test_concept;
  1175. typedef test_class<int, true, false, true, true> test_type;
  1176. typedef any<test_concept> any_val;
  1177. typedef any<test_concept, _self&> any_ref;
  1178. typedef any<test_concept, const _self&> any_cref;
  1179. // Compile-time check.
  1180. TEST_ASSIGNMENT(any_val&(test_type&), any_val&(test_type&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1181. TEST_ASSIGNMENT(any_val&(test_type&), any_val&(const test_type&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1182. // assignment of same type
  1183. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1184. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1185. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1186. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1187. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1188. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1189. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1190. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1191. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1192. // different stored type (undefined behavior)
  1193. // raw value (compile error)
  1194. // assignment to a reference
  1195. TEST_ASSIGNMENT(any_ref&(int&), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1196. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1197. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1198. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1199. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1200. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1201. TEST_ASSIGNMENT(any_ref&(int&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1202. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1203. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1204. // reference with a different type (undefined behavior)
  1205. // reference with raw value (compile error)
  1206. typedef any<test_concept, _self&&> any_rref;
  1207. // rvalue reference as the rhs
  1208. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1209. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1210. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1211. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1212. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1213. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1214. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  1215. TEST_ASSIGNMENT(any_rref&(int&&), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1216. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1217. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1218. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1219. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1220. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1221. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1222. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1223. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1224. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1225. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1226. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1227. // rvalue reference with a different type (undefined behavior)
  1228. // rvalue reference with raw value (compile error)
  1229. }
  1230. BOOST_AUTO_TEST_CASE(test_copy_constructible_move_and_copy_assignable_relaxed)
  1231. {
  1232. typedef ::boost::mpl::vector<
  1233. common<>,
  1234. assignable<>,
  1235. move_assignable<>,
  1236. relaxed
  1237. > test_concept;
  1238. typedef test_class<int, true, false, true, true> test_type;
  1239. typedef any<test_concept> any_val;
  1240. typedef any<test_concept, _self&> any_ref;
  1241. typedef any<test_concept, const _self&> any_cref;
  1242. // Compile-time check.
  1243. TEST_ASSIGNMENT(any_val&(int), test_type&, id_fallback, id_lvalue | id_construct | id_copy);
  1244. TEST_ASSIGNMENT(any_val&(int), test_type const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1245. // assignment of same type
  1246. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1247. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1248. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1249. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1250. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1251. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1252. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1253. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1254. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1255. // different stored type
  1256. TEST_ASSIGNMENT(any_val&(int), any_val(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1257. TEST_ASSIGNMENT(any_val&(int), any_val&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1258. TEST_ASSIGNMENT(any_val&(int), any_val const&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1259. TEST_ASSIGNMENT(any_val&(int), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1260. TEST_ASSIGNMENT(any_val&(int), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1261. TEST_ASSIGNMENT(any_val&(int), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1262. TEST_ASSIGNMENT(any_val&(int), any_cref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1263. TEST_ASSIGNMENT(any_val&(int), any_cref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1264. TEST_ASSIGNMENT(any_val&(int), any_cref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1265. // raw value
  1266. TEST_ASSIGNMENT(any_val&(int), int, id_fallback, id_rvalue | id_construct | id_copy);
  1267. TEST_ASSIGNMENT(any_val&(int), int&, id_fallback, id_lvalue | id_construct | id_copy);
  1268. TEST_ASSIGNMENT(any_val&(int), int const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1269. TEST_ASSIGNMENT(any_val&(int), long, id_fallback, id_rvalue | id_construct | id_copy);
  1270. TEST_ASSIGNMENT(any_val&(int), long&, id_fallback, id_lvalue | id_construct | id_copy);
  1271. TEST_ASSIGNMENT(any_val&(int), long const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1272. // assignment to a reference
  1273. TEST_ASSIGNMENT(any_ref&(int&), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1274. TEST_ASSIGNMENT(any_ref&(int&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1275. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1276. TEST_ASSIGNMENT(any_ref&(int&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1277. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1278. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1279. TEST_ASSIGNMENT(any_ref&(int&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1280. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1281. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1282. // reference with a different type
  1283. TEST_ASSIGNMENT(any_ref&(int&), any_val(long), id_throw, 0);
  1284. TEST_ASSIGNMENT(any_ref&(int&), any_val&(long), id_fallback, id_rvalue | id_construct | id_copy);
  1285. TEST_ASSIGNMENT(any_ref&(int&), any_val const&(long), id_throw, 0);
  1286. TEST_ASSIGNMENT(any_ref&(int&), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  1287. TEST_ASSIGNMENT(any_ref&(int&), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  1288. TEST_ASSIGNMENT(any_ref&(int&), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_int);
  1289. TEST_ASSIGNMENT(any_ref&(int&), any_cref(long&), id_throw, 0);
  1290. TEST_ASSIGNMENT(any_ref&(int&), any_cref&(long&), id_throw, 0);
  1291. TEST_ASSIGNMENT(any_ref&(int&), any_cref const&(long&), id_throw, 0);
  1292. // reference with raw value
  1293. TEST_ASSIGNMENT(any_ref&(int&), int&, id_fallback, id_const_lvalue | id_construct | id_int);
  1294. TEST_ASSIGNMENT(any_ref&(int&), long&, id_fallback, id_const_lvalue | id_construct | id_int);
  1295. typedef any<test_concept, _self&&> any_rref;
  1296. // rvalue reference as the rhs
  1297. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1298. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1299. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1300. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1301. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1302. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1303. TEST_ASSIGNMENT(any_ref&(int&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1304. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1305. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1306. TEST_ASSIGNMENT(any_ref&(int&), any_rref(long&&), id_throw, 0);
  1307. TEST_ASSIGNMENT(any_ref&(int&), any_rref&(long&&), id_throw, 0);
  1308. TEST_ASSIGNMENT(any_ref&(int&), any_rref const&(long&&), id_throw, 0);
  1309. // assignment to an rvalue reference (same dispatching behavior as lvalue reference)
  1310. TEST_ASSIGNMENT(any_rref&(int&&), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1311. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1312. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1313. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1314. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1315. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1316. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1317. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1318. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1319. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1320. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1321. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1322. // rvalue reference with a different type
  1323. TEST_ASSIGNMENT(any_rref&(int&&), any_val&&(long), id_fallback, id_rvalue | id_construct | id_copy);
  1324. TEST_ASSIGNMENT(any_rref&(int&&), any_val&(long), id_throw, 0);
  1325. TEST_ASSIGNMENT(any_rref&(int&&), any_val const&(long), id_throw, 0);
  1326. TEST_ASSIGNMENT(any_rref&(int&&), any_ref(long&), id_throw, 0);
  1327. TEST_ASSIGNMENT(any_rref&(int&&), any_ref&(long&), id_throw, 0);
  1328. TEST_ASSIGNMENT(any_rref&(int&&), any_ref const&(long&), id_throw, 0);
  1329. TEST_ASSIGNMENT(any_rref&(int&&), any_cref(long&), id_throw, 0);
  1330. TEST_ASSIGNMENT(any_rref&(int&&), any_cref&(long&), id_throw, 0);
  1331. TEST_ASSIGNMENT(any_rref&(int&&), any_cref const&(long&), id_throw, 0);
  1332. TEST_ASSIGNMENT(any_rref&(int&&), any_rref(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  1333. TEST_ASSIGNMENT(any_rref&(int&&), any_rref&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  1334. TEST_ASSIGNMENT(any_rref&(int&&), any_rref const&(long&&), id_fallback, id_const_lvalue | id_construct | id_int);
  1335. // rvalue reference with raw value
  1336. TEST_ASSIGNMENT(any_rref&(int&&), int&&, id_fallback, id_const_lvalue | id_construct | id_int);
  1337. TEST_ASSIGNMENT(any_rref&(int&&), long&&, id_fallback, id_const_lvalue | id_construct | id_int);
  1338. }
  1339. #endif // BOOST_NO_CXX11_REF_QUALIFIERS
  1340. #endif // BOOST_NO_CXX11_RVALUE_REFERENCES
  1341. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_REF_QUALIFIERS)
  1342. BOOST_AUTO_TEST_CASE(test_move_and_copy_constructible_only)
  1343. {
  1344. // Nothing to test. Assignment is entirely illegal
  1345. }
  1346. BOOST_AUTO_TEST_CASE(test_move_and_copy_constructible_only_relaxed)
  1347. {
  1348. typedef ::boost::mpl::vector<
  1349. common<>,
  1350. movable_common<>,
  1351. relaxed
  1352. > test_concept;
  1353. typedef test_class<int, true, true, false, false> test_type;
  1354. typedef any<test_concept> any_val;
  1355. typedef any<test_concept, _self&> any_ref;
  1356. typedef any<test_concept, const _self&> any_cref;
  1357. typedef any<test_concept, _self&&> any_rref;
  1358. // Compile-time check.
  1359. TEST_ASSIGNMENT(any_val&(int), test_type&, id_fallback, id_lvalue | id_construct | id_copy);
  1360. TEST_ASSIGNMENT(any_val&(int), test_type const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1361. // assignment of same type
  1362. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_fallback, id_rvalue | id_construct | id_copy);
  1363. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_fallback, id_const_lvalue | id_construct | id_copy);
  1364. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_fallback, id_const_lvalue | id_construct | id_copy);
  1365. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1366. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1367. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1368. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1369. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1370. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1371. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_fallback, id_rvalue | id_construct | id_copy);
  1372. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_fallback, id_rvalue | id_construct | id_copy);
  1373. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_fallback, id_rvalue | id_construct | id_copy);
  1374. // different stored type
  1375. TEST_ASSIGNMENT(any_val&(int), any_val(long), id_fallback, id_rvalue | id_construct | id_copy);
  1376. TEST_ASSIGNMENT(any_val&(int), any_val&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1377. TEST_ASSIGNMENT(any_val&(int), any_val const&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1378. TEST_ASSIGNMENT(any_val&(int), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1379. TEST_ASSIGNMENT(any_val&(int), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1380. TEST_ASSIGNMENT(any_val&(int), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1381. TEST_ASSIGNMENT(any_val&(int), any_cref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1382. TEST_ASSIGNMENT(any_val&(int), any_cref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1383. TEST_ASSIGNMENT(any_val&(int), any_cref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1384. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1385. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1386. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1387. // raw value
  1388. TEST_ASSIGNMENT(any_val&(int), int, id_fallback, id_rvalue | id_construct | id_copy);
  1389. TEST_ASSIGNMENT(any_val&(int), int&, id_fallback, id_lvalue | id_construct | id_copy);
  1390. TEST_ASSIGNMENT(any_val&(int), int const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1391. TEST_ASSIGNMENT(any_val&(int), long, id_fallback, id_rvalue | id_construct | id_copy);
  1392. TEST_ASSIGNMENT(any_val&(int), long&, id_fallback, id_lvalue | id_construct | id_copy);
  1393. TEST_ASSIGNMENT(any_val&(int), long const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1394. }
  1395. BOOST_AUTO_TEST_CASE(test_move_and_copy_constructible_copy_assignable)
  1396. {
  1397. typedef ::boost::mpl::vector<
  1398. common<>,
  1399. movable_common<>,
  1400. assignable<>
  1401. > test_concept;
  1402. typedef test_class<int, true, true, true, false> test_type;
  1403. typedef any<test_concept> any_val;
  1404. typedef any<test_concept, _self&> any_ref;
  1405. typedef any<test_concept, const _self&> any_cref;
  1406. typedef any<test_concept, _self&&> any_rref;
  1407. // Compile-time check.
  1408. TEST_ASSIGNMENT(any_val&(test_type&), any_val&(test_type&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1409. TEST_ASSIGNMENT(any_val&(test_type&), any_val&(const test_type&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1410. // assignment of same type
  1411. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1412. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1413. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1414. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1415. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1416. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1417. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1418. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1419. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1420. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1421. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1422. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1423. // different stored type (undefined behavior)
  1424. }
  1425. BOOST_AUTO_TEST_CASE(test_move_and_copy_constructible_copy_assignable_relaxed)
  1426. {
  1427. typedef ::boost::mpl::vector<
  1428. common<>,
  1429. movable_common<>,
  1430. assignable<>,
  1431. relaxed
  1432. > test_concept;
  1433. typedef test_class<int, true, true, true, false> test_type;
  1434. typedef any<test_concept> any_val;
  1435. typedef any<test_concept, _self&> any_ref;
  1436. typedef any<test_concept, const _self&> any_cref;
  1437. typedef any<test_concept, _self&&> any_rref;
  1438. // Compile-time check.
  1439. TEST_ASSIGNMENT(any_val&(int), test_type&, id_fallback, id_lvalue | id_construct | id_copy);
  1440. TEST_ASSIGNMENT(any_val&(int), test_type const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1441. // assignment of same type
  1442. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1443. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1444. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1445. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1446. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1447. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1448. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1449. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1450. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1451. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1452. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1453. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1454. // different stored type
  1455. TEST_ASSIGNMENT(any_val&(int), any_val(long), id_fallback, id_rvalue | id_construct | id_copy);
  1456. TEST_ASSIGNMENT(any_val&(int), any_val&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1457. TEST_ASSIGNMENT(any_val&(int), any_val const&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1458. TEST_ASSIGNMENT(any_val&(int), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1459. TEST_ASSIGNMENT(any_val&(int), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1460. TEST_ASSIGNMENT(any_val&(int), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1461. TEST_ASSIGNMENT(any_val&(int), any_cref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1462. TEST_ASSIGNMENT(any_val&(int), any_cref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1463. TEST_ASSIGNMENT(any_val&(int), any_cref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1464. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1465. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1466. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1467. // raw value
  1468. TEST_ASSIGNMENT(any_val&(int), int, id_fallback, id_rvalue | id_construct | id_copy);
  1469. TEST_ASSIGNMENT(any_val&(int), int&, id_fallback, id_lvalue | id_construct | id_copy);
  1470. TEST_ASSIGNMENT(any_val&(int), int const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1471. TEST_ASSIGNMENT(any_val&(int), long, id_fallback, id_rvalue | id_construct | id_copy);
  1472. TEST_ASSIGNMENT(any_val&(int), long&, id_fallback, id_lvalue | id_construct | id_copy);
  1473. TEST_ASSIGNMENT(any_val&(int), long const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1474. }
  1475. BOOST_AUTO_TEST_CASE(test_move_and_copy_constructable_move_assignable)
  1476. {
  1477. typedef ::boost::mpl::vector<
  1478. common<>,
  1479. movable_common<>,
  1480. move_assignable<>
  1481. > test_concept;
  1482. typedef test_class<int, true, true, false, true> test_type;
  1483. typedef any<test_concept> any_val;
  1484. typedef any<test_concept, _self&&> any_rref;
  1485. // Compile-time check.
  1486. TEST_ASSIGNMENT(any_val&(test_type&), any_val(test_type), id_dispatch, id_rvalue | id_assign | id_copy);
  1487. TEST_ASSIGNMENT(any_val&(test_type&), any_val(test_type&), id_dispatch, id_rvalue | id_assign | id_copy);
  1488. TEST_ASSIGNMENT(any_val&(test_type&), any_val(test_type const&), id_dispatch, id_rvalue | id_assign | id_copy);
  1489. // assignment of same type
  1490. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1491. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1492. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1493. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1494. // different stored type
  1495. // raw value
  1496. }
  1497. BOOST_AUTO_TEST_CASE(test_move_and_copy_constructable_move_assignable_relaxed)
  1498. {
  1499. typedef ::boost::mpl::vector<
  1500. common<>,
  1501. movable_common<>,
  1502. move_assignable<>,
  1503. relaxed
  1504. > test_concept;
  1505. typedef test_class<int, true, true, false, true> test_type;
  1506. typedef any<test_concept> any_val;
  1507. typedef any<test_concept, _self&> any_ref;
  1508. typedef any<test_concept, const _self&> any_cref;
  1509. typedef any<test_concept, _self&&> any_rref;
  1510. // Compile-time check.
  1511. TEST_ASSIGNMENT(any_val&(int), test_type, id_fallback, id_rvalue | id_construct | id_copy);
  1512. TEST_ASSIGNMENT(any_val&(int), test_type&, id_fallback, id_lvalue | id_construct | id_copy);
  1513. TEST_ASSIGNMENT(any_val&(int), test_type const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1514. // assignment of same type
  1515. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1516. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_fallback, id_const_lvalue | id_construct | id_copy);
  1517. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_fallback, id_const_lvalue | id_construct | id_copy);
  1518. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1519. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1520. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1521. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1522. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1523. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1524. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1525. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1526. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1527. // different stored type
  1528. TEST_ASSIGNMENT(any_val&(int), any_val(long), id_fallback, id_rvalue | id_construct | id_copy);
  1529. TEST_ASSIGNMENT(any_val&(int), any_val&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1530. TEST_ASSIGNMENT(any_val&(int), any_val const&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1531. TEST_ASSIGNMENT(any_val&(int), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1532. TEST_ASSIGNMENT(any_val&(int), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1533. TEST_ASSIGNMENT(any_val&(int), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1534. TEST_ASSIGNMENT(any_val&(int), any_cref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1535. TEST_ASSIGNMENT(any_val&(int), any_cref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1536. TEST_ASSIGNMENT(any_val&(int), any_cref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1537. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1538. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1539. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1540. // raw value
  1541. TEST_ASSIGNMENT(any_val&(int), int, id_fallback, id_rvalue | id_construct | id_copy);
  1542. TEST_ASSIGNMENT(any_val&(int), int&, id_fallback, id_lvalue | id_construct | id_copy);
  1543. TEST_ASSIGNMENT(any_val&(int), int const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1544. TEST_ASSIGNMENT(any_val&(int), long, id_fallback, id_rvalue | id_construct | id_copy);
  1545. TEST_ASSIGNMENT(any_val&(int), long&, id_fallback, id_lvalue | id_construct | id_copy);
  1546. TEST_ASSIGNMENT(any_val&(int), long const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1547. }
  1548. BOOST_AUTO_TEST_CASE(test_move_and_copy_constructible_move_and_copy_assignable)
  1549. {
  1550. typedef ::boost::mpl::vector<
  1551. common<>,
  1552. movable_common<>,
  1553. assignable<>,
  1554. move_assignable<>
  1555. > test_concept;
  1556. typedef test_class<int, true, true, true, true> test_type;
  1557. typedef any<test_concept> any_val;
  1558. typedef any<test_concept, _self&> any_ref;
  1559. typedef any<test_concept, const _self&> any_cref;
  1560. typedef any<test_concept, _self&&> any_rref;
  1561. // Compile-time check.
  1562. TEST_ASSIGNMENT(any_val&(test_type&), any_val&(test_type), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1563. TEST_ASSIGNMENT(any_val&(test_type&), any_val&(test_type&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1564. TEST_ASSIGNMENT(any_val&(test_type&), any_val&(const test_type&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1565. // assignment of same type
  1566. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1567. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1568. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1569. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1570. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1571. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1572. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1573. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1574. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1575. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1576. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1577. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1578. // different stored type (undefined behavior)
  1579. }
  1580. BOOST_AUTO_TEST_CASE(test_move_and_copy_constructible_move_and_copy_assignable_relaxed)
  1581. {
  1582. typedef ::boost::mpl::vector<
  1583. common<>,
  1584. movable_common<>,
  1585. assignable<>,
  1586. move_assignable<>,
  1587. relaxed
  1588. > test_concept;
  1589. typedef test_class<int, true, true, true, true> test_type;
  1590. typedef any<test_concept> any_val;
  1591. typedef any<test_concept, _self&> any_ref;
  1592. typedef any<test_concept, const _self&> any_cref;
  1593. typedef any<test_concept, _self&&> any_rref;
  1594. // Compile-time check.
  1595. TEST_ASSIGNMENT(any_val&(int), test_type, id_fallback, id_rvalue | id_construct | id_copy);
  1596. TEST_ASSIGNMENT(any_val&(int), test_type&, id_fallback, id_lvalue | id_construct | id_copy);
  1597. TEST_ASSIGNMENT(any_val&(int), test_type const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1598. // assignment of same type
  1599. TEST_ASSIGNMENT(any_val&(int), any_val(int), id_dispatch, id_rvalue | id_assign | id_copy);
  1600. TEST_ASSIGNMENT(any_val&(int), any_val&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1601. TEST_ASSIGNMENT(any_val&(int), any_val const&(int), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1602. TEST_ASSIGNMENT(any_val&(int), any_ref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1603. TEST_ASSIGNMENT(any_val&(int), any_ref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1604. TEST_ASSIGNMENT(any_val&(int), any_ref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1605. TEST_ASSIGNMENT(any_val&(int), any_cref(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1606. TEST_ASSIGNMENT(any_val&(int), any_cref&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1607. TEST_ASSIGNMENT(any_val&(int), any_cref const&(int&), id_dispatch, id_const_lvalue | id_assign | id_copy);
  1608. TEST_ASSIGNMENT(any_val&(int), any_rref(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1609. TEST_ASSIGNMENT(any_val&(int), any_rref&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1610. TEST_ASSIGNMENT(any_val&(int), any_rref const&(int&&), id_dispatch, id_rvalue | id_assign | id_copy);
  1611. // different stored type
  1612. TEST_ASSIGNMENT(any_val&(int), any_val(long), id_fallback, id_rvalue | id_construct | id_copy);
  1613. TEST_ASSIGNMENT(any_val&(int), any_val&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1614. TEST_ASSIGNMENT(any_val&(int), any_val const&(long), id_fallback, id_const_lvalue | id_construct | id_copy);
  1615. TEST_ASSIGNMENT(any_val&(int), any_ref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1616. TEST_ASSIGNMENT(any_val&(int), any_ref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1617. TEST_ASSIGNMENT(any_val&(int), any_ref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1618. TEST_ASSIGNMENT(any_val&(int), any_cref(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1619. TEST_ASSIGNMENT(any_val&(int), any_cref&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1620. TEST_ASSIGNMENT(any_val&(int), any_cref const&(long&), id_fallback, id_const_lvalue | id_construct | id_copy);
  1621. TEST_ASSIGNMENT(any_val&(int), any_rref(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1622. TEST_ASSIGNMENT(any_val&(int), any_rref&(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1623. TEST_ASSIGNMENT(any_val&(int), any_rref const&(long&&), id_fallback, id_rvalue | id_construct | id_copy);
  1624. // raw value
  1625. TEST_ASSIGNMENT(any_val&(int), int, id_fallback, id_rvalue | id_construct | id_copy);
  1626. TEST_ASSIGNMENT(any_val&(int), int&, id_fallback, id_lvalue | id_construct | id_copy);
  1627. TEST_ASSIGNMENT(any_val&(int), int const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1628. TEST_ASSIGNMENT(any_val&(int), long, id_fallback, id_rvalue | id_construct | id_copy);
  1629. TEST_ASSIGNMENT(any_val&(int), long&, id_fallback, id_lvalue | id_construct | id_copy);
  1630. TEST_ASSIGNMENT(any_val&(int), long const&, id_fallback, id_const_lvalue | id_construct | id_copy);
  1631. }
  1632. #endif // BOOST_NO_RVALUE_REFERENCES || BOOST_NO_CXX11_REF_QUALIFIERS
  1633. BOOST_AUTO_TEST_CASE(test_basic_int)
  1634. {
  1635. typedef ::boost::mpl::vector<
  1636. common<>,
  1637. assignable<_self, copy_tracker<int> >
  1638. > test_concept;
  1639. typedef any<test_concept> any_val;
  1640. typedef any<test_concept, _self&> any_ref;
  1641. TEST_ASSIGNMENT(any_val&(int), int, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1642. TEST_ASSIGNMENT(any_val&(int), int&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1643. TEST_ASSIGNMENT(any_val&(int), int const&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1644. TEST_ASSIGNMENT(any_ref&(int&), int, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1645. TEST_ASSIGNMENT(any_ref&(int&), int&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1646. TEST_ASSIGNMENT(any_ref&(int&), int const&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1647. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1648. typedef any<test_concept, _self&&> any_rref;
  1649. TEST_ASSIGNMENT(any_rref&(int&&), int, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1650. TEST_ASSIGNMENT(any_rref&(int&&), int&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1651. TEST_ASSIGNMENT(any_rref&(int&&), int const&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1652. #endif
  1653. }
  1654. BOOST_AUTO_TEST_CASE(test_basic_relaxed_int)
  1655. {
  1656. typedef ::boost::mpl::vector<
  1657. common<>,
  1658. assignable<_self, copy_tracker<int> >,
  1659. relaxed
  1660. > test_concept;
  1661. typedef any<test_concept> any_val;
  1662. typedef any<test_concept, _self&> any_ref;
  1663. TEST_ASSIGNMENT(any_val&(int), int, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1664. TEST_ASSIGNMENT(any_val&(int), int&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1665. TEST_ASSIGNMENT(any_val&(int), int const&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1666. TEST_ASSIGNMENT(any_ref&(int&), int, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1667. TEST_ASSIGNMENT(any_ref&(int&), int&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1668. TEST_ASSIGNMENT(any_ref&(int&), int const&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1669. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1670. typedef any<test_concept, _self&&> any_rref;
  1671. TEST_ASSIGNMENT(any_rref&(int&&), int, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1672. TEST_ASSIGNMENT(any_rref&(int&&), int&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1673. TEST_ASSIGNMENT(any_rref&(int&&), int const&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1674. #endif
  1675. }
  1676. BOOST_AUTO_TEST_CASE(test_relaxed_no_copy_int)
  1677. {
  1678. typedef ::boost::mpl::vector<
  1679. destructible<>,
  1680. typeid_<>,
  1681. assignable<_self, copy_tracker<int> >,
  1682. relaxed
  1683. > test_concept;
  1684. typedef any<test_concept> any_val;
  1685. typedef any<test_concept, _self&> any_ref;
  1686. TEST_ASSIGNMENT(any_val&(int), int, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1687. TEST_ASSIGNMENT(any_val&(int), int&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1688. TEST_ASSIGNMENT(any_val&(int), int const&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1689. TEST_ASSIGNMENT(any_ref&(int&), int, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1690. TEST_ASSIGNMENT(any_ref&(int&), int&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1691. TEST_ASSIGNMENT(any_ref&(int&), int const&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1692. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1693. typedef any<test_concept, _self&&> any_rref;
  1694. TEST_ASSIGNMENT(any_rref&(int&&), int, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1695. TEST_ASSIGNMENT(any_rref&(int&&), int&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1696. TEST_ASSIGNMENT(any_rref&(int&&), int const&, id_dispatch, id_const_lvalue | id_assign | id_copy);
  1697. #endif
  1698. }
  1699. BOOST_AUTO_TEST_CASE(test_relaxed_no_assign_int)
  1700. {
  1701. typedef ::boost::mpl::vector<
  1702. common<>,
  1703. relaxed
  1704. > test_concept;
  1705. any<test_concept> x(1);
  1706. x = 2;
  1707. BOOST_CHECK_EQUAL(any_cast<int>(x), 2);
  1708. }
  1709. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1710. struct move_only_assign_int
  1711. {
  1712. explicit move_only_assign_int(int i)
  1713. : value(i) {}
  1714. move_only_assign_int(move_only_assign_int&& other)
  1715. : value(other.value) { other.value = 0; }
  1716. move_only_assign_int& operator=(move_only_assign_int&& other)
  1717. { value = other.value; other.value = 0; return *this; }
  1718. move_only_assign_int& operator=(int&& i)
  1719. { value = i; return *this; }
  1720. int value;
  1721. private:
  1722. move_only_assign_int(const move_only_assign_int&);
  1723. move_only_assign_int& operator=(const move_only_assign_int&);
  1724. };
  1725. struct only_assign_int
  1726. {
  1727. explicit only_assign_int(int i)
  1728. : value(i) {}
  1729. only_assign_int& operator=(int&& i)
  1730. { value = i; return *this; }
  1731. int value;
  1732. private:
  1733. only_assign_int(only_assign_int&&);
  1734. only_assign_int(const only_assign_int&);
  1735. only_assign_int& operator=(only_assign_int&&);
  1736. only_assign_int& operator=(const only_assign_int&);
  1737. };
  1738. struct move_and_copy_assign_int
  1739. {
  1740. explicit move_and_copy_assign_int(int i)
  1741. : value(i) {}
  1742. move_and_copy_assign_int& operator=(move_and_copy_assign_int&& other)
  1743. { value = other.value; other = 0; return *this; }
  1744. move_and_copy_assign_int& operator=(const move_and_copy_assign_int& other)
  1745. { value = other.value; return *this; }
  1746. move_and_copy_assign_int& operator=(int&& i)
  1747. { value = i; return *this; }
  1748. move_and_copy_assign_int& operator=(const int& i)
  1749. { value = i; return *this; }
  1750. int value;
  1751. private:
  1752. move_and_copy_assign_int(move_and_copy_assign_int&&);
  1753. move_and_copy_assign_int(const move_and_copy_assign_int&);
  1754. };
  1755. struct move_and_copy_construct_assign_int
  1756. {
  1757. explicit move_and_copy_construct_assign_int(int i)
  1758. : value(i) {}
  1759. move_and_copy_construct_assign_int(move_and_copy_construct_assign_int&& other)
  1760. : value(other.value) { other.value = 0; }
  1761. move_and_copy_construct_assign_int(const move_and_copy_construct_assign_int& other)
  1762. : value(other.value) {}
  1763. move_and_copy_construct_assign_int& operator=(move_and_copy_construct_assign_int&& other)
  1764. { value = other.value; other = 0; return *this; }
  1765. move_and_copy_construct_assign_int& operator=(const move_and_copy_construct_assign_int& other)
  1766. { value = other.value; return *this; }
  1767. move_and_copy_construct_assign_int& operator=(int&& i)
  1768. { value = i; return *this; }
  1769. move_and_copy_construct_assign_int& operator=(const int& i)
  1770. { value = i; return *this; }
  1771. int value;
  1772. };
  1773. struct copy_only_assign_int
  1774. {
  1775. explicit copy_only_assign_int(int i)
  1776. : value(i) {}
  1777. copy_only_assign_int(const copy_only_assign_int& other)
  1778. : value(other.value) {}
  1779. copy_only_assign_int& operator=(const copy_only_assign_int& other)
  1780. { value = other.value; return *this; }
  1781. copy_only_assign_int& operator=(int&& i)
  1782. { value = i; return *this; }
  1783. copy_only_assign_int& operator=(const int& i)
  1784. { value = i; return *this; }
  1785. int value;
  1786. private:
  1787. copy_only_assign_int(copy_only_assign_int&&);
  1788. copy_only_assign_int& operator=(copy_only_assign_int&&);
  1789. };
  1790. struct copy_only_assign_double
  1791. {
  1792. explicit copy_only_assign_double(double i)
  1793. : value(i) {}
  1794. copy_only_assign_double(const copy_only_assign_double& other)
  1795. : value(other.value) {}
  1796. copy_only_assign_double& operator=(const copy_only_assign_double& other)
  1797. { value = other.value; return *this; }
  1798. copy_only_assign_double& operator=(double&& i)
  1799. { value = i; return *this; }
  1800. copy_only_assign_double& operator=(const double& i)
  1801. { value = i; return *this; }
  1802. double value;
  1803. private:
  1804. copy_only_assign_double(copy_only_assign_double&&);
  1805. copy_only_assign_double& operator=(copy_only_assign_double&&);
  1806. };
  1807. BOOST_AUTO_TEST_CASE(test_movable_basic_int)
  1808. {
  1809. typedef ::boost::mpl::vector<
  1810. movable_common<>,
  1811. move_assignable<_self, int>
  1812. > test_concept;
  1813. typedef move_only_assign_int test_type;
  1814. test_type source_x(1);
  1815. any<test_concept> x(std::move(source_x));
  1816. test_type* ip = any_cast<test_type*>(&x);
  1817. x = std::move(2);
  1818. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 2);
  1819. // make sure that we're actually using assignment
  1820. // of the underlying object, not copy and swap.
  1821. BOOST_CHECK_EQUAL(any_cast<test_type*>(&x), ip);
  1822. }
  1823. BOOST_AUTO_TEST_CASE(test_movable_basic_relaxed_int)
  1824. {
  1825. typedef ::boost::mpl::vector<
  1826. movable_common<>,
  1827. move_assignable<_self, int>,
  1828. relaxed
  1829. > test_concept;
  1830. typedef move_only_assign_int test_type;
  1831. test_type source_x(1);
  1832. any<test_concept> x(std::move(source_x));
  1833. test_type* ip = any_cast<test_type*>(&x);
  1834. x = std::move(2);
  1835. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 2);
  1836. // make sure that we're actually using assignment
  1837. // of the underlying object, not copy and swap.
  1838. BOOST_CHECK_EQUAL(any_cast<test_type*>(&x), ip);
  1839. }
  1840. BOOST_AUTO_TEST_CASE(test_relaxed_no_constructible_int)
  1841. {
  1842. typedef ::boost::mpl::vector<
  1843. destructible<>,
  1844. typeid_<>,
  1845. constructible<_self(int)>,
  1846. move_assignable<_self, int>,
  1847. relaxed
  1848. > test_concept;
  1849. typedef only_assign_int test_type;
  1850. typedef ::boost::mpl::map< ::boost::mpl::pair<_self, test_type> > type;
  1851. any<test_concept> x(binding<test_concept>(make_binding<type>()), 1);
  1852. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 1);
  1853. test_type* ip = any_cast<test_type*>(&x);
  1854. x = std::move(2);
  1855. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 2);
  1856. // make sure that we're actually using assignment
  1857. // of the underlying object, not copy and swap.
  1858. BOOST_CHECK_EQUAL(any_cast<test_type*>(&x), ip);
  1859. }
  1860. BOOST_AUTO_TEST_CASE(test_movable_relaxed_no_assign_int)
  1861. {
  1862. typedef ::boost::mpl::vector<
  1863. movable_common<>,
  1864. relaxed
  1865. > test_concept;
  1866. typedef move_only_assign_int test_type;
  1867. test_type source_x(1);
  1868. any<test_concept> x(std::move(source_x));
  1869. x = test_type(2);
  1870. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 2);
  1871. }
  1872. #ifndef BOOST_NO_CXX11_REF_QUALIFIERS
  1873. BOOST_AUTO_TEST_CASE(test_move_and_copy_assignable_int)
  1874. {
  1875. typedef ::boost::mpl::vector<
  1876. destructible<>,
  1877. typeid_<>,
  1878. constructible<_self(int)>,
  1879. assignable<_self, _self>,
  1880. move_assignable<_self, _self>,
  1881. assignable<_self, int>,
  1882. move_assignable<_self, int>,
  1883. relaxed
  1884. > test_concept;
  1885. typedef move_and_copy_assign_int test_type;
  1886. typedef ::boost::mpl::map< ::boost::mpl::pair<_self, test_type> > type;
  1887. any<test_concept> x(binding<test_concept>(make_binding<type>()), 1);
  1888. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 1);
  1889. any<test_concept> y(binding<test_concept>(make_binding<type>()), 2);
  1890. x = y;
  1891. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 2);
  1892. any<test_concept> z(binding<test_concept>(make_binding<type>()), 3);
  1893. x = std::move(z);
  1894. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 3);
  1895. x = 4;
  1896. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 4);
  1897. x = std::move(5);
  1898. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 5);
  1899. }
  1900. BOOST_AUTO_TEST_CASE(test_move_and_copy_assignable_copy_construct_int)
  1901. {
  1902. typedef ::boost::mpl::vector<
  1903. common<>,
  1904. assignable<_self, _self>,
  1905. move_assignable<_self, _self>,
  1906. assignable<_self, int>,
  1907. move_assignable<_self, int>,
  1908. relaxed
  1909. > test_concept;
  1910. typedef move_and_copy_construct_assign_int test_type;
  1911. test_type source_x(1);
  1912. test_type source_y(2);
  1913. test_type source_z(3);
  1914. any<test_concept> x(source_x);
  1915. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 1);
  1916. test_type* ip = any_cast<test_type*>(&x);
  1917. any<test_concept> y(source_y);
  1918. x = y;
  1919. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 2);
  1920. // make sure that we're actually using assignment
  1921. // of the underlying object, not copy and swap.
  1922. BOOST_CHECK_EQUAL(any_cast<test_type*>(&x), ip);
  1923. any<test_concept> z(source_z);
  1924. x = std::move(z);
  1925. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 3);
  1926. // make sure that we're actually using move-assignment
  1927. // of the underlying object, not copy and swap.
  1928. BOOST_CHECK_EQUAL(any_cast<test_type*>(&x), ip);
  1929. x = 4;
  1930. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 4);
  1931. // make sure that we're actually using assignment
  1932. // of the underlying object, not copy and swap.
  1933. BOOST_CHECK_EQUAL(any_cast<test_type*>(&x), ip);
  1934. x = std::move(5);
  1935. BOOST_CHECK_EQUAL(any_cast<const test_type&>(x).value, 5);
  1936. // make sure that we're actually using move-assignment
  1937. // of the underlying object, not copy and swap.
  1938. BOOST_CHECK_EQUAL(any_cast<test_type*>(&x), ip);
  1939. }
  1940. #endif // BOOST_NO_CXX11_REF_QUALIFIERS
  1941. BOOST_AUTO_TEST_CASE(test_assignable_with_conversion)
  1942. {
  1943. typedef ::boost::mpl::vector<
  1944. destructible<>,
  1945. typeid_<>,
  1946. assignable<_self, int>,
  1947. relaxed
  1948. > test_concept;
  1949. typedef move_and_copy_construct_assign_int test_type1;
  1950. typedef copy_only_assign_int test_type2;
  1951. typedef copy_only_assign_double test_type3;
  1952. test_type1 source_x(1);
  1953. any<test_concept> x(source_x);
  1954. BOOST_CHECK_EQUAL(any_cast<const test_type1&>(x).value, 1);
  1955. // assigning raw values is supported because "relaxed" is in concept.
  1956. test_type2 source_y(2);
  1957. x = source_y;
  1958. BOOST_CHECK_EQUAL(any_cast<const test_type2&>(x).value, 2);
  1959. // move-assigning raw values is supported because "relaxed" is in concept.
  1960. x = test_type1(3);
  1961. BOOST_CHECK_EQUAL(any_cast<const test_type1&>(x).value, 3);
  1962. // assigning int is supported because appropriate "assignable" is in concept.
  1963. int int4 = 4;
  1964. x = int4;
  1965. BOOST_CHECK_EQUAL(any_cast<const test_type1&>(x).value, 4);
  1966. int int5 = 5;
  1967. x = std::move(int5);
  1968. BOOST_CHECK_EQUAL(any_cast<const test_type1&>(x).value, 5);
  1969. // assigning double (which is implicitly convertible to int) is supported
  1970. // because appropriate "assignable" is in concept.
  1971. double double6 = 6.5;
  1972. x = double6; // truncates value
  1973. BOOST_CHECK_EQUAL(any_cast<const test_type1&>(x).value, 6);
  1974. double double7 = 7.5;
  1975. x = std::move(double7); // truncates value
  1976. BOOST_CHECK_EQUAL(any_cast<const test_type1&>(x).value, 7);
  1977. // assigning raw values is supported because "relaxed" is in concept.
  1978. test_type3 source_z(8.5);
  1979. x = source_z;
  1980. BOOST_CHECK_EQUAL(any_cast<const test_type3&>(x).value, 8.5);
  1981. // assigning double (which is implicitly convertible to int) is supported
  1982. // because appropriate "assignable" is in concept.
  1983. double double9 = 9.5;
  1984. x = double9; // truncates value
  1985. BOOST_CHECK_EQUAL(any_cast<const test_type3&>(x).value, 9.0);
  1986. double double10 = 10.5;
  1987. x = std::move(double10); // truncates value
  1988. BOOST_CHECK_EQUAL(any_cast<const test_type3&>(x).value, 10.0);
  1989. }
  1990. BOOST_AUTO_TEST_CASE(test_move_assignable_with_conversion)
  1991. {
  1992. typedef ::boost::mpl::vector<
  1993. destructible<>,
  1994. typeid_<>,
  1995. move_assignable<_self, int>,
  1996. relaxed
  1997. > test_concept;
  1998. typedef move_and_copy_construct_assign_int test_type1;
  1999. typedef copy_only_assign_int test_type2;
  2000. typedef copy_only_assign_double test_type3;
  2001. test_type1 source_x(1);
  2002. any<test_concept> x(source_x);
  2003. BOOST_CHECK_EQUAL(any_cast<const test_type1&>(x).value, 1);
  2004. // assigning raw values is supported because "relaxed" is in concept.
  2005. test_type2 source_y(2);
  2006. x = source_y;
  2007. BOOST_CHECK_EQUAL(any_cast<const test_type2&>(x).value, 2);
  2008. // move-assigning raw values is supported because "relaxed" is in concept.
  2009. x = test_type1(3);
  2010. BOOST_CHECK_EQUAL(any_cast<const test_type1&>(x).value, 3);
  2011. // move-assigning int is supported because appropriate "move_assignable" is in concept.
  2012. int int4 = 4;
  2013. x = std::move(int4);
  2014. BOOST_CHECK_EQUAL(any_cast<const test_type1&>(x).value, 4);
  2015. // copy-assigning int is assigning a raw_value.
  2016. int int5 = 5;
  2017. x = int5;
  2018. BOOST_CHECK_EQUAL(any_cast<const int&>(x), 5);
  2019. x = source_x; // reset.
  2020. // move-assigning double (which is implicitly convertible to int) is supported
  2021. // because appropriate "move_assignable" is in concept.
  2022. double double6 = 6.5;
  2023. x = std::move(double6); // truncates value
  2024. BOOST_CHECK_EQUAL(any_cast<const test_type1&>(x).value, 6);
  2025. // assigning raw values is supported because "relaxed" is in concept.
  2026. test_type3 source_z(8.5);
  2027. x = source_z;
  2028. BOOST_CHECK_EQUAL(any_cast<const test_type3&>(x).value, 8.5);
  2029. // move-assigning double (which is implicitly convertible to int) is supported
  2030. // because appropriate "move_assignable" is in concept.
  2031. double double9 = 9.5;
  2032. x = std::move(double9); // truncates value
  2033. BOOST_CHECK_EQUAL(any_cast<const test_type3&>(x).value, 9.0);
  2034. }
  2035. #endif