FuncSketch
Loading...
Searching...
No Matches
constant_list.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <optional>
23#include <string>
24#include <unordered_map>
25
27
28namespace func_sketch::math {
29
34public:
38 ConstantList() = default;
39
46 void emplace(const std::string& name, Number value) {
47 constants_.emplace(name, value);
48 }
49
56 [[nodiscard]] std::optional<Number> get(const std::string& name) const {
57 const auto iter = constants_.find(name);
58 if (iter == constants_.end()) {
59 return std::nullopt;
60 }
61 return iter->second;
62 }
63
64private:
66 std::unordered_map<std::string, Number> constants_;
67};
68
75
76} // namespace func_sketch::math
Class of lists of constants.
std::unordered_map< std::string, Number > constants_
List of constants.
void emplace(const std::string &name, Number value)
Append a constant to the list.
std::optional< Number > get(const std::string &name) const
Get a constant from the list.
ConstantList()=default
Constructor.
Definitions of common types.
std::variant< Integer, Real, Complex > Number
Type of numbers.
ConstantList generate_constant_list()
Generate a list of built-in constants.