SXEval 1.0.3
A generic s-expression interpreter library.
Loading...
Searching...
No Matches
NotEqual.hpp
Go to the documentation of this file.
1#ifndef SXEVAL_OPERATIONS_NOTEQUAL_HPP
2#define SXEVAL_OPERATIONS_NOTEQUAL_HPP
3
5#include "sxeval/utils.hpp"
6
7
8/* DEFINITIONS */
9
10namespace sxeval {
11namespace operations {
12
13template <typename T>
14class NotEqual : public AOperation<T> {
15public:
16 static constexpr const char* KEY = "!=";
17 static constexpr const int ARITY_MIN = 2;
18 static constexpr const int ARITY_MAX = AOperation<T>::UNLIMITED_ARITY;
19
20 inline NotEqual(const std::vector<IInstruction<T>*>& args) :
21 AOperation<T>(args) {}
22
23 void execute() override;
24
25 inline std::string toString() const override { return KEY; }
26
27};
28
29} /* namespace operations */
30} /* namespace sxeval */
31
32
33/* IMPLEMENTATIONS */
34
35template <typename T>
36constexpr const char* sxeval::operations::NotEqual<T>::KEY;
37
38template <typename T>
40 this->_result = static_cast<T>(1);
41 size_t i = 0;
42 bool verif = true;
43 while (verif && (i + 1) < this->_args.size()) {
44 verif = sxeval::NotEqual(this->_args[i].get(),
45 this->_args[i + 1].get());
46 ++i;
47 }
48 if (verif) {
49 this->_result = static_cast<T>(1);
50 }
51 else {
52 this->_result = static_cast<T>(0);
53 }
54}
55
56#endif /* SXEVAL_OPERATIONS_NOTEQUAL_HPP */
The AOperation class is an abstract base class for operations in the SXEval library.
Definition AOperation.hpp:22
The IInstruction class is an interface for any instructions.
Definition IInstruction.hpp:21
Definition NotEqual.hpp:14
static constexpr const int ARITY_MAX
Definition NotEqual.hpp:18
static constexpr const char * KEY
Definition NotEqual.hpp:16
NotEqual(const std::vector< IInstruction< T > * > &args)
Definition NotEqual.hpp:20
static constexpr const int ARITY_MIN
Definition NotEqual.hpp:17
void execute() override
Execute the operation.
Definition NotEqual.hpp:39
std::string toString() const override
String representation of the instruction.
Definition NotEqual.hpp:25
Definition AOperation.hpp:8
bool NotEqual(const T &a, const T &b)
Check if a is not equal to b.
Definition utils.hpp:73
std::enable_if< std::is_unsigned< T >::value, T >::type Absolute(const T &a)
Perform an absolute value operation on types T.
Definition utils.hpp:262