diff --git a/example/backtrace.cpp b/example/backtrace.cpp index 58ddc3f..73d9136 100644 --- a/example/backtrace.cpp +++ b/example/backtrace.cpp @@ -11,9 +11,7 @@ #include -#include - -namespace ctx = boost::context; +#include void backtrace() { unw_cursor_t cursor; @@ -45,13 +43,13 @@ void foo() { bar(); } -ctx::fiber_context f1( ctx::fiber_context && c) { +std::fiber_context f1( std::fiber_context && c) { foo(); return std::move( c); } int main() { - ctx::fiber_context{ f1 }.resume(); + std::fiber_context{ f1 }.resume(); std::cout << "main: done" << std::endl; return EXIT_SUCCESS; } diff --git a/example/circle.cpp b/example/circle.cpp index c2dc5f9..2119935 100644 --- a/example/circle.cpp +++ b/example/circle.cpp @@ -8,13 +8,11 @@ #include #include -#include - -namespace ctx = boost::context; +#include int main() { - ctx::fiber_context f1, f2, f3; - f3 = ctx::fiber_context{[&](ctx::fiber_context && f)->ctx::fiber_context{ + std::fiber_context f1, f2, f3; + f3 = std::fiber_context{[&](std::fiber_context && f)->std::fiber_context{ f2 = std::move( f); for (;;) { std::cout << "f3\n"; @@ -22,7 +20,7 @@ int main() { } return {}; }}; - f2 = ctx::fiber_context{[&](ctx::fiber_context && f)->ctx::fiber_context{ + f2 = std::fiber_context{[&](std::fiber_context && f)->std::fiber_context{ f1 = std::move( f); for (;;) { std::cout << "f2\n"; @@ -30,7 +28,7 @@ int main() { } return {}; }}; - f1 = ctx::fiber_context{[&](ctx::fiber_context && /*main*/)->ctx::fiber_context{ + f1 = std::fiber_context{[&](std::fiber_context && /*main*/)->std::fiber_context{ for (;;) { std::cout << "f1\n"; f3 = std::move( f2).resume(); diff --git a/example/echosse.cpp b/example/echosse.cpp index f878e0c..a4e8e8d 100644 --- a/example/echosse.cpp +++ b/example/echosse.cpp @@ -10,9 +10,7 @@ #include #include -#include - -namespace ctx = boost::context; +#include void echoSSE( int i) { __m128i xmm; @@ -28,8 +26,8 @@ void echoSSE( int i) { int main( int argc, char * argv[]) { int i = 0; - ctx::fiber_context f{ - [&i](ctx::fiber_context && f) { + std::fiber_context f{ + [&i](std::fiber_context && f) { for (;;) { std::cout << i; echoSSE( i); diff --git a/example/endless_loop.cpp b/example/endless_loop.cpp index 984a909..e7376d8 100644 --- a/example/endless_loop.cpp +++ b/example/endless_loop.cpp @@ -7,11 +7,9 @@ #include #include -#include +#include -namespace ctx = boost::context; - -ctx::fiber_context bar( ctx::fiber_context && f) { +std::fiber_context bar( std::fiber_context && f) { do { std::cout << "bar\n"; f = std::move( f).resume(); @@ -20,7 +18,7 @@ ctx::fiber_context bar( ctx::fiber_context && f) { } int main() { - ctx::fiber_context f{ bar }; + std::fiber_context f{ bar }; do { std::cout << "foo\n"; f = std::move( f).resume(); diff --git a/example/fibonacci.cpp b/example/fibonacci.cpp index 3b8ed82..64a40f3 100644 --- a/example/fibonacci.cpp +++ b/example/fibonacci.cpp @@ -8,14 +8,12 @@ #include #include -#include - -namespace ctx = boost::context; +#include int main() { int a; - ctx::fiber_context f{ - [&a](ctx::fiber_context && f){ + std::fiber_context f{ + [&a](std::fiber_context && f){ a=0; int b=1; for(;;){ diff --git a/example/jump.cpp b/example/jump.cpp index 671d065..05243bc 100644 --- a/example/jump.cpp +++ b/example/jump.cpp @@ -7,14 +7,12 @@ #include #include -#include - -namespace ctx = boost::context; +#include int main() { int data = 1; - ctx::fiber_context f{ - [&data](ctx::fiber_context && f){ + std::fiber_context f{ + [&data](std::fiber_context && f){ std::cout << "entered first time: " << data << std::endl; data += 2; f = std::move( f).resume(); diff --git a/example/jump_mov.cpp b/example/jump_mov.cpp index 07a0141..858caf1 100644 --- a/example/jump_mov.cpp +++ b/example/jump_mov.cpp @@ -7,9 +7,7 @@ #include #include -#include - -namespace ctx = boost::context; +#include class moveable { public: @@ -40,8 +38,8 @@ public: int main() { moveable data{ 1 }; - ctx::fiber_context f{ std::allocator_arg, ctx::fixedsize_stack{}, - [&data](ctx::fiber_context && f){ + std::fiber_context f{ std::allocator_arg, std::fixedsize_stack{}, + [&data](std::fiber_context && f){ std::cout << "entered first time: " << data.value << std::endl; data = std::move( moveable{ 3 }); f = std::move( f).resume(); diff --git a/example/jump_void.cpp b/example/jump_void.cpp index 9a515e8..c6e43c4 100644 --- a/example/jump_void.cpp +++ b/example/jump_void.cpp @@ -7,11 +7,9 @@ #include #include -#include +#include -namespace ctx = boost::context; - -ctx::fiber_context f1( ctx::fiber_context && f) { +std::fiber_context f1( std::fiber_context && f) { std::cout << "f1: entered first time" << std::endl; f = std::move( f).resume(); std::cout << "f1: entered second time" << std::endl; @@ -19,7 +17,7 @@ ctx::fiber_context f1( ctx::fiber_context && f) { } int main() { - ctx::fiber_context f{ f1 }; + std::fiber_context f{ f1 }; f = std::move( f).resume(); std::cout << "f1: returned first time" << std::endl; f = std::move( f).resume(); diff --git a/example/ontop.cpp b/example/ontop.cpp index 0f98481..f3e1bdd 100644 --- a/example/ontop.cpp +++ b/example/ontop.cpp @@ -8,13 +8,11 @@ #include #include -#include - -namespace ctx = boost::context; +#include int main() { int data = 0; - ctx::fiber_context f{ [&data](ctx::fiber_context && f) { + std::fiber_context f{ [&data](std::fiber_context && f) { std::cout << "f1: entered first time: " << data << std::endl; data += 1; f = std::move( f).resume(); @@ -30,7 +28,7 @@ int main() { f = std::move( f).resume(); std::cout << "f1: returned second time: " << data << std::endl; data += 1; - f = std::move( f).resume_with([&data](ctx::fiber_context && f){ + f = std::move( f).resume_with([&data](std::fiber_context && f){ std::cout << "f2: entered: " << data << std::endl; data = -1; return std::move( f); diff --git a/example/ontop_void.cpp b/example/ontop_void.cpp index edca806..26f1a9e 100644 --- a/example/ontop_void.cpp +++ b/example/ontop_void.cpp @@ -8,11 +8,9 @@ #include #include -#include +#include -namespace ctx = boost::context; - -ctx::fiber_context f1( ctx::fiber_context && f) { +std::fiber_context f1( std::fiber_context && f) { std::cout << "f1: entered first time" << std::endl; f = std::move( f).resume(); std::cout << "f1: entered second time" << std::endl; @@ -21,13 +19,13 @@ ctx::fiber_context f1( ctx::fiber_context && f) { return std::move( f); } -ctx::fiber_context f2( ctx::fiber_context && f) { +std::fiber_context f2( std::fiber_context && f) { std::cout << "f2: entered" << std::endl; return std::move( f); } int main() { - ctx::fiber_context f{ f1 }; + std::fiber_context f{ f1 }; f = std::move( f).resume(); std::cout << "f1: returned first time" << std::endl; f = std::move( f).resume(); diff --git a/example/parser.cpp b/example/parser.cpp index 499c6bd..8deda18 100644 --- a/example/parser.cpp +++ b/example/parser.cpp @@ -12,9 +12,7 @@ #include #include -#include - -namespace ctx = boost::context; +#include /* * grammar: @@ -98,7 +96,7 @@ int main() { char c; bool done = false; // execute parser in new execution context - ctx::fiber_context source{[&is,&c,&done](ctx::fiber_context && sink){ + std::fiber_context source{[&is,&c,&done](std::fiber_context && sink){ // create parser with callback function Parser p( is, [&sink,&c](char c_){ diff --git a/example/segmented.cpp b/example/segmented.cpp index b9f9e25..79ed4b8 100644 --- a/example/segmented.cpp +++ b/example/segmented.cpp @@ -8,9 +8,7 @@ #include #include -#include - -namespace ctx = boost::context; +#include #ifdef BOOST_MSVC //MS VisualStudio __declspec(noinline) void access( char *buf); @@ -34,15 +32,15 @@ int main() { int count = 100*1024; #if defined(BOOST_USE_SEGMENTED_STACKS) std::cout << "using segmented_stack stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; - std::cout << "initial stack size = " << ctx::segmented_stack::traits_type::default_size() / 1024 << "kB" << std::endl; + std::cout << "initial stack size = " << std::segmented_stack::traits_type::default_size() / 1024 << "kB" << std::endl; std::cout << "application should not fail" << std::endl; #else std::cout << "using standard stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; - std::cout << "initial stack size = " << ctx::fixedsize_stack::traits_type::default_size() / 1024 << "kB" << std::endl; + std::cout << "initial stack size = " << std::fixedsize_stack::traits_type::default_size() / 1024 << "kB" << std::endl; std::cout << "application might fail" << std::endl; #endif - ctx::fiber_context{ - [count](ctx::fiber_context && f){ + std::fiber_context{ + [count](std::fiber_context && f){ bar( count); return std::move( f); }}.resume(); diff --git a/example/stack.cpp b/example/stack.cpp index 8879326..2361ab5 100644 --- a/example/stack.cpp +++ b/example/stack.cpp @@ -7,18 +7,16 @@ #include #include -#include - -namespace ctx = boost::context; +#include int main() { - std::cout << "minimum stack size: " << ctx::stack_traits::minimum_size() << " byte\n"; - std::cout << "default stack size: " << ctx::stack_traits::default_size() << " byte\n"; + std::cout << "minimum stack size: " << std::stack_traits::minimum_size() << " byte\n"; + std::cout << "default stack size: " << std::stack_traits::default_size() << " byte\n"; std::cout << "maximum stack size: "; - if ( ctx::stack_traits::is_unbounded() ) { + if ( std::stack_traits::is_unbounded() ) { std::cout << "unlimited\n"; } else { - std::cout << ctx::stack_traits::maximum_size() << " byte\n"; + std::cout << std::stack_traits::maximum_size() << " byte\n"; } std::cout << "main: done" << std::endl; return EXIT_SUCCESS; diff --git a/example/throw.cpp b/example/throw.cpp index 157f414..405cbc7 100644 --- a/example/throw.cpp +++ b/example/throw.cpp @@ -10,20 +10,18 @@ #include #include -#include - -namespace ctx = boost::context; +#include struct my_exception : public std::runtime_error { - ctx::fiber_context f; - my_exception( ctx::fiber_context && f_, std::string const& what) : + std::fiber_context f; + my_exception( std::fiber_context && f_, std::string const& what) : std::runtime_error{ what }, f{ std::move( f_) } { } }; int main() { - ctx::fiber_context f{[](ctx::fiber_context && f) ->ctx::fiber_context { + std::fiber_context f{[](std::fiber_context && f) ->std::fiber_context { std::cout << "entered" << std::endl; try { f = std::move( f).resume(); @@ -34,7 +32,7 @@ int main() { return {}; }}; f = std::move( f).resume(); - f = std::move( f).resume_with([](ctx::fiber_context && f) ->ctx::fiber_context { + f = std::move( f).resume_with([](std::fiber_context && f) ->std::fiber_context { throw my_exception(std::move( f), "abc"); return {}; }); diff --git a/include/boost/context/detail/apply.hpp b/include/boost/context/detail/apply.hpp deleted file mode 100644 index fbf0ca6..0000000 --- a/include/boost/context/detail/apply.hpp +++ /dev/null @@ -1,74 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_CONTEXT_DETAIL_APPLY_H -#define BOOST_CONTEXT_DETAIL_APPLY_H - -#include -#include -#include -#include - -#include - -#include -#if defined(BOOST_NO_CXX17_STD_INVOKE) -#include -#endif -#include - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -#if defined(BOOST_MSVC) -# pragma warning(push) -# pragma warning(disable: 4100) -#endif - -namespace boost { -namespace context { -namespace detail { - -template< typename Fn, typename Tpl, std::size_t ... I > -auto -apply_impl( Fn && fn, Tpl && tpl, index_sequence< I ... >) -#if defined(BOOST_NO_CXX17_STD_INVOKE) - -> decltype( boost::context::detail::invoke( std::forward< Fn >( fn), std::get< I >( std::forward< Tpl >( tpl) ) ... ) ) -#else - -> decltype( std::invoke( std::forward< Fn >( fn), std::get< I >( std::forward< Tpl >( tpl) ) ... ) ) -#endif -{ -#if defined(BOOST_NO_CXX17_STD_INVOKE) - return boost::context::detail::invoke( std::forward< Fn >( fn), std::get< I >( std::forward< Tpl >( tpl) ) ... ); -#else - return std::invoke( std::forward< Fn >( fn), std::get< I >( std::forward< Tpl >( tpl) ) ... ); -#endif -} - -template< typename Fn, typename Tpl > -auto -apply( Fn && fn, Tpl && tpl) - -> decltype( apply_impl( std::forward< Fn >( fn), - std::forward< Tpl >( tpl), - make_index_sequence< std::tuple_size< typename std::decay< Tpl >::type >::value >{}) ) -{ - return apply_impl( std::forward< Fn >( fn), - std::forward< Tpl >( tpl), - make_index_sequence< std::tuple_size< typename std::decay< Tpl >::type >::value >{}); -} - -}}} - -#if defined(BOOST_MSVC) -# pragma warning(pop) -#endif - -#ifdef BOOST_HAS_ABI_HEADERS -#include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_CONTEXT_DETAIL_APPLY_H diff --git a/include/boost/context/detail/disable_overload.hpp b/include/boost/context/detail/disable_overload.hpp index c88f916..39a23c9 100644 --- a/include/boost/context/detail/disable_overload.hpp +++ b/include/boost/context/detail/disable_overload.hpp @@ -17,8 +17,7 @@ # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { namespace detail { // http://ericniebler.com/2013/08/07/universal-references-and-the-copy-constructo/ @@ -31,7 +30,7 @@ using disable_overload = >::value >::type; -}}} +}} #ifdef BOOST_HAS_ABI_HEADERS #include BOOST_ABI_SUFFIX diff --git a/include/boost/context/detail/exception.hpp b/include/boost/context/detail/exception.hpp index 801201d..ade12c0 100644 --- a/include/boost/context/detail/exception.hpp +++ b/include/boost/context/detail/exception.hpp @@ -16,8 +16,7 @@ # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { namespace detail { struct forced_unwind { @@ -30,7 +29,7 @@ struct forced_unwind { } }; -}}} +}} #ifdef BOOST_HAS_ABI_HEADERS #include BOOST_ABI_SUFFIX diff --git a/include/boost/context/detail/exchange.hpp b/include/boost/context/detail/exchange.hpp deleted file mode 100644 index c5ee912..0000000 --- a/include/boost/context/detail/exchange.hpp +++ /dev/null @@ -1,36 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_CONTEXT_DETAIL_EXCHANGE_H -#define BOOST_CONTEXT_DETAIL_EXCHANGE_H - -#include -#include - -#include - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace context { -namespace detail { - -template< typename T, typename U = T > -T exchange( T & t, U && nv) { - T ov = std::move( t); - t = std::forward< U >( nv); - return ov; -} - -}}} - -#ifdef BOOST_HAS_ABI_HEADERS -#include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_CONTEXT_DETAIL_EXCHANGE_H diff --git a/include/boost/context/detail/fcontext.hpp b/include/boost/context/detail/fcontext.hpp index 00cb24d..b20d6c1 100644 --- a/include/boost/context/detail/fcontext.hpp +++ b/include/boost/context/detail/fcontext.hpp @@ -16,8 +16,7 @@ # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { namespace detail { typedef void* fcontext_t; @@ -36,7 +35,7 @@ fcontext_t BOOST_CONTEXT_CALLDECL make_fcontext( void * sp, std::size_t size, vo extern "C" BOOST_CONTEXT_DECL transfer_t BOOST_CONTEXT_CALLDECL ontop_fcontext( fcontext_t const to, void * vp, transfer_t (* fn)( transfer_t) ); -}}} +}} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/detail/index_sequence.hpp b/include/boost/context/detail/index_sequence.hpp deleted file mode 100644 index ed54425..0000000 --- a/include/boost/context/detail/index_sequence.hpp +++ /dev/null @@ -1,50 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_CONTEXT_DETAIL_INDEX_SEQUENCE_H -#define BOOST_CONTEXT_DETAIL_INDEX_SEQUENCE_H - -#include - -#include - -#include - -#if defined(BOOST_CONTEXT_NO_CXX14_INTEGER_SEQUENCE) -#include -#endif - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace context { -namespace detail { - -#if ! defined(BOOST_CONTEXT_NO_CXX14_INTEGER_SEQUENCE) -template< std::size_t ... I > -using index_sequence = std::index_sequence< I ... >; -template< std::size_t I > -using make_index_sequence = std::make_index_sequence< I >; -template< typename ... T > -using index_sequence_for = std::index_sequence_for< T ... >; -#else -template< std::size_t ... I > -using index_sequence = mp11::index_sequence< I ... >; -template< std::size_t I > -using make_index_sequence = mp11::make_index_sequence< I >; -template< typename ... T > -using index_sequence_for = mp11::index_sequence_for< T ... >; -#endif - -}}} - -#ifdef BOOST_HAS_ABI_HEADERS -#include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_CONTEXT_DETAIL_INDEX_SEQUENCE_H diff --git a/include/boost/context/detail/invoke.hpp b/include/boost/context/detail/invoke.hpp deleted file mode 100644 index 9173cbc..0000000 --- a/include/boost/context/detail/invoke.hpp +++ /dev/null @@ -1,50 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_CONTEXT_DETAIL_INVOKE_H -#define BOOST_CONTEXT_DETAIL_INVOKE_H - -#include -#include -#include - -#include - -#include - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace context { -namespace detail { - -template< typename Fn, typename ... Args > -typename std::enable_if< - std::is_member_pointer< typename std::decay< Fn >::type >::value, - typename std::result_of< Fn &&( Args && ... ) >::type ->::type -invoke( Fn && fn, Args && ... args) { - return std::mem_fn( fn)( std::forward< Args >( args) ... ); -} - -template< typename Fn, typename ... Args > -typename std::enable_if< - ! std::is_member_pointer< typename std::decay< Fn >::type >::value, - typename std::result_of< Fn &&( Args && ... ) >::type ->::type -invoke( Fn && fn, Args && ... args) { - return std::forward< Fn >( fn)( std::forward< Args >( args) ... ); -} - -}}} - -#ifdef BOOST_HAS_ABI_HEADERS -#include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_CONTEXT_DETAIL_INVOKE_H diff --git a/include/boost/context/detail/prefetch.hpp b/include/boost/context/detail/prefetch.hpp index 27f2fdb..489a0e8 100644 --- a/include/boost/context/detail/prefetch.hpp +++ b/include/boost/context/detail/prefetch.hpp @@ -26,8 +26,7 @@ # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { namespace detail { #if BOOST_COMP_GNUC || BOOST_COMP_CLANG @@ -69,7 +68,7 @@ void prefetch_range( void * addr, std::size_t len) { #undef BOOST_HAS_PREFETCH -}}} +}} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/detail/tuple.hpp b/include/boost/context/detail/tuple.hpp deleted file mode 100644 index e1b2f86..0000000 --- a/include/boost/context/detail/tuple.hpp +++ /dev/null @@ -1,129 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_CONTEXT_DETAIL_TUPLE_H -#define BOOST_CONTEXT_DETAIL_TUPLE_H - -#include -#include - -#include - -#include -#include - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace context { -namespace detail { - -template< typename ... S, typename ... T, std::size_t ... I > -void -head_impl( std::tuple< S ... > & s, - std::tuple< T ... > & t, index_sequence< I ... >) { - t = std::tuple< T ... >{ std::get< I >( s) ... }; -} - -template< typename ... S, typename ... T, std::size_t ... I > -void -head_impl( std::tuple< S ... > && s, - std::tuple< T ... > & t, index_sequence< I ... >) { - t = std::tuple< T ... >{ std::get< I >( std::move( s) ) ... }; -} - -template< typename ... S, std::size_t ... I1, typename ... T, std::size_t ... I2 > -void -tail_impl( std::tuple< S ... > & s, index_sequence< I1 ... >, - std::tuple< T ... > & t, index_sequence< I2 ... >) { - constexpr std::size_t Idx = (sizeof...(I1)) - (sizeof...(I2)); - t = std::tuple< T ... >{ std::get< (Idx + I2) >( s) ... }; -} - -template< typename ... S, std::size_t ... I1, typename ... T, std::size_t ... I2 > -void -tail_impl( std::tuple< S ... > && s, index_sequence< I1 ... >, - std::tuple< T ... > & t, index_sequence< I2 ... >) { - constexpr std::size_t Idx = (sizeof...(I1)) - (sizeof...(I2)); - t = std::tuple< T ... >{ std::get< (Idx + I2) >( std::move( s) ) ... }; -} - -template< typename ... T > -class tuple_head; - -template< typename ... T > -class tuple_head< std::tuple< T ... > > { -private: - std::tuple< T ... > & t_; - -public: - tuple_head( std::tuple< T ... > & t) noexcept : - t_( t) { - } - - template< typename ... S > - void operator=( std::tuple< S ... > & s) { - static_assert((sizeof...(T)) <= (sizeof...(S)), "invalid tuple size"); - head_impl( s, - t_, index_sequence_for< T ... >{} ); - } - template< typename ... S > - void operator=( std::tuple< S ... > && s) { - static_assert((sizeof...(T)) <= (sizeof...(S)), "invalid tuple size"); - head_impl( std::move( s), - t_, index_sequence_for< T ... >{} ); - } -}; - -template< typename ... T > -class tuple_tail; - -template< typename ... T > -class tuple_tail< std::tuple< T ... > > { -private: - std::tuple< T ... > & t_; - -public: - tuple_tail( std::tuple< T ... > & t) noexcept : - t_( t) { - } - - template< typename ... S > - void operator=( std::tuple< S ... > & s) { - static_assert((sizeof...(T)) <= (sizeof...(S)), "invalid tuple size"); - tail_impl( s, index_sequence_for< S ... >{}, - t_, index_sequence_for< T ... >{} ); - } - - template< typename ... S > - void operator=( std::tuple< S ... > && s) { - static_assert((sizeof...(T)) <= (sizeof...(S)), "invalid tuple size"); - tail_impl( std::move( s), index_sequence_for< S ... >{}, - t_, index_sequence_for< T ... >{} ); - } -}; - -template< typename ... T > -detail::tuple_head< std::tuple< T ... > > -head( std::tuple< T ... > & tpl) { - return tuple_head< std::tuple< T ... > >{ tpl }; -} - -template< typename ... T > -detail::tuple_tail< std::tuple< T ... > > -tail( std::tuple< T ... > & tpl) { - return tuple_tail< std::tuple< T ... > >{ tpl }; -} - -}}} - -#ifdef BOOST_HAS_ABI_HEADERS -#include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_CONTEXT_DETAIL_TUPLE_H diff --git a/include/boost/context/fiber_context.hpp b/include/boost/context/fiber_context similarity index 100% rename from include/boost/context/fiber_context.hpp rename to include/boost/context/fiber_context diff --git a/include/boost/context/fiber_context_fcontext.hpp b/include/boost/context/fiber_context_fcontext.hpp index f9c8712..cde203a 100644 --- a/include/boost/context/fiber_context_fcontext.hpp +++ b/include/boost/context/fiber_context_fcontext.hpp @@ -17,23 +17,15 @@ #include #include #include -#include #include #include #include #include -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) -#include -#endif -#if defined(BOOST_NO_CXX17_STD_INVOKE) -#include -#endif #include #include #include -#include #include #include #include @@ -60,8 +52,7 @@ # pragma warning(disable: 4702) #endif -namespace boost { -namespace context { +namespace std { namespace detail { inline @@ -111,11 +102,7 @@ transfer_t fiber_context_ontop( transfer_t t) { t.data = nullptr; // execute function, pass fiber_context via reference Ctx c = p( Ctx{ t.fctx } ); -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - return { exchange( c.fctx_, nullptr), nullptr }; -#else return { std::exchange( c.fctx_, nullptr), nullptr }; -#endif } template< typename Ctx, typename StackAlloc, typename Fn > @@ -151,16 +138,8 @@ public: fcontext_t run( fcontext_t fctx) { // invoke context-function -#if defined(BOOST_NO_CXX17_STD_INVOKE) - Ctx c = boost::context::detail::invoke( fn_, Ctx{ fctx } ); -#else Ctx c = std::invoke( fn_, Ctx{ fctx } ); -#endif -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - return exchange( c.fctx_, nullptr); -#else return std::exchange( c.fctx_, nullptr); -#endif } }; @@ -296,11 +275,7 @@ public: ~fiber_context() { if ( BOOST_UNLIKELY( nullptr != fctx_) ) { detail::ontop_fcontext( -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - detail::exchange( fctx_, nullptr), -#else std::exchange( fctx_, nullptr), -#endif nullptr, detail::fiber_context_unwind); } @@ -324,11 +299,7 @@ public: fiber_context resume() && { BOOST_ASSERT( nullptr != fctx_); return { detail::jump_fcontext( -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - detail::exchange( fctx_, nullptr), -#else std::exchange( fctx_, nullptr), -#endif nullptr).fctx }; } @@ -337,11 +308,7 @@ public: BOOST_ASSERT( nullptr != fctx_); auto p = std::forward< Fn >( fn); return { detail::ontop_fcontext( -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - detail::exchange( fctx_, nullptr), -#else std::exchange( fctx_, nullptr), -#endif & p, detail::fiber_context_ontop< fiber_context, decltype(p) >).fctx }; } @@ -369,7 +336,7 @@ public: } #if !defined(BOOST_EMBTC) - + template< typename charT, class traitsT > friend std::basic_ostream< charT, traitsT > & operator<<( std::basic_ostream< charT, traitsT > & os, fiber_context const& other) { @@ -381,7 +348,7 @@ public: } #else - + template< typename charT, class traitsT > friend std::basic_ostream< charT, traitsT > & operator<<( std::basic_ostream< charT, traitsT > & os, fiber_context const& other); @@ -402,13 +369,13 @@ public: } #endif - + inline void swap( fiber_context & l, fiber_context & r) noexcept { l.swap( r); } -}} +} #if defined(BOOST_MSVC) # pragma warning(pop) diff --git a/include/boost/context/fiber_context_ucontext.hpp b/include/boost/context/fiber_context_ucontext.hpp index df37ad6..2750582 100644 --- a/include/boost/context/fiber_context_ucontext.hpp +++ b/include/boost/context/fiber_context_ucontext.hpp @@ -28,7 +28,6 @@ extern "C" { #include #include #include -#include #include #include @@ -36,13 +35,7 @@ extern "C" { #include #include -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) -#include -#endif #include -#if defined(BOOST_NO_CXX17_STD_INVOKE) -#include -#endif #include #include #include @@ -59,8 +52,7 @@ extern "C" { #include #endif -namespace boost { -namespace context { +namespace std { namespace detail { // tampoline function @@ -163,11 +155,7 @@ struct BOOST_CONTEXT_DECL fiber_context_activation_record { (const void **) & current()->from->stack_bottom, & current()->from->stack_size); #endif -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - return exchange( current()->from, nullptr); -#else return std::exchange( current()->from, nullptr); -#endif } template< typename Ctx, typename Fn > @@ -177,36 +165,14 @@ struct BOOST_CONTEXT_DECL fiber_context_activation_record { // `this` will become the active (running) context // returned by fiber_context::current() current() = this; -#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - current()->ontop = std::bind( - [](typename std::decay< Fn >::type & fn, fiber_context_activation_record *& ptr){ - Ctx c{ ptr }; - c = fn( std::move( c) ); - if ( ! c) { - ptr = nullptr; - } -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - return exchange( c.ptr_, nullptr); -#else - return std::exchange( c.ptr_, nullptr); -#endif - }, - std::forward< Fn >( fn), - std::placeholders::_1); -#else current()->ontop = [fn=std::forward(fn)](fiber_context_activation_record *& ptr){ Ctx c{ ptr }; c = fn( std::move( c) ); if ( ! c) { ptr = nullptr; } -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - return exchange( c.ptr_, nullptr); -#else return std::exchange( c.ptr_, nullptr); -#endif }; -#endif #if defined(BOOST_USE_SEGMENTED_STACKS) // adjust segmented stack properties __splitstack_getcontext( from->sctx.segments_ctx); @@ -225,11 +191,7 @@ struct BOOST_CONTEXT_DECL fiber_context_activation_record { (const void **) & current()->from->stack_bottom, & current()->from->stack_size); #endif -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - return exchange( current()->from, nullptr); -#else return std::exchange( current()->from, nullptr); -#endif } virtual void deallocate() noexcept { @@ -285,11 +247,7 @@ public: Ctx c{ from }; try { // invoke context-function -#if defined(BOOST_NO_CXX17_STD_INVOKE) - c = boost::context::detail::invoke( fn_, std::move( c) ); -#else c = std::invoke( fn_, std::move( c) ); -#endif } catch ( forced_unwind const& ex) { c = Ctx{ ex.from }; } @@ -482,11 +440,7 @@ public: fiber_context resume() && { BOOST_ASSERT( nullptr != ptr_); -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - detail::fiber_context_activation_record * ptr = detail::exchange( ptr_, nullptr)->resume(); -#else detail::fiber_context_activation_record * ptr = std::exchange( ptr_, nullptr)->resume(); -#endif if ( BOOST_UNLIKELY( detail::fiber_context_activation_record::current()->force_unwind) ) { throw detail::forced_unwind{ ptr}; } else if ( BOOST_UNLIKELY( nullptr != detail::fiber_context_activation_record::current()->ontop) ) { @@ -499,13 +453,8 @@ public: template< typename Fn > fiber_context resume_with( Fn && fn) && { BOOST_ASSERT( nullptr != ptr_); -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - detail::fiber_context_activation_record * ptr = - detail::exchange( ptr_, nullptr)->resume_with< fiber_context >( std::forward< Fn >( fn) ); -#else detail::fiber_context_activation_record * ptr = std::exchange( ptr_, nullptr)->resume_with< fiber_context >( std::forward< Fn >( fn) ); -#endif if ( BOOST_UNLIKELY( detail::fiber_context_activation_record::current()->force_unwind) ) { throw detail::forced_unwind{ ptr}; } else if ( BOOST_UNLIKELY( nullptr != detail::fiber_context_activation_record::current()->ontop) ) { @@ -577,7 +526,7 @@ void swap( fiber_context & l, fiber_context & r) noexcept { l.swap( r); } -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/fiber_context_winfib.hpp b/include/boost/context/fiber_context_winfib.hpp index 629adff..d0d2d9b 100644 --- a/include/boost/context/fiber_context_winfib.hpp +++ b/include/boost/context/fiber_context_winfib.hpp @@ -20,19 +20,12 @@ #include #include #include -#include #include #include #include #include -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) -#include -#endif -#if defined(BOOST_NO_CXX17_STD_INVOKE) -#include -#endif #include #include #include @@ -47,8 +40,7 @@ # pragma warning(disable: 4702) #endif -namespace boost { -namespace context { +namespace std { namespace detail { // tampoline function @@ -121,11 +113,7 @@ struct BOOST_CONTEXT_DECL fiber_context_activation_record { // context switch from parent context to `this`-context // context switch ::SwitchToFiber( fiber_context); -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - return detail::exchange( current()->from, nullptr); -#else return std::exchange( current()->from, nullptr); -#endif } template< typename Ctx, typename Fn > @@ -135,43 +123,17 @@ struct BOOST_CONTEXT_DECL fiber_context_activation_record { // `this` will become the active (running) context // returned by fiber_context::current() current() = this; -#if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) - current()->ontop = std::bind( - [](typename std::decay< Fn >::type & fn, fiber_context_activation_record *& ptr){ - Ctx c{ ptr }; - c = fn( std::move( c) ); - if ( ! c) { - ptr = nullptr; - } -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - return exchange( c.ptr_, nullptr); -#else - return std::exchange( c.ptr_, nullptr); -#endif - }, - std::forward< Fn >( fn), - std::placeholders::_1); -#else current()->ontop = [fn=std::forward(fn)](fiber_context_activation_record *& ptr){ Ctx c{ ptr }; c = fn( std::move( c) ); if ( ! c) { ptr = nullptr; } -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - return exchange( c.ptr_, nullptr); -#else return std::exchange( c.ptr_, nullptr); -#endif }; -#endif // context switch ::SwitchToFiber( fiber_context); -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - return detail::exchange( current()->from, nullptr); -#else return std::exchange( current()->from, nullptr); -#endif } virtual void deallocate() noexcept { @@ -222,11 +184,7 @@ public: Ctx c{ from }; try { // invoke context-function -#if defined(BOOST_NO_CXX17_STD_INVOKE) - c = boost::context::detail::invoke( fn_, std::move( c) ); -#else c = std::invoke( fn_, std::move( c) ); -#endif } catch ( forced_unwind const& ex) { c = Ctx{ ex.from }; } @@ -346,11 +304,7 @@ public: fiber_context resume() && { BOOST_ASSERT( nullptr != ptr_); -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - detail::fiber_context_activation_record * ptr = detail::exchange( ptr_, nullptr)->resume(); -#else detail::fiber_context_activation_record * ptr = std::exchange( ptr_, nullptr)->resume(); -#endif if ( BOOST_UNLIKELY( detail::fiber_context_activation_record::current()->force_unwind) ) { throw detail::forced_unwind{ ptr}; } else if ( BOOST_UNLIKELY( nullptr != detail::fiber_context_activation_record::current()->ontop) ) { @@ -363,13 +317,8 @@ public: template< typename Fn > fiber_context resume_with( Fn && fn) && { BOOST_ASSERT( nullptr != ptr_); -#if defined(BOOST_NO_CXX14_STD_EXCHANGE) - detail::fiber_context_activation_record * ptr = - detail::exchange( ptr_, nullptr)->resume_with< fiber_context >( std::forward< Fn >( fn) ); -#else detail::fiber_context_activation_record * ptr = std::exchange( ptr_, nullptr)->resume_with< fiber_context >( std::forward< Fn >( fn) ); -#endif if ( BOOST_UNLIKELY( detail::fiber_context_activation_record::current()->force_unwind) ) { throw detail::forced_unwind{ ptr}; } else if ( BOOST_UNLIKELY( nullptr != detail::fiber_context_activation_record::current()->ontop) ) { @@ -441,7 +390,7 @@ void swap( fiber_context & l, fiber_context & r) noexcept { l.swap( r); } -}} +} #if defined(BOOST_MSVC) # pragma warning(pop) diff --git a/include/boost/context/fixedsize_stack.hpp b/include/boost/context/fixedsize_stack.hpp index c309347..24d6d30 100644 --- a/include/boost/context/fixedsize_stack.hpp +++ b/include/boost/context/fixedsize_stack.hpp @@ -32,8 +32,7 @@ extern "C" { # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { template< typename traitsT > class basic_fixedsize_stack { @@ -88,7 +87,7 @@ typedef basic_fixedsize_stack< stack_traits > fixedsize_stack; typedef fixedsize_stack default_stack; # endif -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/flags.hpp b/include/boost/context/flags.hpp index c7ff117..b967780 100644 --- a/include/boost/context/flags.hpp +++ b/include/boost/context/flags.hpp @@ -13,13 +13,12 @@ # include BOOST_ABI_PREFIX # endif -namespace boost { -namespace context { +namespace std { struct exec_ontop_arg_t {}; const exec_ontop_arg_t exec_ontop_arg{}; -}} +} # ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/pooled_fixedsize_stack.hpp b/include/boost/context/pooled_fixedsize_stack.hpp index c115c86..5ebf690 100644 --- a/include/boost/context/pooled_fixedsize_stack.hpp +++ b/include/boost/context/pooled_fixedsize_stack.hpp @@ -36,8 +36,7 @@ extern "C" { # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { #if defined(BOOST_CONTEXT_USE_MAP_STACK) namespace detail { @@ -143,7 +142,7 @@ public: typedef basic_pooled_fixedsize_stack< stack_traits > pooled_fixedsize_stack; -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/posix/protected_fixedsize_stack.hpp b/include/boost/context/posix/protected_fixedsize_stack.hpp index cc77d7d..2ec8987 100644 --- a/include/boost/context/posix/protected_fixedsize_stack.hpp +++ b/include/boost/context/posix/protected_fixedsize_stack.hpp @@ -34,8 +34,7 @@ extern "C" { # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { template< typename traitsT > class basic_protected_fixedsize_stack { @@ -93,7 +92,7 @@ public: typedef basic_protected_fixedsize_stack< stack_traits > protected_fixedsize_stack; -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/posix/segmented_stack.hpp b/include/boost/context/posix/segmented_stack.hpp index e3d2efc..577b1a1 100644 --- a/include/boost/context/posix/segmented_stack.hpp +++ b/include/boost/context/posix/segmented_stack.hpp @@ -34,8 +34,7 @@ void __splitstack_block_signals_context( void * [BOOST_CONTEXT_SEGMENTS], int * new_value, int * old_value); } -namespace boost { -namespace context { +namespace std { template< typename traitsT > class basic_segmented_stack { @@ -73,7 +72,7 @@ typedef basic_segmented_stack< stack_traits > segmented_stack; typedef segmented_stack default_stack; # endif -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/preallocated.hpp b/include/boost/context/preallocated.hpp index 862a6a5..7b17065 100644 --- a/include/boost/context/preallocated.hpp +++ b/include/boost/context/preallocated.hpp @@ -17,8 +17,7 @@ # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { struct preallocated { void * sp; @@ -30,7 +29,7 @@ struct preallocated { } }; -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/stack_context.hpp b/include/boost/context/stack_context.hpp index 740d981..222d508 100644 --- a/include/boost/context/stack_context.hpp +++ b/include/boost/context/stack_context.hpp @@ -17,8 +17,7 @@ # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { #if ! defined(BOOST_CONTEXT_NO_CXX11) struct BOOST_CONTEXT_DECL stack_context { @@ -63,7 +62,7 @@ struct BOOST_CONTEXT_DECL stack_context { }; #endif -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/stack_traits.hpp b/include/boost/context/stack_traits.hpp index d5320f5..97a2caf 100644 --- a/include/boost/context/stack_traits.hpp +++ b/include/boost/context/stack_traits.hpp @@ -17,8 +17,7 @@ # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { struct BOOST_CONTEXT_DECL stack_traits { @@ -33,7 +32,7 @@ struct BOOST_CONTEXT_DECL stack_traits static std::size_t maximum_size() BOOST_NOEXCEPT_OR_NOTHROW; }; -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/include/boost/context/windows/protected_fixedsize_stack.hpp b/include/boost/context/windows/protected_fixedsize_stack.hpp index 30f74c2..7108fe0 100644 --- a/include/boost/context/windows/protected_fixedsize_stack.hpp +++ b/include/boost/context/windows/protected_fixedsize_stack.hpp @@ -27,8 +27,7 @@ extern "C" { # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { template< typename traitsT > class basic_protected_fixedsize_stack { @@ -73,7 +72,7 @@ public: typedef basic_protected_fixedsize_stack< stack_traits > protected_fixedsize_stack; -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/src/fiber_context.cpp b/src/fiber_context.cpp index a421e75..6bf9ba2 100644 --- a/src/fiber_context.cpp +++ b/src/fiber_context.cpp @@ -16,8 +16,7 @@ # include BOOST_ABI_PREFIX #endif -namespace boost { -namespace context { +namespace std { namespace detail { // zero-initialization @@ -51,7 +50,7 @@ fiber_context_activation_record::current() noexcept { } -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/src/posix/stack_traits.cpp b/src/posix/stack_traits.cpp index 4dd1829..84cdc21 100644 --- a/src/posix/stack_traits.cpp +++ b/src/posix/stack_traits.cpp @@ -56,8 +56,7 @@ rlim_t stacksize_limit() BOOST_NOEXCEPT_OR_NOTHROW { } -namespace boost { -namespace context { +namespace std { bool stack_traits::is_unbounded() BOOST_NOEXCEPT_OR_NOTHROW { @@ -86,7 +85,7 @@ stack_traits::maximum_size() BOOST_NOEXCEPT_OR_NOTHROW { return static_cast< std::size_t >( stacksize_limit() ); } -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/src/windows/stack_traits.cpp b/src/windows/stack_traits.cpp index 4edada0..2987bb8 100644 --- a/src/windows/stack_traits.cpp +++ b/src/windows/stack_traits.cpp @@ -51,8 +51,7 @@ std::size_t pagesize() BOOST_NOEXCEPT_OR_NOTHROW { } -namespace boost { -namespace context { +namespace std { // Windows seams not to provide a limit for the stacksize // libcoco uses 32k+4k bytes as minimum @@ -91,7 +90,7 @@ stack_traits::maximum_size() BOOST_NOEXCEPT_OR_NOTHROW { return 1 * 1024 * 1024 * 1024; // 1GB } -}} +} #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 8d964d1..ea79254 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -57,38 +57,6 @@ local only-when-segmented-stack-is-available = ; test-suite minimal : -[ run test_invoke.cpp : - : : - [ requires cxx11_auto_declarations - cxx11_constexpr - cxx11_defaulted_functions - cxx11_final - cxx11_hdr_thread - cxx11_hdr_tuple - cxx11_lambdas - cxx11_noexcept - cxx11_nullptr - cxx11_rvalue_references - cxx11_template_aliases - cxx11_thread_local - cxx11_variadic_templates ] ] - -[ run test_apply.cpp : - : : - [ requires cxx11_auto_declarations - cxx11_constexpr - cxx11_defaulted_functions - cxx11_final - cxx11_hdr_thread - cxx11_hdr_tuple - cxx11_lambdas - cxx11_noexcept - cxx11_nullptr - cxx11_rvalue_references - cxx11_template_aliases - cxx11_thread_local - cxx11_variadic_templates ] ] - [ run test_fiber_context.cpp : : : fcontext diff --git a/test/test_apply.cpp b/test/test_apply.cpp deleted file mode 100644 index 5fa685f..0000000 --- a/test/test_apply.cpp +++ /dev/null @@ -1,208 +0,0 @@ - -// Copyright Oliver Kowalke 2009. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#define BOOST_CHECK_EQUAL(a, b) BOOST_TEST_EQ(a, b) - -namespace ctx = boost::context; - -struct callable { - int k{ 0 }; - - callable() = default; - - callable( int k_) : - k{ k_ } { - } - - int foo( int i, int j) const { - return i + j + k; - } - - int operator()( int i, int j) const { - return foo( i, j); - } -}; - -struct movable { - int k{ 0 }; - - movable() = default; - - movable( int k_) : - k{ k_ } { - } - - movable( movable const&) = delete; - movable & operator=( movable const&) = delete; - - movable( movable && other) : - k{ other.k } { - other.k = -1; - } - - movable & operator=( movable && other) { - if ( this == & other) return * this; - k = other.k; - other.k = -1; - return * this; - } - - int foo( int i, int j) const { - return i + j + k; - } - - int operator()( int i, int j) const { - return foo( i, j); - } -}; - -int fn1( int i, int j) { - return i + j; -} - -int * fn2( int * ip) { - return ip; -} - -int * fn3( int & ir) { - return & ir; -} - -int & fn4( int & ir) { - return ir; -} - -int fn5( int i, callable && c) { - return i + c.k; -} - -int fn6( int i, movable && m) { - return i + m.k; -} - -void test1() { - int result = ctx::detail::apply( fn1, std::make_tuple( 1, 2) ); - BOOST_CHECK_EQUAL( result, 3); -} - -void test2() { - { - int i = 3; - int * ip = & i; - int * result = ctx::detail::apply( fn2, std::make_tuple( ip) ); - BOOST_CHECK_EQUAL( result, ip); - BOOST_CHECK_EQUAL( * result, i); - } - { - int i = 3; - int * result = ctx::detail::apply( fn2, std::make_tuple( & i) ); - BOOST_CHECK_EQUAL( result, & i); - BOOST_CHECK_EQUAL( * result, i); - } -} - -void test3() { - { - int i = 'c'; - int & ir = i; - int * result = ctx::detail::apply( fn3, std::make_tuple( std::ref( ir) ) ); - BOOST_CHECK_EQUAL( result, & ir); - BOOST_CHECK_EQUAL( * result, i); - } - { - int i = 'c'; - int * result = ctx::detail::apply( fn3, std::make_tuple( std::ref( i) ) ); - BOOST_CHECK_EQUAL( result, & i); - BOOST_CHECK_EQUAL( * result, i); - } -} - -void test4() { - { - int i = 3; - int & ir = i; - int & result = ctx::detail::apply( fn4, std::make_tuple( std::ref( ir) ) ); - BOOST_CHECK_EQUAL( result, ir); - BOOST_CHECK_EQUAL( & result, & ir); - BOOST_CHECK_EQUAL( result, i); - } - { - int i = 3; - int & result = ctx::detail::apply( fn4, std::make_tuple( std::ref( i) ) ); - BOOST_CHECK_EQUAL( & result, & i); - BOOST_CHECK_EQUAL( result, i); - } -} - -void test5() { - { - callable c( 5); - int result = ctx::detail::apply( fn5, std::make_tuple( 1, std::move( c) ) ); - BOOST_CHECK_EQUAL( result, 6); - BOOST_CHECK_EQUAL( c.k, 5); - } - { - movable m( 5); - int result = ctx::detail::apply( fn6, std::make_tuple( 1, std::move( m) ) ); - BOOST_CHECK_EQUAL( result, 6); - BOOST_CHECK_EQUAL( m.k, -1); - } -} - -void test6() { - { - callable c; - int result = ctx::detail::apply( c, std::make_tuple( 1, 2) ); - BOOST_CHECK_EQUAL( result, 3); - BOOST_CHECK_EQUAL( c.k, 0); - } - { - callable c; - int result = ctx::detail::apply( & callable::foo, std::make_tuple( c, 1, 2) ); - BOOST_CHECK_EQUAL( result, 3); - BOOST_CHECK_EQUAL( c.k, 0); - } -} - -void test7() { - { - movable m; - int result = ctx::detail::apply( std::move( m), std::make_tuple( 1, 2) ); - BOOST_CHECK_EQUAL( result, 3); - } - { - movable m; - int result = ctx::detail::apply( & movable::foo, std::make_tuple( std::move( m), 1, 2) ); - BOOST_CHECK_EQUAL( result, 3); - } -} - -int main() -{ - test1(); - test2(); - test3(); - test4(); - test5(); - test6(); - test7(); - - return boost::report_errors(); -} diff --git a/test/test_fcontext.cpp b/test/test_fcontext.cpp index 5173242..90511c7 100644 --- a/test/test_fcontext.cpp +++ b/test/test_fcontext.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #define BOOST_CHECK(x) BOOST_TEST(x) @@ -65,7 +64,7 @@ typedef simple_stack_allocator< 8 * 1024 * 1024, 64 * 1024, 8 * 1024 > stack_allocator; -namespace ctx = boost::context::detail; +namespace ctx = std::detail; typedef simple_stack_allocator< 8 * 1024 * 1024, // 8MB diff --git a/test/test_fiber_context.cpp b/test/test_fiber_context.cpp index cadfaff..9519db7 100644 --- a/test/test_fiber_context.cpp +++ b/test/test_fiber_context.cpp @@ -27,7 +27,6 @@ #include #include -#include #ifdef BOOST_WINDOWS #include @@ -43,14 +42,12 @@ typedef boost::variant variant_t; -namespace ctx = boost::context; - int value1 = 0; std::string value2; double value3 = 0.; struct X { - ctx::fiber_context foo( ctx::fiber_context && f, int i) { + std::fiber_context foo( std::fiber_context && f, int i) { value1 = i; return std::move( f); } @@ -109,8 +106,8 @@ public: }; struct my_exception : public std::runtime_error { - ctx::fiber_context f; - my_exception( ctx::fiber_context && f_, char const* what) : + std::fiber_context f; + my_exception( std::fiber_context && f_, char const* what) : std::runtime_error( what), f{ std::move( f_) } { } @@ -134,8 +131,8 @@ void test_move() { value1 = 0; int i = 1; BOOST_CHECK_EQUAL( 0, value1); - ctx::fiber_context f1{ - [&i](ctx::fiber_context && f) { + std::fiber_context f1{ + [&i](std::fiber_context && f) { value1 = i; f = std::move( f).resume(); value1 = i; @@ -148,7 +145,7 @@ void test_move() { BOOST_CHECK( f1); BOOST_CHECK( ! f1.empty() ); BOOST_CHECK( f1.can_resume() ); - ctx::fiber_context f2; + std::fiber_context f2; BOOST_CHECK( f2.empty() ); BOOST_CHECK( ! f2.can_resume() ); f2 = std::move( f1); @@ -169,7 +166,7 @@ void test_move() { void test_bind() { value1 = 0; X x; - ctx::fiber_context f{ std::bind( & X::foo, x, std::placeholders::_1, 7) }; + std::fiber_context f{ std::bind( & X::foo, x, std::placeholders::_1, 7) }; f = std::move( f).resume(); BOOST_CHECK_EQUAL( 7, value1); } @@ -177,8 +174,8 @@ void test_bind() { void test_exception() { { const char * what = "hello world"; - ctx::fiber_context f{ - [&what](ctx::fiber_context && f) { + std::fiber_context f{ + [&what](std::fiber_context && f) { try { throw std::runtime_error( what); } catch ( std::runtime_error const& e) { @@ -195,7 +192,7 @@ void test_exception() { { bool catched = false; std::thread([&catched](){ - ctx::fiber_context f{ [&catched](ctx::fiber_context && f){ + std::fiber_context f{ [&catched](std::fiber_context && f){ seh( catched); return std::move( f); }}; @@ -210,8 +207,8 @@ void test_exception() { void test_fp() { value3 = 0.; double d = 7.13; - ctx::fiber_context f{ - [&d]( ctx::fiber_context && f) { + std::fiber_context f{ + [&d]( std::fiber_context && f) { d += 3.45; value3 = d; return std::move( f); @@ -225,10 +222,10 @@ void test_fp() { void test_stacked() { value1 = 0; value3 = 0.; - ctx::fiber_context f{ - [](ctx::fiber_context && f) { - ctx::fiber_context f1{ - [](ctx::fiber_context && f) { + std::fiber_context f{ + [](std::fiber_context && f) { + std::fiber_context f1{ + [](std::fiber_context && f) { value1 = 3; return std::move( f); }}; @@ -245,14 +242,14 @@ void test_stacked() { void test_prealloc() { value1 = 0; - ctx::default_stack alloc; - ctx::stack_context sctx( alloc.allocate() ); + std::default_stack alloc; + std::stack_context sctx( alloc.allocate() ); void * sp = static_cast< char * >( sctx.sp) - 10; std::size_t size = sctx.size - 10; int i = 7; - ctx::fiber_context f{ - std::allocator_arg, ctx::preallocated( sp, size, sctx), alloc, - [&i]( ctx::fiber_context && f) { + std::fiber_context f{ + std::allocator_arg, std::preallocated( sp, size, sctx), alloc, + [&i]( std::fiber_context && f) { value1 = i; return std::move( f); }}; @@ -265,7 +262,7 @@ void test_prealloc() { void test_ontop() { { int i = 3; - ctx::fiber_context f{ [&i](ctx::fiber_context && f) { + std::fiber_context f{ [&i](std::fiber_context && f) { for (;;) { i *= 10; f = std::move( f).resume(); @@ -274,7 +271,7 @@ void test_ontop() { }}; f = std::move( f).resume(); // Pass fn by reference to see if the types are properly decayed. - auto fn = [&i](ctx::fiber_context && f){ + auto fn = [&i](std::fiber_context && f){ i -= 10; return std::move( f); }; @@ -283,8 +280,8 @@ void test_ontop() { BOOST_CHECK_EQUAL( i, 200); } { - ctx::fiber_context f1; - ctx::fiber_context f{ [&f1](ctx::fiber_context && f) { + std::fiber_context f1; + std::fiber_context f{ [&f1](std::fiber_context && f) { f = std::move( f).resume(); BOOST_CHECK( f.empty() ); BOOST_CHECK( ! f.can_resume() ); @@ -292,7 +289,7 @@ void test_ontop() { }}; f = std::move( f).resume(); f = std::move( f).resume_with( - [&f1](ctx::fiber_context && f){ + [&f1](std::fiber_context && f){ f1 = std::move( f); return std::move( f); }); @@ -302,7 +299,7 @@ void test_ontop() { void test_ontop_exception() { value1 = 0; value2 = ""; - ctx::fiber_context f{ [](ctx::fiber_context && f){ + std::fiber_context f{ [](std::fiber_context && f){ for (;;) { value1 = 3; try { @@ -318,7 +315,7 @@ void test_ontop_exception() { BOOST_CHECK_EQUAL( 3, value1); const char * what = "hello world"; f = std::move( f).resume_with( - [what](ctx::fiber_context && f){ + [what](std::fiber_context && f){ throw my_exception( std::move( f), what); return std::move( f); }); @@ -329,8 +326,8 @@ void test_ontop_exception() { void test_termination1() { { value1 = 0; - ctx::fiber_context f{ - [](ctx::fiber_context && f){ + std::fiber_context f{ + [](std::fiber_context && f){ Y y; f = std::move( f).resume(); return std::move(f); @@ -342,8 +339,8 @@ void test_termination1() { { value1 = 0; BOOST_CHECK_EQUAL( 0, value1); - ctx::fiber_context f{ - [](ctx::fiber_context && f) { + std::fiber_context f{ + [](std::fiber_context && f) { value1 = 3; return std::move( f); }}; @@ -356,8 +353,8 @@ void test_termination1() { value1 = 0; BOOST_CHECK_EQUAL( 0, value1); int i = 3; - ctx::fiber_context f{ - [&i](ctx::fiber_context && f){ + std::fiber_context f{ + [&i](std::fiber_context && f){ value1 = i; f = std::move( f).resume(); value1 = i; @@ -379,8 +376,8 @@ void test_termination2() { { value1 = 0; value3 = 0.0; - ctx::fiber_context f{ - [](ctx::fiber_context && f){ + std::fiber_context f{ + [](std::fiber_context && f){ Y y; value1 = 3; value3 = 4.; @@ -402,8 +399,8 @@ void test_termination2() { } void test_sscanf() { - ctx::fiber_context{ - []( ctx::fiber_context && f) { + std::fiber_context{ + []( std::fiber_context && f) { { double n1 = 0; double n2 = 0; @@ -430,8 +427,8 @@ void test_sscanf() { } void test_snprintf() { - ctx::fiber_context{ - []( ctx::fiber_context && f) { + std::fiber_context{ + []( std::fiber_context && f) { { const char *fmt = "sqrt(2) = %f"; char buf[19]; @@ -452,8 +449,8 @@ void test_snprintf() { #ifdef BOOST_WINDOWS void test_bug12215() { - ctx::fiber_context{ - [](ctx::fiber_context && f) { + std::fiber_context{ + [](std::fiber_context && f) { char buffer[MAX_PATH]; GetModuleFileName( nullptr, buffer, MAX_PATH); return std::move( f); @@ -465,15 +462,15 @@ void test_goodcatch() { value1 = 0; value3 = 0.0; { - ctx::fiber_context f{ - []( ctx::fiber_context && f) { + std::fiber_context f{ + []( std::fiber_context && f) { Y y; value3 = 2.; f = std::move( f).resume(); try { value3 = 3.; f = std::move( f).resume(); - } catch ( boost::context::detail::forced_unwind const&) { + } catch ( std::detail::forced_unwind const&) { value3 = 4.; throw; } catch (...) { @@ -500,8 +497,8 @@ void test_badcatch() { value1 = 0; value3 = 0.; { - ctx::fiber_context f{ - []( ctx::fiber_context && f) { + std::fiber_context f{ + []( std::fiber_context && f) { Y y; try { value3 = 3.; diff --git a/test/test_invoke.cpp b/test/test_invoke.cpp deleted file mode 100644 index e3a5edc..0000000 --- a/test/test_invoke.cpp +++ /dev/null @@ -1,241 +0,0 @@ - -// Copyright Oliver Kowalke 2009. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#if defined(BOOST_NO_CXX17_STD_INVOKE) -#include -#include - -#define BOOST_CHECK_EQUAL(a, b) BOOST_TEST_EQ(a, b) - -namespace ctx = boost::context; - -struct callable { - int k{ 0 }; - - callable() = default; - - callable( int k_) : - k{ k_ } { - } - - int foo( int i, int j) const { - return i + j + k; - } - - int operator()( int i, int j) const { - return foo( i, j); - } -}; - -struct movable { - int k{ 0 }; - - movable() = default; - - movable( int k_) : - k{ k_ } { - } - - movable( movable const&) = delete; - movable & operator=( movable const&) = delete; - - movable( movable && other) : - k{ other.k } { - other.k = -1; - } - - movable & operator=( movable && other) { - if ( this == & other) return * this; - k = other.k; - other.k = -1; - return * this; - } - - int foo( int i, int j) const { - return i + j + k; - } - - int operator()( int i, int j) const { - return foo( i, j); - } -}; - -int fn1( int i, int j) { - return i + j; -} - -int * fn2( int * ip) { - return ip; -} - -int * fn3( int & ir) { - return & ir; -} - -int & fn4( int & ir) { - return ir; -} - -template< typename T > -int fn5( int i, T && t_) { - T t = std::forward< T >( t_); - return i + t.k; -} - -void test1() { - int result = ctx::detail::invoke( fn1, 1, 2); - BOOST_CHECK_EQUAL( result, 3); -} - -void test2() { - { - int i = 3; - int * ip = & i; - int * result = ctx::detail::invoke( fn2, ip); - BOOST_CHECK_EQUAL( result, ip); - BOOST_CHECK_EQUAL( * result, i); - } - { - int i = 3; - int * result = ctx::detail::invoke( fn2, & i); - BOOST_CHECK_EQUAL( result, & i); - BOOST_CHECK_EQUAL( * result, i); - } -} - -void test3() { - { - int i = 3; - int & ir = i; - int * result = ctx::detail::invoke( fn3, ir); - BOOST_CHECK_EQUAL( result, & ir); - BOOST_CHECK_EQUAL( * result, i); - } - { - int i = 3; - int * result = ctx::detail::invoke( fn3, i); - BOOST_CHECK_EQUAL( result, & i); - BOOST_CHECK_EQUAL( * result, i); - } -} - -void test4() { - { - int i = 3; - int & ir = i; - int & result = ctx::detail::invoke( fn4, ir); - BOOST_CHECK_EQUAL( result, ir); - BOOST_CHECK_EQUAL( & result, & ir); - BOOST_CHECK_EQUAL( result, i); - } - { - int i = 3; - int & result = ctx::detail::invoke( fn4, i); - BOOST_CHECK_EQUAL( & result, & i); - BOOST_CHECK_EQUAL( result, i); - } -} - -void test5() { - { - callable c( 5); - int result = ctx::detail::invoke( fn5< callable >, 1, std::move( c) ); - BOOST_CHECK_EQUAL( result, 6); - BOOST_CHECK_EQUAL( c.k, 5); - } - { - movable m( 5); - int result = ctx::detail::invoke( fn5< movable >, 1, std::move( m) ); - BOOST_CHECK_EQUAL( result, 6); - BOOST_CHECK_EQUAL( m.k, -1); - } -} - -void test6() { - { - callable c; - int result = ctx::detail::invoke( c, 1, 2); - BOOST_CHECK_EQUAL( result, 3); - BOOST_CHECK_EQUAL( c.k, 0); - } - { - callable c; - int result = ctx::detail::invoke( & callable::foo, c, 1, 2); - BOOST_CHECK_EQUAL( result, 3); - BOOST_CHECK_EQUAL( c.k, 0); - } -} - -void test7() { - { - int result = ctx::detail::invoke( movable{}, 1, 2); - BOOST_CHECK_EQUAL( result, 3); - } - { - int result = ctx::detail::invoke( & movable::foo, movable{}, 1, 2); - BOOST_CHECK_EQUAL( result, 3); - } -} - -template< typename R, typename Fn, typename ... Args > -R apply( Fn && fn, Args && ... args) { - return ctx::detail::invoke( - std::forward< Fn >( fn), - std::forward< Args >( args) ... ); -} - -void test8() { - { - int result = apply< int >( fn1, 1, 2); - BOOST_CHECK_EQUAL( result, 3); - } - { - int i = 3; - int & ir = i; - int * result = apply< int * >( fn3, ir); - BOOST_CHECK_EQUAL( result, & ir); - BOOST_CHECK_EQUAL( * result, i); - } - { - movable m( 5); - int result = apply< int >( fn5< movable >, 1, std::move( m) ); - BOOST_CHECK_EQUAL( result, 6); - BOOST_CHECK_EQUAL( m.k, -1); - } -} -#else -void dummy() {} -#endif - -int main() -{ -#if defined(BOOST_NO_CXX17_STD_INVOKE) - test1(); - test2(); - test3(); - test4(); - test5(); - test6(); - test7(); - test8(); -#else - dummy(); -#endif - - return boost::report_errors(); -}