-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit a1c10b1.
- Loading branch information
Showing
5 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
// 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 <functional> | ||
#include <tuple> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
#include <boost/config.hpp> | ||
|
||
#include <boost/context/detail/config.hpp> | ||
#if defined(BOOST_NO_CXX17_STD_INVOKE) | ||
#include <boost/context/detail/invoke.hpp> | ||
#endif | ||
#include <boost/context/detail/index_sequence.hpp> | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
// 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 <cstddef> | ||
|
||
#include <boost/config.hpp> | ||
|
||
#include <boost/context/detail/config.hpp> | ||
|
||
#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 | ||
//http://stackoverflow.com/questions/17424477/implementation-c14-make-integer-sequence | ||
|
||
template< std::size_t ... I > | ||
struct index_sequence { | ||
using type = index_sequence; | ||
using value_type = std::size_t; | ||
static constexpr std::size_t size() { | ||
return sizeof ... (I); | ||
} | ||
}; | ||
|
||
template< typename Seq1, typename Seq2 > | ||
struct concat_sequence; | ||
|
||
template< std::size_t ... I1, std::size_t ... I2 > | ||
struct concat_sequence< index_sequence< I1 ... >, index_sequence< I2 ... > > : public index_sequence< I1 ..., (sizeof ... (I1)+I2) ... > { | ||
}; | ||
|
||
template< std::size_t I > | ||
struct make_index_sequence : public concat_sequence< typename make_index_sequence< I/2 >::type, | ||
typename make_index_sequence< I-I/2 >::type > { | ||
}; | ||
|
||
template<> | ||
struct make_index_sequence< 0 > : public index_sequence<> { | ||
}; | ||
template<> | ||
struct make_index_sequence< 1 > : public index_sequence< 0 > { | ||
}; | ||
|
||
template< typename ... T > | ||
using index_sequence_for = make_index_sequence< sizeof ... (T) >; | ||
#endif | ||
|
||
}}} | ||
|
||
#ifdef BOOST_HAS_ABI_HEADERS | ||
#include BOOST_ABI_SUFFIX | ||
#endif | ||
|
||
#endif // BOOST_CONTEXT_DETAIL_INDEX_SEQUENCE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
|
||
// 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 <tuple> | ||
#include <utility> | ||
|
||
#include <boost/config.hpp> | ||
|
||
#include <boost/context/detail/config.hpp> | ||
#include <boost/context/detail/index_sequence.hpp> | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters