xtd 0.2.0
Loading...
Searching...
No Matches
not_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 {
27 template <typename value_t>
28 struct not_expression : unary_expression {
30
35
37
40 constexpr not_expression() = default;
41
44 constexpr not_expression(value_t value) : value {std::move(value)} {}
46
48
53 template <typename... args_t>
54 constexpr auto operator()(args_t&&... args) const {
55 auto&& v = value(std::forward<args_t>(args)...);
56 using result_t = std::decay_t<decltype(v)>;
57 if constexpr (xtd::numeric<result_t>) return static_cast<result_t>(~v);
58 else return ~v;
59 }
60
61
63 friend inline auto operator <<(std::ostream& os, const not_expression& e) -> std::ostream& {return os << "~" << expression_stream {e.value, e.precedence};}
65
66 private:
67 [[no_unique_address]] value_t value;
68 };
69
71 template <typename vakue_t>
72 requires std::is_base_of_v<expression, std::decay_t<vakue_t>>
73 constexpr auto expression::not_(vakue_t value) {
74 auto expression = as_expression(value);
75 return not_expression<std::decay_t<decltype(expression)>> {std::move(expression)};
76 }
78
80
113 template <typename value_t>
115 constexpr auto operator ~(value_t value) {return expression::not_(std::move(value));}
117 }
118}
Contains xtd::expressions::as_expression methods.
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~(value_t value)
Add the specified left and right operands.
Definition not_expression.hpp:115
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 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_not
Represnets the bitwise not operator precedence (~a).
Definition operator_precedence.hpp:58
@ v
The V key.
Definition console_key.hpp:130
@ 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 not_(value_t value)
Bitwise not the specified left and right operands.
static constexpr auto value(type_t value)
Gets the value value.
The xtd::expressions::not_expression is the bitwise not expression.
Definition not_expression.hpp:28
constexpr not_expression(value_t value)
Initialize a new xtd::expressions::not_expression object with specified value operand.
Definition not_expression.hpp:44
static constexpr operator_precedence precedence
The operator precedence. That contains one of xtd::expressions::operator_precedence values.
Definition not_expression.hpp:33
constexpr not_expression()=default
Initialize a new xtd::expressions::not_expression object.
constexpr auto operator()(args_t &&... args) const
Add the specified arguments.
Definition not_expression.hpp:54
The xtd::expressions::value is the value wrapper.
Definition value.hpp:55
Contains xtd::expressions::unary_expression struct.