move_only_function.hpp 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973
  1. #ifndef BOOST_COMPAT_MOVE_ONLY_FUNCTION_HPP_INCLUDED
  2. #define BOOST_COMPAT_MOVE_ONLY_FUNCTION_HPP_INCLUDED
  3. // Copyright 2025 Christian Mazakas.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #include <boost/compat/invoke.hpp>
  7. #include <boost/compat/type_traits.hpp>
  8. #include <boost/assert.hpp>
  9. #include <cstddef>
  10. #include <initializer_list>
  11. #include <type_traits>
  12. #include <boost/config/workaround.hpp>
  13. #if BOOST_WORKAROUND(BOOST_GCC, >= 6 * 10000)
  14. # pragma GCC diagnostic push
  15. # pragma GCC diagnostic ignored "-Wnonnull-compare"
  16. # pragma GCC diagnostic ignored "-Waddress"
  17. #endif
  18. namespace boost {
  19. namespace compat {
  20. template<class... S>
  21. class move_only_function;
  22. template< class T >
  23. struct in_place_type_t { explicit in_place_type_t() = default; };
  24. namespace detail
  25. {
  26. union pointers
  27. {
  28. void* pobj_;
  29. void ( *pfn_ )();
  30. };
  31. struct storage
  32. {
  33. // we want SBO to be large enough to store a type which can be used for delegation purposes
  34. struct delegate { void( storage::*pmfn_ )(); storage* pobj_; };
  35. union
  36. {
  37. void* pobj_;
  38. void ( *pfn_ )();
  39. alignas(delegate) unsigned char buf_[ sizeof(delegate) ];
  40. };
  41. template<class T>
  42. constexpr static bool use_sbo() noexcept
  43. {
  44. return sizeof( T ) <= sizeof( storage ) && alignof( T ) <= alignof( storage ) && std::is_nothrow_move_constructible<T>::value;
  45. }
  46. void* addr() noexcept
  47. {
  48. return buf_;
  49. }
  50. };
  51. template<class>
  52. struct is_polymorphic_function : std::false_type
  53. {
  54. };
  55. template<class R, class ...Args>
  56. struct is_polymorphic_function<move_only_function<R( Args... )>> : std::true_type
  57. {
  58. };
  59. template<class R, class ...Args>
  60. struct is_polymorphic_function<move_only_function<R( Args... ) &>> : std::true_type
  61. {
  62. };
  63. template<class R, class ...Args>
  64. struct is_polymorphic_function<move_only_function<R( Args... ) &&>> : std::true_type
  65. {
  66. };
  67. template<class R, class ...Args>
  68. struct is_polymorphic_function<move_only_function<R( Args... ) const>> : std::true_type
  69. {
  70. };
  71. template<class R, class ...Args>
  72. struct is_polymorphic_function<move_only_function<R( Args... ) const&>> : std::true_type
  73. {
  74. };
  75. template<class R, class ...Args>
  76. struct is_polymorphic_function<move_only_function<R( Args... ) const&&>> : std::true_type
  77. {
  78. };
  79. #if defined(__cpp_noexcept_function_type)
  80. template<class R, class ...Args>
  81. struct is_polymorphic_function<move_only_function<R( Args... ) noexcept>> : std::true_type
  82. {
  83. };
  84. template<class R, class ...Args>
  85. struct is_polymorphic_function<move_only_function<R( Args... ) & noexcept>> : std::true_type
  86. {
  87. };
  88. template<class R, class ...Args>
  89. struct is_polymorphic_function<move_only_function<R( Args... ) && noexcept>> : std::true_type
  90. {
  91. };
  92. template<class R, class ...Args>
  93. struct is_polymorphic_function<move_only_function<R( Args... ) const noexcept>> : std::true_type
  94. {
  95. };
  96. template<class R, class ...Args>
  97. struct is_polymorphic_function<move_only_function<R( Args... ) const& noexcept>> : std::true_type
  98. {
  99. };
  100. template<class R, class ...Args>
  101. struct is_polymorphic_function<move_only_function<R( Args... ) const&& noexcept>> : std::true_type
  102. {
  103. };
  104. #endif
  105. template<class T>
  106. using is_move_only_function = is_polymorphic_function<T>;
  107. template<class T>
  108. struct is_in_place_type_t : std::false_type
  109. {
  110. };
  111. template<class T>
  112. struct is_in_place_type_t<in_place_type_t<T>> : std::true_type
  113. {
  114. };
  115. template<class T, class ...Args>
  116. struct nothrow_init
  117. {
  118. constexpr static bool const value = ( storage::use_sbo<T>() && std::is_nothrow_constructible<T, Args...>::value ) || false;
  119. };
  120. enum class ref_quals { none, lvalue, rvalue };
  121. template<ref_quals RQ, bool Const, bool NoEx, class VT, class R, class ...Args>
  122. struct is_callable_from;
  123. template<ref_quals RQ, bool Const, class VT, class R, class ...Args>
  124. struct is_callable_from<RQ, Const, true, VT, R, Args...>
  125. {
  126. using cv_VT = conditional_t<Const, add_const_t<VT>, VT>;
  127. using cv_ref_VT = conditional_t<
  128. RQ == ref_quals::none, cv_VT,
  129. conditional_t<
  130. RQ == ref_quals::rvalue, add_rvalue_reference_t<cv_VT>, add_lvalue_reference_t<cv_VT>
  131. >
  132. >;
  133. using inv_quals_VT = conditional_t<
  134. RQ == ref_quals::none, add_lvalue_reference_t<cv_VT>,
  135. conditional_t<
  136. RQ == ref_quals::rvalue, add_rvalue_reference_t<cv_VT>, add_lvalue_reference_t<cv_VT>
  137. >
  138. >;
  139. constexpr static bool const value =
  140. is_nothrow_invocable_r<R, cv_ref_VT, Args...>::value &&
  141. is_nothrow_invocable_r<R, inv_quals_VT, Args...>::value;
  142. };
  143. template<ref_quals RQ, bool Const, class VT, class R, class ...Args>
  144. struct is_callable_from<RQ, Const, false, VT, R, Args...>
  145. {
  146. using cv_VT = conditional_t<Const, add_const_t<VT>, VT>;
  147. using cv_ref_VT = conditional_t<
  148. RQ == ref_quals::none, cv_VT,
  149. conditional_t<
  150. RQ == ref_quals::rvalue, add_rvalue_reference_t<cv_VT>, add_lvalue_reference_t<cv_VT>
  151. >
  152. >;
  153. using inv_quals_VT = conditional_t<
  154. RQ == ref_quals::none, add_lvalue_reference_t<cv_VT>,
  155. conditional_t<
  156. RQ == ref_quals::rvalue, add_rvalue_reference_t<cv_VT>, add_lvalue_reference_t<cv_VT>
  157. >
  158. >;
  159. constexpr static bool const value =
  160. is_invocable_r<R, cv_ref_VT, Args...>::value &&
  161. is_invocable_r<R, inv_quals_VT, Args...>::value;
  162. };
  163. inline std::nullptr_t get_first_arg()
  164. {
  165. return nullptr;
  166. }
  167. template<class T, class ...CArgs>
  168. T&& get_first_arg( T&& t, CArgs&& ... )
  169. {
  170. return std::forward<T>( t );
  171. }
  172. template<class ...Ts>
  173. bool is_nullary_arg( Ts&&... )
  174. {
  175. return false;
  176. }
  177. template<
  178. class F, class VT = decay_t<F>,
  179. enable_if_t<
  180. std::is_member_pointer<VT>::value ||
  181. is_move_only_function<VT>::value,
  182. int> = 0
  183. >
  184. bool is_nullary_arg( F&& f )
  185. {
  186. return f == nullptr;
  187. }
  188. template<
  189. class F, class VT = decay_t<F>,
  190. enable_if_t<
  191. std::is_function<remove_pointer_t<VT>>::value,
  192. int> = 0
  193. >
  194. bool is_nullary_arg( F f )
  195. {
  196. return f == nullptr;
  197. }
  198. template<bool NoEx, class R, class ...Args>
  199. struct mo_invoke_function_holder
  200. {
  201. static R invoke_function( storage s, Args&&... args) noexcept( NoEx )
  202. {
  203. auto f = reinterpret_cast<R(*)( Args... )>( s.pfn_ );
  204. return compat::invoke_r<R>( f, std::forward<Args>( args )... );
  205. }
  206. };
  207. template<ref_quals RQ, bool Const, bool NoEx, class F, class R, class ...Args>
  208. struct mo_invoke_object_holder
  209. {
  210. static R invoke_object( storage s, Args&&... args ) noexcept( NoEx )
  211. {
  212. using T = remove_reference_t<F>;
  213. using cv_T = conditional_t<Const, add_const_t<T>, T>;
  214. using cv_ref_T = conditional_t<
  215. RQ == ref_quals::none, add_lvalue_reference_t<cv_T>,
  216. conditional_t<
  217. RQ == ref_quals::rvalue, add_rvalue_reference_t<cv_T>, add_lvalue_reference_t<cv_T>
  218. >
  219. >;
  220. return compat::invoke_r<R>( static_cast<cv_ref_T>( *static_cast<cv_T*>( s.pobj_ ) ), std::forward<Args>( args )... );
  221. }
  222. };
  223. template<ref_quals RQ, bool Const, bool NoEx, class F, class R, class ...Args>
  224. struct mo_invoke_local_holder
  225. {
  226. static R invoke_local( storage s, Args&&... args ) noexcept( NoEx )
  227. {
  228. using T = remove_reference_t<F>;
  229. using cv_T = conditional_t<Const, add_const_t<T>, T>;
  230. using cv_ref_T = conditional_t<
  231. RQ == ref_quals::none, add_lvalue_reference_t<cv_T>,
  232. conditional_t<
  233. RQ == ref_quals::rvalue, add_rvalue_reference_t<cv_T>, add_lvalue_reference_t<cv_T>
  234. >
  235. >;
  236. return compat::invoke_r<R>( static_cast<cv_ref_T>( *static_cast<cv_T*>( s.addr() ) ), std::forward<Args>( args )... );
  237. }
  238. };
  239. enum class op_type { move, destroy };
  240. template <ref_quals RQ, bool Const, bool NoEx, class R, class ...Args>
  241. struct move_only_function_base
  242. {
  243. move_only_function_base() = default;
  244. move_only_function_base( move_only_function_base&& rhs ) noexcept
  245. {
  246. manager_ = rhs.manager_;
  247. manager_( op_type::move, s_, &rhs.s_ );
  248. invoke_ = rhs.invoke_;
  249. rhs.invoke_ = nullptr;
  250. rhs.manager_ = &manage_empty;
  251. }
  252. ~move_only_function_base()
  253. {
  254. destroy();
  255. }
  256. void swap( move_only_function_base& rhs ) noexcept
  257. {
  258. // to properly swap with storages, we need to treat the destination storage
  259. // the same as the source storage, which means that we need to use the
  260. // source manager_'s move operation
  261. storage s;
  262. rhs.manager_( op_type::move, s, &rhs.s_ );
  263. manager_( op_type::move, rhs.s_, &s_ );
  264. rhs.manager_( op_type::move, s_, &s );
  265. std::swap( manager_, rhs.manager_ );
  266. std::swap( invoke_, rhs.invoke_ );
  267. }
  268. move_only_function_base& operator=( move_only_function_base&& rhs )
  269. {
  270. destroy();
  271. manager_ = rhs.manager_;
  272. manager_( op_type::move, s_, &rhs.s_ );
  273. invoke_ = rhs.invoke_;
  274. rhs.invoke_ = nullptr;
  275. rhs.manager_ = &manage_empty;
  276. return *this;
  277. }
  278. move_only_function_base& operator=( std::nullptr_t ) noexcept
  279. {
  280. destroy();
  281. invoke_ = nullptr;
  282. manager_ = &manage_empty;
  283. return *this;
  284. }
  285. static void manage_empty( op_type, detail::storage&, detail::storage* )
  286. {
  287. }
  288. static void manage_function( op_type op, detail::storage& s, detail::storage* src )
  289. {
  290. switch( op )
  291. {
  292. case op_type::move:
  293. s.pfn_ = src->pfn_;
  294. src->pfn_ = nullptr;
  295. break;
  296. default:
  297. break;
  298. }
  299. }
  300. template<class VT>
  301. static void manage_object( op_type op, detail::storage& s, detail::storage* src )
  302. {
  303. switch( op )
  304. {
  305. case op_type::destroy:
  306. delete static_cast<VT*>( s.pobj_ );
  307. break;
  308. case op_type::move:
  309. s.pobj_ = src->pobj_;
  310. src->pobj_ = nullptr;
  311. break;
  312. default:
  313. break;
  314. }
  315. }
  316. template<class VT>
  317. static void manage_local( op_type op, detail::storage& s, detail::storage* src )
  318. {
  319. switch( op )
  320. {
  321. case op_type::destroy:
  322. static_cast<VT*>( s.addr() )->~VT();
  323. break;
  324. case op_type::move:
  325. {
  326. VT* p = static_cast<VT*>( src->addr() );
  327. new(s.addr()) VT( std::move( *p ) );
  328. // destruct the element here because move construction will leave the container empty
  329. // outside of this function
  330. p->~VT();
  331. break;
  332. }
  333. default:
  334. break;
  335. }
  336. }
  337. template <ref_quals RQ2, bool Const2, bool NoEx2, class R2, class ...Args2>
  338. void
  339. move_from_compatible_base( move_only_function_base<RQ2, Const2, NoEx2, R2, Args2...>& base )
  340. {
  341. using polymorphic_base = move_only_function_base<RQ2, Const2, NoEx2, R2, Args2...>;
  342. manager_ = base.manager_;
  343. manager_( op_type::move, s_, &base.s_ );
  344. invoke_ = base.invoke_;
  345. base.invoke_ = nullptr;
  346. base.manager_ = &polymorphic_base::manage_empty;
  347. }
  348. template<class F>
  349. void base_init( std::true_type, F&& f )
  350. {
  351. move_from_compatible_base( f );
  352. }
  353. template<class ...F>
  354. void base_init( std::false_type, F&&... )
  355. {
  356. }
  357. template<class VT, class ...CArgs>
  358. void init( std::false_type /* is_function */, CArgs&& ...args )
  359. {
  360. if( is_polymorphic_function<VT>::value )
  361. {
  362. base_init( is_polymorphic_function<VT>{}, std::forward<CArgs>( args )... );
  363. return;
  364. }
  365. if( !storage::use_sbo<VT>() )
  366. {
  367. s_.pobj_ = new VT( std::forward<CArgs>( args )... );
  368. invoke_ = &mo_invoke_object_holder<RQ, Const, NoEx, VT, R, Args...>::invoke_object;
  369. manager_ = &manage_object<VT>;
  370. }
  371. else
  372. {
  373. new( s_.addr() ) VT( std::forward<CArgs>( args )... );
  374. invoke_ = &mo_invoke_local_holder<RQ, Const, NoEx, VT, R, Args...>::invoke_local;
  375. manager_ = &manage_local<VT>;
  376. }
  377. }
  378. template<class VT, class ...CArgs>
  379. void init( std::true_type /* is_function */, CArgs ...args )
  380. {
  381. R (*pfn)( Args... ) = get_first_arg( args... );
  382. s_.pfn_ = reinterpret_cast<void(*)()>( pfn );
  383. invoke_ = &detail::mo_invoke_function_holder<NoEx, R, Args...>::invoke_function;
  384. manager_ = &manage_function;
  385. }
  386. template <class VT, class ...CArgs>
  387. void init( type_identity<VT>, CArgs&& ...args )
  388. {
  389. init<VT>( std::is_function<remove_pointer_t<VT>>(), std::forward<CArgs>( args )... );
  390. }
  391. void destroy()
  392. {
  393. manager_( op_type::destroy, s_, nullptr );
  394. }
  395. explicit operator bool() const noexcept
  396. {
  397. return invoke_ != nullptr;
  398. }
  399. detail::storage s_;
  400. #if defined(__cpp_noexcept_function_type)
  401. R ( *invoke_ )( detail::storage, Args&&... ) noexcept( NoEx ) = nullptr;
  402. #else
  403. R ( *invoke_ )( detail::storage, Args&&... ) = nullptr;
  404. #endif
  405. void ( *manager_ )( op_type, detail::storage&, detail::storage* ) = &manage_empty;
  406. };
  407. } // namespace detail
  408. template<class R, class ...Args>
  409. class move_only_function<R( Args... )> : detail::move_only_function_base<detail::ref_quals::none, false, false, R, Args...>
  410. {
  411. private:
  412. template<detail::ref_quals, bool, bool, class, class ...>
  413. friend struct detail::move_only_function_base;
  414. using base = detail::move_only_function_base<detail::ref_quals::none, false, false, R, Args...>;
  415. public:
  416. move_only_function() noexcept
  417. {
  418. }
  419. move_only_function( std::nullptr_t ) noexcept
  420. : move_only_function()
  421. {
  422. }
  423. template<
  424. class F,
  425. class VT = decay_t<F>,
  426. enable_if_t<
  427. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  428. !detail::is_in_place_type_t<VT>::value &&
  429. detail::is_callable_from<detail::ref_quals::none, false, false, VT, R, Args...>::value,
  430. int> = 0
  431. >
  432. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  433. {
  434. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  435. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  436. }
  437. template<
  438. class T, class ...CArgs,
  439. enable_if_t<
  440. std::is_constructible<T, CArgs...>::value &&
  441. detail::is_callable_from<detail::ref_quals::none, false, false, T, R, Args...>::value,
  442. int> = 0
  443. >
  444. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  445. {
  446. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  447. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  448. }
  449. template<
  450. class T, class U, class ...CArgs,
  451. enable_if_t<
  452. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  453. detail::is_callable_from<detail::ref_quals::none, false, false, T, R, Args...>::value,
  454. int> = 0
  455. >
  456. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  457. {
  458. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  459. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  460. }
  461. move_only_function( move_only_function const& ) = delete;
  462. move_only_function( move_only_function&& ) = default;
  463. ~move_only_function() = default;
  464. move_only_function& operator=( move_only_function&& rhs )
  465. {
  466. if( this != &rhs )
  467. {
  468. this->base::operator=( static_cast<base&&>( rhs ) );
  469. }
  470. return *this;
  471. }
  472. move_only_function& operator=( std::nullptr_t ) noexcept
  473. {
  474. this->base::operator=( nullptr );
  475. return *this;
  476. }
  477. template<class F> move_only_function& operator=( F&& f )
  478. {
  479. move_only_function( std::forward<F>( f ) ).swap( *this );
  480. return *this;
  481. }
  482. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  483. {
  484. return fn.invoke_ == nullptr;
  485. }
  486. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  487. {
  488. return !( fn == nullptr );
  489. }
  490. void swap( move_only_function& rhs ) noexcept
  491. {
  492. if( this != &rhs )
  493. {
  494. this->base::swap( rhs );
  495. }
  496. }
  497. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  498. {
  499. lhs.swap( rhs );
  500. }
  501. explicit operator bool() const noexcept
  502. {
  503. return static_cast<bool>( *static_cast<base const*>( this ) );
  504. }
  505. R operator()( Args... args )
  506. {
  507. return this->invoke_( this->s_, std::forward<Args>( args )... );
  508. }
  509. };
  510. template<class R, class ...Args>
  511. class move_only_function<R( Args... ) &> : detail::move_only_function_base<detail::ref_quals::lvalue, false, false, R, Args...>
  512. {
  513. private:
  514. template<detail::ref_quals, bool, bool, class, class ...>
  515. friend struct detail::move_only_function_base;
  516. using base = detail::move_only_function_base<detail::ref_quals::lvalue, false, false, R, Args...>;
  517. public:
  518. move_only_function() noexcept
  519. {
  520. }
  521. move_only_function( std::nullptr_t ) noexcept
  522. : move_only_function()
  523. {
  524. }
  525. template<
  526. class F,
  527. class VT = decay_t<F>,
  528. enable_if_t<
  529. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  530. !detail::is_in_place_type_t<VT>::value &&
  531. detail::is_callable_from<detail::ref_quals::lvalue, false, false, VT, R, Args...>::value,
  532. int> = 0
  533. >
  534. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  535. {
  536. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  537. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  538. }
  539. template<
  540. class T, class ...CArgs,
  541. enable_if_t<
  542. std::is_constructible<T, CArgs...>::value &&
  543. detail::is_callable_from<detail::ref_quals::lvalue, false, false, T, R, Args...>::value,
  544. int> = 0
  545. >
  546. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  547. {
  548. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  549. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  550. }
  551. template<
  552. class T, class U, class ...CArgs,
  553. enable_if_t<
  554. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  555. detail::is_callable_from<detail::ref_quals::lvalue, false, false, T, R, Args...>::value,
  556. int> = 0
  557. >
  558. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  559. {
  560. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  561. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  562. }
  563. move_only_function( move_only_function const& ) = delete;
  564. move_only_function( move_only_function&& ) = default;
  565. ~move_only_function() = default;
  566. move_only_function& operator=( move_only_function&& rhs )
  567. {
  568. if( this != &rhs )
  569. {
  570. this->base::operator=( static_cast<base&&>( rhs ) );
  571. }
  572. return *this;
  573. }
  574. move_only_function& operator=( std::nullptr_t ) noexcept
  575. {
  576. this->base::operator=( nullptr );
  577. return *this;
  578. }
  579. template<class F> move_only_function& operator=( F&& f )
  580. {
  581. move_only_function( std::forward<F>( f ) ).swap( *this );
  582. return *this;
  583. }
  584. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  585. {
  586. return fn.invoke_ == nullptr;
  587. }
  588. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  589. {
  590. return !( fn == nullptr );
  591. }
  592. void swap( move_only_function& rhs ) noexcept
  593. {
  594. if( this != &rhs )
  595. {
  596. this->base::swap( rhs );
  597. }
  598. }
  599. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  600. {
  601. lhs.swap( rhs );
  602. }
  603. explicit operator bool() const noexcept
  604. {
  605. return static_cast<bool>( *static_cast<base const*>( this ) );
  606. }
  607. R operator()( Args... args ) &
  608. {
  609. return this->invoke_( this->s_, std::forward<Args>( args )... );
  610. }
  611. };
  612. template<class R, class ...Args>
  613. class move_only_function<R( Args... ) &&> : detail::move_only_function_base<detail::ref_quals::rvalue, false, false, R, Args...>
  614. {
  615. private:
  616. template<detail::ref_quals, bool, bool, class, class ...>
  617. friend struct detail::move_only_function_base;
  618. using base = detail::move_only_function_base<detail::ref_quals::rvalue, false, false, R, Args...>;
  619. public:
  620. move_only_function() noexcept
  621. {
  622. }
  623. move_only_function( std::nullptr_t ) noexcept
  624. : move_only_function()
  625. {
  626. }
  627. template<
  628. class F,
  629. class VT = decay_t<F>,
  630. enable_if_t<
  631. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  632. !detail::is_in_place_type_t<VT>::value &&
  633. detail::is_callable_from<detail::ref_quals::rvalue, false, false, VT, R, Args...>::value,
  634. int> = 0
  635. >
  636. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  637. {
  638. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  639. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  640. }
  641. template<
  642. class T, class ...CArgs,
  643. enable_if_t<
  644. std::is_constructible<T, CArgs...>::value &&
  645. detail::is_callable_from<detail::ref_quals::rvalue, false, false, T, R, Args...>::value,
  646. int> = 0
  647. >
  648. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  649. {
  650. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  651. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  652. }
  653. template<
  654. class T, class U, class ...CArgs,
  655. enable_if_t<
  656. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  657. detail::is_callable_from<detail::ref_quals::rvalue, false, false, T, R, Args...>::value,
  658. int> = 0
  659. >
  660. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  661. {
  662. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  663. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  664. }
  665. move_only_function( move_only_function const& ) = delete;
  666. move_only_function( move_only_function&& ) = default;
  667. ~move_only_function() = default;
  668. move_only_function& operator=( move_only_function&& rhs )
  669. {
  670. if( this != &rhs )
  671. {
  672. this->base::operator=( static_cast<base&&>( rhs ) );
  673. }
  674. return *this;
  675. }
  676. move_only_function& operator=( std::nullptr_t ) noexcept
  677. {
  678. this->base::operator=( nullptr );
  679. return *this;
  680. }
  681. template<class F> move_only_function& operator=( F&& f )
  682. {
  683. move_only_function( std::forward<F>( f ) ).swap( *this );
  684. return *this;
  685. }
  686. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  687. {
  688. return fn.invoke_ == nullptr;
  689. }
  690. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  691. {
  692. return !( fn == nullptr );
  693. }
  694. void swap( move_only_function& rhs ) noexcept
  695. {
  696. if( this != &rhs )
  697. {
  698. this->base::swap( rhs );
  699. }
  700. }
  701. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  702. {
  703. lhs.swap( rhs );
  704. }
  705. explicit operator bool() const noexcept
  706. {
  707. return static_cast<bool>( *static_cast<base const*>( this ) );
  708. }
  709. R operator()( Args... args ) &&
  710. {
  711. return this->invoke_( this->s_, std::forward<Args>( args )... );
  712. }
  713. };
  714. template<class R, class ...Args>
  715. class move_only_function<R( Args... ) const> : detail::move_only_function_base<detail::ref_quals::none, true, false, R, Args...>
  716. {
  717. private:
  718. template<detail::ref_quals, bool, bool, class, class ...>
  719. friend struct detail::move_only_function_base;
  720. using base = detail::move_only_function_base<detail::ref_quals::none, true, false, R, Args...>;
  721. public:
  722. move_only_function() noexcept
  723. {
  724. }
  725. move_only_function( std::nullptr_t ) noexcept
  726. : move_only_function()
  727. {
  728. }
  729. template<
  730. class F,
  731. class VT = decay_t<F>,
  732. enable_if_t<
  733. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  734. !detail::is_in_place_type_t<VT>::value &&
  735. detail::is_callable_from<detail::ref_quals::none, true, false, VT, R, Args...>::value,
  736. int> = 0
  737. >
  738. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  739. {
  740. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  741. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  742. }
  743. template<
  744. class T, class ...CArgs,
  745. enable_if_t<
  746. std::is_constructible<T, CArgs...>::value &&
  747. detail::is_callable_from<detail::ref_quals::none, true, false, T, R, Args...>::value,
  748. int> = 0
  749. >
  750. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  751. {
  752. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  753. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  754. }
  755. template<
  756. class T, class U, class ...CArgs,
  757. enable_if_t<
  758. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  759. detail::is_callable_from<detail::ref_quals::none, true, false, T, R, Args...>::value,
  760. int> = 0
  761. >
  762. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  763. {
  764. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  765. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  766. }
  767. move_only_function( move_only_function const& ) = delete;
  768. move_only_function( move_only_function&& ) = default;
  769. ~move_only_function() = default;
  770. move_only_function& operator=( move_only_function&& rhs )
  771. {
  772. if( this != &rhs )
  773. {
  774. this->base::operator=( static_cast<base&&>( rhs ) );
  775. }
  776. return *this;
  777. }
  778. move_only_function& operator=( std::nullptr_t ) noexcept
  779. {
  780. this->base::operator=( nullptr );
  781. return *this;
  782. }
  783. template<class F> move_only_function& operator=( F&& f )
  784. {
  785. move_only_function( std::forward<F>( f ) ).swap( *this );
  786. return *this;
  787. }
  788. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  789. {
  790. return fn.invoke_ == nullptr;
  791. }
  792. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  793. {
  794. return !( fn == nullptr );
  795. }
  796. void swap( move_only_function& rhs ) noexcept
  797. {
  798. if( this != &rhs )
  799. {
  800. this->base::swap( rhs );
  801. }
  802. }
  803. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  804. {
  805. lhs.swap( rhs );
  806. }
  807. explicit operator bool() const noexcept
  808. {
  809. return static_cast<bool>( *static_cast<base const*>( this ) );
  810. }
  811. R operator()( Args... args ) const
  812. {
  813. return this->invoke_( this->s_, std::forward<Args>( args )... );
  814. }
  815. };
  816. template<class R, class ...Args>
  817. class move_only_function<R( Args... ) const&> : detail::move_only_function_base<detail::ref_quals::lvalue, true, false, R, Args...>
  818. {
  819. private:
  820. template<detail::ref_quals, bool, bool, class, class ...>
  821. friend struct detail::move_only_function_base;
  822. using base = detail::move_only_function_base<detail::ref_quals::lvalue, true, false, R, Args...>;
  823. public:
  824. move_only_function() noexcept
  825. {
  826. }
  827. move_only_function( std::nullptr_t ) noexcept
  828. : move_only_function()
  829. {
  830. }
  831. template<
  832. class F,
  833. class VT = decay_t<F>,
  834. enable_if_t<
  835. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  836. !detail::is_in_place_type_t<VT>::value &&
  837. detail::is_callable_from<detail::ref_quals::lvalue, true, false, VT, R, Args...>::value,
  838. int> = 0
  839. >
  840. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  841. {
  842. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  843. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  844. }
  845. template<
  846. class T, class ...CArgs,
  847. enable_if_t<
  848. std::is_constructible<T, CArgs...>::value &&
  849. detail::is_callable_from<detail::ref_quals::lvalue, true, false, T, R, Args...>::value,
  850. int> = 0
  851. >
  852. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  853. {
  854. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  855. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  856. }
  857. template<
  858. class T, class U, class ...CArgs,
  859. enable_if_t<
  860. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  861. detail::is_callable_from<detail::ref_quals::lvalue, true, false, T, R, Args...>::value,
  862. int> = 0
  863. >
  864. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  865. {
  866. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  867. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  868. }
  869. move_only_function( move_only_function const& ) = delete;
  870. move_only_function( move_only_function&& ) = default;
  871. ~move_only_function() = default;
  872. move_only_function& operator=( move_only_function&& rhs )
  873. {
  874. if( this != &rhs )
  875. {
  876. this->base::operator=( static_cast<base&&>( rhs ) );
  877. }
  878. return *this;
  879. }
  880. move_only_function& operator=( std::nullptr_t ) noexcept
  881. {
  882. this->base::operator=( nullptr );
  883. return *this;
  884. }
  885. template<class F> move_only_function& operator=( F&& f )
  886. {
  887. move_only_function( std::forward<F>( f ) ).swap( *this );
  888. return *this;
  889. }
  890. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  891. {
  892. return fn.invoke_ == nullptr;
  893. }
  894. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  895. {
  896. return !( fn == nullptr );
  897. }
  898. void swap( move_only_function& rhs ) noexcept
  899. {
  900. if( this != &rhs )
  901. {
  902. this->base::swap( rhs );
  903. }
  904. }
  905. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  906. {
  907. lhs.swap( rhs );
  908. }
  909. explicit operator bool() const noexcept
  910. {
  911. return static_cast<bool>( *static_cast<base const*>( this ) );
  912. }
  913. R operator()( Args... args ) const &
  914. {
  915. return this->invoke_( this->s_, std::forward<Args>( args )... );
  916. }
  917. };
  918. template<class R, class ...Args>
  919. class move_only_function<R( Args... ) const&&> : detail::move_only_function_base<detail::ref_quals::rvalue, true, false, R, Args...>
  920. {
  921. private:
  922. template<detail::ref_quals, bool, bool, class, class ...>
  923. friend struct detail::move_only_function_base;
  924. using base = detail::move_only_function_base<detail::ref_quals::rvalue, true, false, R, Args...>;
  925. public:
  926. move_only_function() noexcept
  927. {
  928. }
  929. move_only_function( std::nullptr_t ) noexcept
  930. : move_only_function()
  931. {
  932. }
  933. template<
  934. class F,
  935. class VT = decay_t<F>,
  936. enable_if_t<
  937. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  938. !detail::is_in_place_type_t<VT>::value &&
  939. detail::is_callable_from<detail::ref_quals::rvalue, true, false, VT, R, Args...>::value,
  940. int> = 0
  941. >
  942. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  943. {
  944. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  945. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  946. }
  947. template<
  948. class T, class ...CArgs,
  949. enable_if_t<
  950. std::is_constructible<T, CArgs...>::value &&
  951. detail::is_callable_from<detail::ref_quals::rvalue, true, false, T, R, Args...>::value,
  952. int> = 0
  953. >
  954. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  955. {
  956. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  957. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  958. }
  959. template<
  960. class T, class U, class ...CArgs,
  961. enable_if_t<
  962. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  963. detail::is_callable_from<detail::ref_quals::rvalue, true, false, T, R, Args...>::value,
  964. int> = 0
  965. >
  966. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  967. {
  968. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  969. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  970. }
  971. move_only_function( move_only_function const& ) = delete;
  972. move_only_function( move_only_function&& ) = default;
  973. ~move_only_function() = default;
  974. move_only_function& operator=( move_only_function&& rhs )
  975. {
  976. if( this != &rhs )
  977. {
  978. this->base::operator=( static_cast<base&&>( rhs ) );
  979. }
  980. return *this;
  981. }
  982. move_only_function& operator=( std::nullptr_t ) noexcept
  983. {
  984. this->base::operator=( nullptr );
  985. return *this;
  986. }
  987. template<class F> move_only_function& operator=( F&& f )
  988. {
  989. move_only_function( std::forward<F>( f ) ).swap( *this );
  990. return *this;
  991. }
  992. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  993. {
  994. return fn.invoke_ == nullptr;
  995. }
  996. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  997. {
  998. return !( fn == nullptr );
  999. }
  1000. void swap( move_only_function& rhs ) noexcept
  1001. {
  1002. if( this != &rhs )
  1003. {
  1004. this->base::swap( rhs );
  1005. }
  1006. }
  1007. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  1008. {
  1009. lhs.swap( rhs );
  1010. }
  1011. explicit operator bool() const noexcept
  1012. {
  1013. return static_cast<bool>( *static_cast<base const*>( this ) );
  1014. }
  1015. R operator()( Args... args ) const &&
  1016. {
  1017. return this->invoke_( this->s_, std::forward<Args>( args )... );
  1018. }
  1019. };
  1020. #if defined(__cpp_noexcept_function_type)
  1021. template<class R, class ...Args>
  1022. class move_only_function<R( Args... ) noexcept> : detail::move_only_function_base<detail::ref_quals::none, false, true, R, Args...>
  1023. {
  1024. private:
  1025. template<detail::ref_quals, bool, bool, class, class ...>
  1026. friend struct detail::move_only_function_base;
  1027. using base = detail::move_only_function_base<detail::ref_quals::none, false, true, R, Args...>;
  1028. public:
  1029. move_only_function() noexcept
  1030. {
  1031. }
  1032. move_only_function( std::nullptr_t ) noexcept
  1033. : move_only_function()
  1034. {
  1035. }
  1036. template<
  1037. class F,
  1038. class VT = decay_t<F>,
  1039. enable_if_t<
  1040. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  1041. !detail::is_in_place_type_t<VT>::value &&
  1042. detail::is_callable_from<detail::ref_quals::none, false, true, VT, R, Args...>::value,
  1043. int> = 0
  1044. >
  1045. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  1046. {
  1047. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  1048. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  1049. }
  1050. template<
  1051. class T, class ...CArgs,
  1052. enable_if_t<
  1053. std::is_constructible<T, CArgs...>::value &&
  1054. detail::is_callable_from<detail::ref_quals::none, false, true, T, R, Args...>::value,
  1055. int> = 0
  1056. >
  1057. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  1058. {
  1059. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1060. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  1061. }
  1062. template<
  1063. class T, class U, class ...CArgs,
  1064. enable_if_t<
  1065. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  1066. detail::is_callable_from<detail::ref_quals::none, false, true, T, R, Args...>::value,
  1067. int> = 0
  1068. >
  1069. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  1070. {
  1071. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1072. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  1073. }
  1074. move_only_function( move_only_function const& ) = delete;
  1075. move_only_function( move_only_function&& ) = default;
  1076. ~move_only_function() = default;
  1077. move_only_function& operator=( move_only_function&& rhs )
  1078. {
  1079. if( this != &rhs )
  1080. {
  1081. this->base::operator=( static_cast<base&&>( rhs ) );
  1082. }
  1083. return *this;
  1084. }
  1085. move_only_function& operator=( std::nullptr_t ) noexcept
  1086. {
  1087. this->base::operator=( nullptr );
  1088. return *this;
  1089. }
  1090. template<class F> move_only_function& operator=( F&& f )
  1091. {
  1092. move_only_function( std::forward<F>( f ) ).swap( *this );
  1093. return *this;
  1094. }
  1095. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  1096. {
  1097. return fn.invoke_ == nullptr;
  1098. }
  1099. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  1100. {
  1101. return !( fn == nullptr );
  1102. }
  1103. void swap( move_only_function& rhs ) noexcept
  1104. {
  1105. if( this != &rhs )
  1106. {
  1107. this->base::swap( rhs );
  1108. }
  1109. }
  1110. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  1111. {
  1112. lhs.swap( rhs );
  1113. }
  1114. explicit operator bool() const noexcept
  1115. {
  1116. return static_cast<bool>( *static_cast<base const*>( this ) );
  1117. }
  1118. R operator()( Args... args ) noexcept
  1119. {
  1120. return this->invoke_( this->s_, std::forward<Args>( args )... );
  1121. }
  1122. };
  1123. template<class R, class ...Args>
  1124. class move_only_function<R( Args... ) & noexcept> : detail::move_only_function_base<detail::ref_quals::lvalue, false, true, R, Args...>
  1125. {
  1126. private:
  1127. template<detail::ref_quals, bool, bool, class, class ...>
  1128. friend struct detail::move_only_function_base;
  1129. using base = detail::move_only_function_base<detail::ref_quals::lvalue, false, true, R, Args...>;
  1130. public:
  1131. move_only_function() noexcept
  1132. {
  1133. }
  1134. move_only_function( std::nullptr_t ) noexcept
  1135. : move_only_function()
  1136. {
  1137. }
  1138. template<
  1139. class F,
  1140. class VT = decay_t<F>,
  1141. enable_if_t<
  1142. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  1143. !detail::is_in_place_type_t<VT>::value &&
  1144. detail::is_callable_from<detail::ref_quals::lvalue, false, true, VT, R, Args...>::value,
  1145. int> = 0
  1146. >
  1147. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  1148. {
  1149. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  1150. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  1151. }
  1152. template<
  1153. class T, class ...CArgs,
  1154. enable_if_t<
  1155. std::is_constructible<T, CArgs...>::value &&
  1156. detail::is_callable_from<detail::ref_quals::lvalue, false, true, T, R, Args...>::value,
  1157. int> = 0
  1158. >
  1159. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  1160. {
  1161. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1162. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  1163. }
  1164. template<
  1165. class T, class U, class ...CArgs,
  1166. enable_if_t<
  1167. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  1168. detail::is_callable_from<detail::ref_quals::lvalue, false, true, T, R, Args...>::value,
  1169. int> = 0
  1170. >
  1171. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  1172. {
  1173. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1174. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  1175. }
  1176. move_only_function( move_only_function const& ) = delete;
  1177. move_only_function( move_only_function&& ) = default;
  1178. ~move_only_function() = default;
  1179. move_only_function& operator=( move_only_function&& rhs )
  1180. {
  1181. if( this != &rhs )
  1182. {
  1183. this->base::operator=( static_cast<base&&>( rhs ) );
  1184. }
  1185. return *this;
  1186. }
  1187. move_only_function& operator=( std::nullptr_t ) noexcept
  1188. {
  1189. this->base::operator=( nullptr );
  1190. return *this;
  1191. }
  1192. template<class F> move_only_function& operator=( F&& f )
  1193. {
  1194. move_only_function( std::forward<F>( f ) ).swap( *this );
  1195. return *this;
  1196. }
  1197. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  1198. {
  1199. return fn.invoke_ == nullptr;
  1200. }
  1201. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  1202. {
  1203. return !( fn == nullptr );
  1204. }
  1205. void swap( move_only_function& rhs ) noexcept
  1206. {
  1207. if( this != &rhs )
  1208. {
  1209. this->base::swap( rhs );
  1210. }
  1211. }
  1212. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  1213. {
  1214. lhs.swap( rhs );
  1215. }
  1216. explicit operator bool() const noexcept
  1217. {
  1218. return static_cast<bool>( *static_cast<base const*>( this ) );
  1219. }
  1220. R operator()( Args... args ) & noexcept
  1221. {
  1222. return this->invoke_( this->s_, std::forward<Args>( args )... );
  1223. }
  1224. };
  1225. template<class R, class ...Args>
  1226. class move_only_function<R( Args... ) && noexcept> : detail::move_only_function_base<detail::ref_quals::rvalue, false, true, R, Args...>
  1227. {
  1228. private:
  1229. template<detail::ref_quals, bool, bool, class, class ...>
  1230. friend struct detail::move_only_function_base;
  1231. using base = detail::move_only_function_base<detail::ref_quals::rvalue, false, true, R, Args...>;
  1232. public:
  1233. move_only_function() noexcept
  1234. {
  1235. }
  1236. move_only_function( std::nullptr_t ) noexcept
  1237. : move_only_function()
  1238. {
  1239. }
  1240. template<
  1241. class F,
  1242. class VT = decay_t<F>,
  1243. enable_if_t<
  1244. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  1245. !detail::is_in_place_type_t<VT>::value &&
  1246. detail::is_callable_from<detail::ref_quals::rvalue, false, true, VT, R, Args...>::value,
  1247. int> = 0
  1248. >
  1249. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  1250. {
  1251. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  1252. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  1253. }
  1254. template<
  1255. class T, class ...CArgs,
  1256. enable_if_t<
  1257. std::is_constructible<T, CArgs...>::value &&
  1258. detail::is_callable_from<detail::ref_quals::rvalue, false, true, T, R, Args...>::value,
  1259. int> = 0
  1260. >
  1261. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  1262. {
  1263. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1264. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  1265. }
  1266. template<
  1267. class T, class U, class ...CArgs,
  1268. enable_if_t<
  1269. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  1270. detail::is_callable_from<detail::ref_quals::rvalue, false, true, T, R, Args...>::value,
  1271. int> = 0
  1272. >
  1273. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  1274. {
  1275. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1276. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  1277. }
  1278. move_only_function( move_only_function const& ) = delete;
  1279. move_only_function( move_only_function&& ) = default;
  1280. ~move_only_function() = default;
  1281. move_only_function& operator=( move_only_function&& rhs )
  1282. {
  1283. if( this != &rhs )
  1284. {
  1285. this->base::operator=( static_cast<base&&>( rhs ) );
  1286. }
  1287. return *this;
  1288. }
  1289. move_only_function& operator=( std::nullptr_t ) noexcept
  1290. {
  1291. this->base::operator=( nullptr );
  1292. return *this;
  1293. }
  1294. template<class F> move_only_function& operator=( F&& f )
  1295. {
  1296. move_only_function( std::forward<F>( f ) ).swap( *this );
  1297. return *this;
  1298. }
  1299. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  1300. {
  1301. return fn.invoke_ == nullptr;
  1302. }
  1303. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  1304. {
  1305. return !( fn == nullptr );
  1306. }
  1307. void swap( move_only_function& rhs ) noexcept
  1308. {
  1309. if( this != &rhs )
  1310. {
  1311. this->base::swap( rhs );
  1312. }
  1313. }
  1314. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  1315. {
  1316. lhs.swap( rhs );
  1317. }
  1318. explicit operator bool() const noexcept
  1319. {
  1320. return static_cast<bool>( *static_cast<base const*>( this ) );
  1321. }
  1322. R operator()( Args... args ) && noexcept
  1323. {
  1324. return this->invoke_( this->s_, std::forward<Args>( args )... );
  1325. }
  1326. };
  1327. template<class R, class ...Args>
  1328. class move_only_function<R( Args... ) const noexcept> : detail::move_only_function_base<detail::ref_quals::none, true, true, R, Args...>
  1329. {
  1330. private:
  1331. template<detail::ref_quals, bool, bool, class, class ...>
  1332. friend struct detail::move_only_function_base;
  1333. using base = detail::move_only_function_base<detail::ref_quals::none, true, true, R, Args...>;
  1334. public:
  1335. move_only_function() noexcept
  1336. {
  1337. }
  1338. move_only_function( std::nullptr_t ) noexcept
  1339. : move_only_function()
  1340. {
  1341. }
  1342. template<
  1343. class F,
  1344. class VT = decay_t<F>,
  1345. enable_if_t<
  1346. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  1347. !detail::is_in_place_type_t<VT>::value &&
  1348. detail::is_callable_from<detail::ref_quals::none, true, true, VT, R, Args...>::value,
  1349. int> = 0
  1350. >
  1351. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  1352. {
  1353. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  1354. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  1355. }
  1356. template<
  1357. class T, class ...CArgs,
  1358. enable_if_t<
  1359. std::is_constructible<T, CArgs...>::value &&
  1360. detail::is_callable_from<detail::ref_quals::none, true, true, T, R, Args...>::value,
  1361. int> = 0
  1362. >
  1363. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  1364. {
  1365. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1366. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  1367. }
  1368. template<
  1369. class T, class U, class ...CArgs,
  1370. enable_if_t<
  1371. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  1372. detail::is_callable_from<detail::ref_quals::none, true, true, T, R, Args...>::value,
  1373. int> = 0
  1374. >
  1375. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  1376. {
  1377. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1378. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  1379. }
  1380. move_only_function( move_only_function const& ) = delete;
  1381. move_only_function( move_only_function&& ) = default;
  1382. ~move_only_function() = default;
  1383. move_only_function& operator=( move_only_function&& rhs )
  1384. {
  1385. if( this != &rhs )
  1386. {
  1387. this->base::operator=( static_cast<base&&>( rhs ) );
  1388. }
  1389. return *this;
  1390. }
  1391. move_only_function& operator=( std::nullptr_t ) noexcept
  1392. {
  1393. this->base::operator=( nullptr );
  1394. return *this;
  1395. }
  1396. template<class F> move_only_function& operator=( F&& f )
  1397. {
  1398. move_only_function( std::forward<F>( f ) ).swap( *this );
  1399. return *this;
  1400. }
  1401. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  1402. {
  1403. return fn.invoke_ == nullptr;
  1404. }
  1405. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  1406. {
  1407. return !( fn == nullptr );
  1408. }
  1409. void swap( move_only_function& rhs ) noexcept
  1410. {
  1411. if( this != &rhs )
  1412. {
  1413. this->base::swap( rhs );
  1414. }
  1415. }
  1416. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  1417. {
  1418. lhs.swap( rhs );
  1419. }
  1420. explicit operator bool() const noexcept
  1421. {
  1422. return static_cast<bool>( *static_cast<base const*>( this ) );
  1423. }
  1424. R operator()( Args... args ) const noexcept
  1425. {
  1426. return this->invoke_( this->s_, std::forward<Args>( args )... );
  1427. }
  1428. };
  1429. template<class R, class ...Args>
  1430. class move_only_function<R( Args... ) const& noexcept> : detail::move_only_function_base<detail::ref_quals::lvalue, true, true, R, Args...>
  1431. {
  1432. private:
  1433. template<detail::ref_quals, bool, bool, class, class ...>
  1434. friend struct detail::move_only_function_base;
  1435. using base = detail::move_only_function_base<detail::ref_quals::lvalue, true, true, R, Args...>;
  1436. public:
  1437. move_only_function() noexcept
  1438. {
  1439. }
  1440. move_only_function( std::nullptr_t ) noexcept
  1441. : move_only_function()
  1442. {
  1443. }
  1444. template<
  1445. class F,
  1446. class VT = decay_t<F>,
  1447. enable_if_t<
  1448. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  1449. !detail::is_in_place_type_t<VT>::value &&
  1450. detail::is_callable_from<detail::ref_quals::lvalue, true, true, VT, R, Args...>::value,
  1451. int> = 0
  1452. >
  1453. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  1454. {
  1455. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  1456. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  1457. }
  1458. template<
  1459. class T, class ...CArgs,
  1460. enable_if_t<
  1461. std::is_constructible<T, CArgs...>::value &&
  1462. detail::is_callable_from<detail::ref_quals::lvalue, true, true, T, R, Args...>::value,
  1463. int> = 0
  1464. >
  1465. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  1466. {
  1467. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1468. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  1469. }
  1470. template<
  1471. class T, class U, class ...CArgs,
  1472. enable_if_t<
  1473. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  1474. detail::is_callable_from<detail::ref_quals::lvalue, true, true, T, R, Args...>::value,
  1475. int> = 0
  1476. >
  1477. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  1478. {
  1479. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1480. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  1481. }
  1482. move_only_function( move_only_function const& ) = delete;
  1483. move_only_function( move_only_function&& ) = default;
  1484. ~move_only_function() = default;
  1485. move_only_function& operator=( move_only_function&& rhs )
  1486. {
  1487. if( this != &rhs )
  1488. {
  1489. this->base::operator=( static_cast<base&&>( rhs ) );
  1490. }
  1491. return *this;
  1492. }
  1493. move_only_function& operator=( std::nullptr_t ) noexcept
  1494. {
  1495. this->base::operator=( nullptr );
  1496. return *this;
  1497. }
  1498. template<class F> move_only_function& operator=( F&& f )
  1499. {
  1500. move_only_function( std::forward<F>( f ) ).swap( *this );
  1501. return *this;
  1502. }
  1503. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  1504. {
  1505. return fn.invoke_ == nullptr;
  1506. }
  1507. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  1508. {
  1509. return !( fn == nullptr );
  1510. }
  1511. void swap( move_only_function& rhs ) noexcept
  1512. {
  1513. if( this != &rhs )
  1514. {
  1515. this->base::swap( rhs );
  1516. }
  1517. }
  1518. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  1519. {
  1520. lhs.swap( rhs );
  1521. }
  1522. explicit operator bool() const noexcept
  1523. {
  1524. return static_cast<bool>( *static_cast<base const*>( this ) );
  1525. }
  1526. R operator()( Args... args ) const& noexcept
  1527. {
  1528. return this->invoke_( this->s_, std::forward<Args>( args )... );
  1529. }
  1530. };
  1531. template<class R, class ...Args>
  1532. class move_only_function<R( Args... ) const&& noexcept> : detail::move_only_function_base<detail::ref_quals::rvalue, true, true, R, Args...>
  1533. {
  1534. private:
  1535. template<detail::ref_quals, bool, bool, class, class ...>
  1536. friend struct detail::move_only_function_base;
  1537. using base = detail::move_only_function_base<detail::ref_quals::rvalue, true, true, R, Args...>;
  1538. public:
  1539. move_only_function() noexcept
  1540. {
  1541. }
  1542. move_only_function( std::nullptr_t ) noexcept
  1543. : move_only_function()
  1544. {
  1545. }
  1546. template<
  1547. class F,
  1548. class VT = decay_t<F>,
  1549. enable_if_t<
  1550. !std::is_same<move_only_function, remove_cvref_t<F>>::value &&
  1551. !detail::is_in_place_type_t<VT>::value &&
  1552. detail::is_callable_from<detail::ref_quals::rvalue, true, true, VT, R, Args...>::value,
  1553. int> = 0
  1554. >
  1555. move_only_function( F&& f ) noexcept( detail::nothrow_init<VT, F>::value )
  1556. {
  1557. if( detail::is_nullary_arg( std::forward<F>( f ) ) ) return;
  1558. base::init( type_identity<VT>{}, std::forward<F>( f ) );
  1559. }
  1560. template<
  1561. class T, class ...CArgs,
  1562. enable_if_t<
  1563. std::is_constructible<T, CArgs...>::value &&
  1564. detail::is_callable_from<detail::ref_quals::rvalue, true, true, T, R, Args...>::value,
  1565. int> = 0
  1566. >
  1567. explicit move_only_function( in_place_type_t<T>, CArgs&& ... args ) noexcept( detail::nothrow_init<T, CArgs...>::value )
  1568. {
  1569. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1570. base::init( type_identity<T>{}, std::forward<CArgs>( args )... );
  1571. }
  1572. template<
  1573. class T, class U, class ...CArgs,
  1574. enable_if_t<
  1575. std::is_constructible<T, std::initializer_list<U>&, CArgs...>::value &&
  1576. detail::is_callable_from<detail::ref_quals::rvalue, true, true, T, R, Args...>::value,
  1577. int> = 0
  1578. >
  1579. explicit move_only_function( in_place_type_t<T>, std::initializer_list<U> il, CArgs&& ... args ) noexcept( detail::nothrow_init<T, std::initializer_list<U>&, CArgs...>::value )
  1580. {
  1581. static_assert( std::is_same<T, decay_t<T>>::value, "T and `decay_t<T>` must be the same" );
  1582. base::init( type_identity<T>{}, il, std::forward<CArgs>( args )... );
  1583. }
  1584. move_only_function( move_only_function const& ) = delete;
  1585. move_only_function( move_only_function&& ) = default;
  1586. ~move_only_function() = default;
  1587. move_only_function& operator=( move_only_function&& rhs )
  1588. {
  1589. if( this != &rhs )
  1590. {
  1591. this->base::operator=( static_cast<base&&>( rhs ) );
  1592. }
  1593. return *this;
  1594. }
  1595. move_only_function& operator=( std::nullptr_t ) noexcept
  1596. {
  1597. this->base::operator=( nullptr );
  1598. return *this;
  1599. }
  1600. template<class F> move_only_function& operator=( F&& f )
  1601. {
  1602. move_only_function( std::forward<F>( f ) ).swap( *this );
  1603. return *this;
  1604. }
  1605. friend bool operator==( move_only_function const& fn, std::nullptr_t ) noexcept
  1606. {
  1607. return fn.invoke_ == nullptr;
  1608. }
  1609. friend bool operator!=( move_only_function const& fn, std::nullptr_t ) noexcept
  1610. {
  1611. return !( fn == nullptr );
  1612. }
  1613. void swap( move_only_function& rhs ) noexcept
  1614. {
  1615. if( this != &rhs )
  1616. {
  1617. this->base::swap( rhs );
  1618. }
  1619. }
  1620. friend void swap( move_only_function& lhs, move_only_function& rhs ) noexcept
  1621. {
  1622. lhs.swap( rhs );
  1623. }
  1624. explicit operator bool() const noexcept
  1625. {
  1626. return static_cast<bool>( *static_cast<base const*>( this ) );
  1627. }
  1628. R operator()( Args... args ) const&& noexcept
  1629. {
  1630. return this->invoke_( this->s_, std::forward<Args>( args )... );
  1631. }
  1632. };
  1633. #endif
  1634. } // namespace compat
  1635. } // namespace boost
  1636. #if BOOST_WORKAROUND(BOOST_GCC, >= 6 * 10000)
  1637. # pragma GCC diagnostic pop
  1638. #endif
  1639. #endif // #ifndef BOOST_COMPAT_MOVE_ONLY_FUNCTION_HPP_INCLUDED