xtd 1.0.0
Loading...
Searching...
No Matches
and.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 {
30 template<typename left_t, typename right_t>
31 struct and_ : binary_expression {
33
38
40
43 constexpr and_() = default;
44
48 constexpr and_(left_t left, right_t right) : left {std::move(left)}, right {std::move(right)} {}
50
52
57 template<typename... args_t>
58 constexpr auto operator()(args_t&&... args) const {
59 auto&& l = left(std::forward<args_t>(args)...);
60 auto&& r = right(std::forward<args_t>(args)...);
61 using result_t = std::decay_t<decltype(l & r)>;
62 if constexpr (xtd::numeric<result_t>) return static_cast<result_t>(l & r);
63 else return l & r;
64 }
65
66
68 friend inline auto operator <<(std::ostream& os, const and_& e) -> std::ostream& {return os << expression_stream {e.left, e.precedence} << " & " << expression_stream {e.right, e.precedence};}
70
71 private:
72 [[no_unique_address]] left_t left;
73 [[no_unique_address]] right_t right;
74 };
75
77 template<typename left_t, typename right_t>
78 requires std::is_base_of_v<expression, std::decay_t<left_t>> || std::is_base_of_v<expression, std::decay_t<right_t>>
79 constexpr auto expression::and_(left_t left, right_t right) {
80 auto left_expression = as_expression(left);
81 auto right_expression = as_expression(right);
82 return expressions::and_<std::decay_t<decltype(left_expression)>, std::decay_t<decltype(right_expression)>> {std::move(left_expression), std::move(right_expression)};
83 }
85
87
105 template<typename left_t, typename right_t>
107 constexpr auto operator &(left_t left, right_t right) {return expression::and_(std::move(left), std::move(right));}
109 }
110}
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.
constexpr auto operator<<(left_t left, right_t right)
Subtract the specified left and right operands.
Definition left_shift.hpp:127
operator_precedence
Specifies the operator precedence.
Definition operator_precedence.hpp:22
constexpr auto operator&(left_t left, right_t right)
Subtract the specified left and right operands.
Definition and.hpp:107
@ bitwise_and
Represnets the bitwise and operator precedence (a & b).
Definition operator_precedence.hpp:110
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
@ 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.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::and_ is the bitwise and expression.
Definition and.hpp:31
constexpr and_()=default
Initialize a new xtd::expressions::and_ object.
constexpr auto operator()(args_t &&... args) const
Bitwise and the specified arguments.
Definition and.hpp:58
static constexpr operator_precedence precedence
The operator precedence. That contains one of xtd::expressions::operator_precedence values.
Definition and.hpp:36
constexpr and_(left_t left, right_t right)
Initialize a new xtd::expressions::and_ object with specified left and right operands.
Definition and.hpp:48
Generates a set of positional args that can be decomposed using structured bindings to build readable...
Definition args.hpp:42
The xtd::expressions::expression_stream is the streamable class for expression objects.
Definition expression_stream.hpp:23
static constexpr auto and_(left_t left, right_t right)
Bitwise and the specified left and right operands.