criteria/include/matador/condition/value.hpp

41 lines
883 B
C++

#ifndef CONDITION_VALUE_HPP
#define CONDITION_VALUE_HPP
#include "types.hpp"
#include <optional>
namespace matador::condition {
class value final {
public:
value() = default;
template<typename Type>
value(const Type& value) : value_(value) {}
value(const value &x) = default;
value& operator=(const value &x) = default;
value(value &&x) noexcept = default;
value& operator=(value &&x) noexcept = default;
~value() = default;
template<class Type>
std::optional<Type> as() const {
if (std::holds_alternative<Type>(value_)) {
return std::get<Type>(value_);
}
return std::nullopt;
}
template<class Type>
bool is() const {
return std::holds_alternative<Type>(value_);
}
[[nodiscard]] std::string str() const;
private:
basic_types value_;
};
}
#endif //CONDITION_VALUE_HPP