mirror of
https://github.com/boostorg/yap.git
synced 2026-02-23 16:22:09 +00:00
Factor out detail/expression.hpp.
This commit is contained in:
77
detail/expression.hpp
Normal file
77
detail/expression.hpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef BOOST_PROTO17_DETAIL_EXPRESSION_HPP_INCLUDED
|
||||
#define BOOST_PROTO17_DETAIL_EXPRESSION_HPP_INCLUDED
|
||||
|
||||
#include "../expression_fwd.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
namespace boost::proto17 {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename T>
|
||||
struct partial_decay
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct partial_decay<T[]> { using type = T *; };
|
||||
template <typename T, std::size_t N>
|
||||
struct partial_decay<T[N]> { using type = T *; };
|
||||
|
||||
template <typename T>
|
||||
struct partial_decay<T(&)[]> { using type = T *; };
|
||||
template <typename T, std::size_t N>
|
||||
struct partial_decay<T(&)[N]> { using type = T *; };
|
||||
|
||||
template <typename R, typename ...A>
|
||||
struct partial_decay<R(A...)> { using type = R(*)(A...); };
|
||||
template <typename R, typename ...A>
|
||||
struct partial_decay<R(A..., ...)> { using type = R(*)(A..., ...); };
|
||||
|
||||
template <typename T,
|
||||
typename U = typename detail::partial_decay<T>::type,
|
||||
bool AddRValueRef = std::is_same_v<T, U> && !std::is_const_v<U>>
|
||||
struct rhs_value_type_phase_1;
|
||||
|
||||
template <typename T, typename U>
|
||||
struct rhs_value_type_phase_1<T, U, true>
|
||||
{ using type = U &&; };
|
||||
|
||||
template <typename T, typename U>
|
||||
struct rhs_value_type_phase_1<T, U, false>
|
||||
{ using type = U; };
|
||||
|
||||
template <typename ...T>
|
||||
struct is_expr
|
||||
{ static bool const value = false; };
|
||||
|
||||
template <expr_kind Kind, typename ...T>
|
||||
struct is_expr<expression<Kind, T...>>
|
||||
{ static bool const value = true; };
|
||||
|
||||
template <typename T,
|
||||
typename U = typename rhs_value_type_phase_1<T>::type,
|
||||
bool RemoveRefs = std::is_rvalue_reference_v<U>,
|
||||
bool IsExpr = is_expr<std::decay_t<T>>::value>
|
||||
struct rhs_type;
|
||||
|
||||
template <typename T, typename U, bool RemoveRefs>
|
||||
struct rhs_type<T, U, RemoveRefs, true>
|
||||
{ using type = std::remove_cv_t<std::remove_reference_t<T>>; };
|
||||
|
||||
template <typename T, typename U>
|
||||
struct rhs_type<T, U, true, false>
|
||||
{ using type = terminal<std::remove_reference_t<U>>; };
|
||||
|
||||
template <typename T, typename U>
|
||||
struct rhs_type<T, U, false, false>
|
||||
{ using type = terminal<U>; };
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef BOOST_PROTO17_EXPRESSION_FWD_HPP_INCLUDED
|
||||
#define BOOST_PROTO17_EXPRESSION_FWD_HPP_INCLUDED
|
||||
|
||||
#include <boost/hana/fwd/integral_constant.hpp>
|
||||
|
||||
|
||||
namespace boost::proto17 {
|
||||
|
||||
@@ -17,6 +19,12 @@ namespace boost::proto17 {
|
||||
template <expr_kind Kind, typename ...T>
|
||||
struct expression;
|
||||
|
||||
template <typename T>
|
||||
using terminal = expression<expr_kind::terminal, T>;
|
||||
|
||||
template <long long I>
|
||||
using placeholder = expression<expr_kind::placeholder, hana::llong<I>>;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef BOOST_PROTO17_OPERATORS_HPP_INCLUDED
|
||||
#define BOOST_PROTO17_OPERATORS_HPP_INCLUDED
|
||||
|
||||
#include "expression_fwd.hpp"
|
||||
|
||||
|
||||
namespace boost::proto17 {
|
||||
|
||||
|
||||
67
sketch.cpp
67
sketch.cpp
@@ -1,6 +1,7 @@
|
||||
#include "expression_fwd.hpp"
|
||||
|
||||
#include "operators.hpp"
|
||||
#include "detail/expression.hpp"
|
||||
|
||||
#define BOOST_PROTO17_STREAM_OPERATORS // TODO: For testing.
|
||||
#include "print.hpp"
|
||||
@@ -18,71 +19,8 @@
|
||||
|
||||
namespace boost::proto17 {
|
||||
|
||||
template <typename T>
|
||||
using terminal = expression<expr_kind::terminal, T>;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename T>
|
||||
struct partial_decay
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct partial_decay<T[]> { using type = T *; };
|
||||
template <typename T, std::size_t N>
|
||||
struct partial_decay<T[N]> { using type = T *; };
|
||||
|
||||
template <typename T>
|
||||
struct partial_decay<T(&)[]> { using type = T *; };
|
||||
template <typename T, std::size_t N>
|
||||
struct partial_decay<T(&)[N]> { using type = T *; };
|
||||
|
||||
template <typename R, typename ...A>
|
||||
struct partial_decay<R(A...)> { using type = R(*)(A...); };
|
||||
template <typename R, typename ...A>
|
||||
struct partial_decay<R(A..., ...)> { using type = R(*)(A..., ...); };
|
||||
|
||||
template <typename T,
|
||||
typename U = typename detail::partial_decay<T>::type,
|
||||
bool AddRValueRef = std::is_same_v<T, U> && !std::is_const_v<U>>
|
||||
struct rhs_value_type_phase_1;
|
||||
|
||||
template <typename T, typename U>
|
||||
struct rhs_value_type_phase_1<T, U, true>
|
||||
{ using type = U &&; };
|
||||
|
||||
template <typename T, typename U>
|
||||
struct rhs_value_type_phase_1<T, U, false>
|
||||
{ using type = U; };
|
||||
|
||||
template <typename ...T>
|
||||
struct is_expr
|
||||
{ static bool const value = false; };
|
||||
|
||||
template <expr_kind Kind, typename ...T>
|
||||
struct is_expr<expression<Kind, T...>>
|
||||
{ static bool const value = true; };
|
||||
|
||||
template <typename T,
|
||||
typename U = typename rhs_value_type_phase_1<T>::type,
|
||||
bool RemoveRefs = std::is_rvalue_reference_v<U>,
|
||||
bool IsExpr = is_expr<std::decay_t<T>>::value>
|
||||
struct rhs_type;
|
||||
|
||||
template <typename T, typename U, bool RemoveRefs>
|
||||
struct rhs_type<T, U, RemoveRefs, true>
|
||||
{ using type = std::remove_cv_t<std::remove_reference_t<T>>; };
|
||||
|
||||
template <typename T, typename U>
|
||||
struct rhs_type<T, U, true, false>
|
||||
{ using type = terminal<std::remove_reference_t<U>>; };
|
||||
|
||||
template <typename T, typename U>
|
||||
struct rhs_type<T, U, false, false>
|
||||
{ using type = terminal<U>; };
|
||||
|
||||
template <typename Tuple, expr_kind Kind, typename ...T>
|
||||
auto default_eval_expr (expression<Kind, T...> const & expr, Tuple && tuple)
|
||||
{
|
||||
@@ -194,9 +132,6 @@ namespace boost::proto17 {
|
||||
}
|
||||
};
|
||||
|
||||
template <long long I>
|
||||
using placeholder = expression<expr_kind::placeholder, hana::llong<I>>;
|
||||
|
||||
namespace literals {
|
||||
|
||||
template <char ...c>
|
||||
|
||||
Reference in New Issue
Block a user