Program Listing for File expression.hpp

Return to documentation for file (rcppsw/math/expression.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "rcppsw/rcppsw.hpp"

/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace rcppsw::math {

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
template <class T>
class expression {
 public:
  expression(void) = default;
  explicit expression(const T& last) : m_last(last) {}
  virtual ~expression(void) = default;

  expression(const expression&) = default;
  expression& operator=(const expression&) = default;

  T v(void) const { return m_last; }

  T eval(const T& val) { return m_last = val; }

  void reset(void) { m_last = T{ 0 }; }

  bool operator==(const expression& other) const {
    return this->v() == other.v();
  }
  bool operator>(const expression& other) const { return this->v() > other.v(); }
  bool operator<(const expression& other) const { return this->v() < other.v(); }

 private:
  /* clang-format off */
  T m_last{};
  /* clang-format on */
};

} /* namespace math::rcppsw */