xtd 0.2.0
Loading...
Searching...
No Matches
xor_expression.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "as_expression.hpp"
9#include "../numeric.hpp"
10#include <utility>
11
13namespace xtd {
15 namespace expressions {
46 template <typename left_t, typename right_t>
47 struct xor_expression : binary_expression {
49
54
56
59 constexpr xor_expression() = default;
60
64 constexpr xor_expression(left_t left, right_t right) : left {std::move(left)}, right {std::move(right)} {}
66
68
73 template <typename... args_t>
74 constexpr auto operator()(args_t&&... args) const {
75 auto&& l = left(std::forward<args_t>(args)...);
76 auto&& r = right(std::forward<args_t>(args)...);
77 using result_t = std::decay_t<decltype(l & r)>;
78 if constexpr (xtd::numeric<result_t>) return static_cast<result_t>(l ^ r);
79 else return l ^ r;
80 }
81
82
84 friend inline auto operator <<(std::ostream& os, const xor_expression& e) -> std::ostream& {return os << expression_stream {e.left, e.precedence} << " ^ " << expression_stream {e.right, e.precedence};}
86
87 private:
88 [[no_unique_address]] left_t left;
89 [[no_unique_address]] right_t right;
90 };
91
93 template <typename left_t, typename right_t>
94 requires std::is_base_of_v<expression, std::decay_t<left_t>> || std::is_base_of_v<expression, std::decay_t<right_t>>
95 constexpr auto expression::xor_(left_t left, right_t right) {
96 auto left_expression = as_expression(left);
97 auto right_expression = as_expression(right);
98 return xor_expression<std::decay_t<decltype(left_expression)>, std::decay_t<decltype(right_expression)>> {std::move(left_expression), std::move(right_expression)};
99 }
101
103
145 template <typename left_t, typename right_t>
147 constexpr auto operator ^(left_t left, right_t right) {return expression::xor_(std::move(left), std::move(right));}
149 }
150}
Contains xtd::expressions::as_expression methods.
Contains xtd::expressions::binary_expression struct.
The xtd::expressions::expression_operand object is expression operand concept.
Definition expression_operand.hpp:27
Definition numeric.hpp:12
Contains xtd::expressions::expression_operand concept.
Contains xtd::expressions::expression_stream struct.
operator_precedence
Specifies the operator precedence.
Definition operator_precedence.hpp:22
constexpr decltype(auto) as_expression(type_t &&value)
The xtd::expressions::as_expression method convert a type as xtd::expressions::expression.
Definition as_expression.hpp:33
constexpr auto operator^(left_t left, right_t right)
Subtract the specified left and right operands.
Definition xor_expression.hpp:147
constexpr auto operator<<(left_t left, right_t right)
Subtract the specified left and right operands.
Definition left_shift_expression.hpp:127
constexpr auto args()
Generates a set of positional placeholders that can be decomposed using structured bindings to build ...
Definition args.hpp:43
@ bitwise_xor
Represnets the bitwise xor operator precedence (a ^ b).
Definition operator_precedence.hpp:112
@ l
The L key.
Definition console_key.hpp:110
@ r
The R key.
Definition console_key.hpp:122
@ e
The E key.
Definition console_key.hpp:96
The xtd::expressions namespace provides a lightweight, composable expression template framework for b...
Definition add_expression.hpp:14
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::numeric concept.
The xtd::expressions::expression_stream is the streamable class for expression objects.
Definition expression_stream.hpp:23
static constexpr auto xor_(left_t left, right_t right)
Bitwise xor the specified left and right operands.
The xtd::expressions::xor_expression is the bitwise xor expression.
Definition xor_expression.hpp:47
constexpr auto operator()(args_t &&... args) const
Bitwise xor the specified arguments.
Definition xor_expression.hpp:74
static constexpr operator_precedence precedence
The operator precedence. That contains one of xtd::expressions::operator_precedence values.
Definition xor_expression.hpp:52
constexpr xor_expression(left_t left, right_t right)
Initialize a new xtd::expressions::xor_expression object with specified left and right operands.
Definition xor_expression.hpp:64
constexpr xor_expression()=default
Initialize a new xtd::expressions::xor_expression object.