98 lines
2.8 KiB
C++
98 lines
2.8 KiB
C++
#ifndef REXY_EXPRESSION_HPP
|
|
#define REXY_EXPRESSION_HPP
|
|
|
|
#include <type_traits>
|
|
#include <utility> //forward
|
|
|
|
namespace rexy{
|
|
|
|
template<class L, class R>
|
|
class binary_expression
|
|
{
|
|
static_assert(!std::is_same<std::decay_t<L>,void>::value, "Left value of rexy::binary_expression cannot be void!");
|
|
static_assert(!std::is_same<std::decay_t<R>,void>::value, "Right value of rexy::binary_expression cannot be void!");
|
|
|
|
public:
|
|
using left_type = std::conditional_t<std::is_rvalue_reference<L>::value,
|
|
std::remove_reference_t<L>,
|
|
L>;
|
|
using right_type = std::conditional_t<std::is_rvalue_reference<R>::value,
|
|
std::remove_reference_t<R>,
|
|
R>;
|
|
|
|
using left_reference = std::remove_reference_t<left_type>&;
|
|
using left_const_reference = const std::remove_reference_t<left_type>&;
|
|
using right_reference = std::remove_reference_t<right_type>&;
|
|
using right_const_reference = const std::remove_reference_t<right_type>&;
|
|
|
|
protected:
|
|
left_type m_l;
|
|
right_type m_r;
|
|
|
|
public:
|
|
template<class U, class V>
|
|
constexpr binary_expression(U&& u, V&& v)noexcept:
|
|
m_l(std::forward<U>(u)),
|
|
m_r(std::forward<V>(v)){}
|
|
constexpr binary_expression(const binary_expression&) = default;
|
|
constexpr binary_expression(binary_expression&&) = default;
|
|
|
|
constexpr binary_expression& operator=(const binary_expression&) = default;
|
|
constexpr binary_expression& operator=(binary_expression&&) = default;
|
|
|
|
constexpr left_reference left(void)noexcept{
|
|
return m_l;
|
|
}
|
|
constexpr left_const_reference left(void)const noexcept{
|
|
return m_l;
|
|
}
|
|
constexpr right_reference right(void)noexcept{
|
|
return m_r;
|
|
}
|
|
constexpr right_const_reference right(void)const noexcept{
|
|
return m_r;
|
|
}
|
|
|
|
};
|
|
|
|
template<class L>
|
|
class unary_expression
|
|
{
|
|
static_assert(!std::is_same<std::decay_t<L>,void>::value, "Value of rexy::unary_expression cannot be void!");
|
|
|
|
public:
|
|
using left_type = std::conditional_t<std::is_rvalue_reference<L>::value,
|
|
std::remove_reference_t<L>,
|
|
L>;
|
|
using left_reference = std::remove_reference_t<left_type>&;
|
|
using left_const_reference = const std::remove_reference_t<left_type>&;
|
|
|
|
using value_type = left_type;
|
|
using reference = left_reference;
|
|
using const_reference = left_const_reference;
|
|
|
|
protected:
|
|
value_type m_l;
|
|
|
|
public:
|
|
template<class U>
|
|
constexpr unary_expression(U&& u)noexcept:
|
|
m_l(std::forward<U>(u)){}
|
|
|
|
constexpr unary_expression(const unary_expression&)noexcept = default;
|
|
constexpr unary_expression(unary_expression&&)noexcept = default;
|
|
|
|
constexpr reference left(void)noexcept{
|
|
return m_l;
|
|
}
|
|
constexpr const_reference left(void)const noexcept{
|
|
return m_l;
|
|
}
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
#endif
|