Sleipnir C++ API
Loading...
Searching...
No Matches
expression_type.hpp
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <stdint.h>
6
7#include <format>
8#include <utility>
9
10namespace slp {
11
15enum class ExpressionType : uint8_t {
17 NONE,
19 CONSTANT,
21 LINEAR,
23 QUADRATIC,
25 NONLINEAR
26};
27
28} // namespace slp
29
31template <>
32struct std::formatter<slp::ExpressionType> {
37 constexpr auto parse(std::format_parse_context& ctx) {
38 return m_underlying.parse(ctx);
39 }
40
47 template <typename FmtContext>
48 auto format(const slp::ExpressionType& type, FmtContext& ctx) const {
49 using enum slp::ExpressionType;
50
51 switch (type) {
52 case NONE:
53 return m_underlying.format("none", ctx);
54 case CONSTANT:
55 return m_underlying.format("constant", ctx);
56 case LINEAR:
57 return m_underlying.format("linear", ctx);
58 case QUADRATIC:
59 return m_underlying.format("quadratic", ctx);
60 case NONLINEAR:
61 return m_underlying.format("nonlinear", ctx);
62 default:
63 std::unreachable();
64 }
65 }
66
67 private:
68 std::formatter<const char*> m_underlying;
69};
auto format(const slp::ExpressionType &type, FmtContext &ctx) const
Definition expression_type.hpp:48
constexpr auto parse(std::format_parse_context &ctx)
Definition expression_type.hpp:37