FuncSketch
Loading...
Searching...
No Matches
math_function.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 <string_view>
23#include <utility>
24#include <vector>
25
29
30namespace func_sketch::math {
31
36public:
43 template <MathFunctionType T>
44 explicit MathFunction(T function)
45 : function_(std::move(function)),
46 get_name_([](const utilities::Any& obj) -> std::string_view {
47 return obj.get<T>().name();
48 }),
49 scalar_operator_(
50 [](const utilities::Any& obj, const std::vector<Number>& args,
51 Number& result) { obj.get<T>()(args, result); }) {}
52
58 [[nodiscard]] std::string_view name() const { return get_name_(function_); }
59
66 void operator()(const std::vector<Number>& args, Number& result) const {
67 scalar_operator_(function_, args, result);
68 }
69
70private:
72 using GetNameSignature = std::string_view(
73 const utilities::Any& /*function_object*/);
74
77 const utilities::Any& /*function_object*/,
78 const std::vector<Number>& /*args*/, Number& /*result*/);
79
82
85
88};
89
90} // namespace func_sketch::math
Definition of Any class.
std::string_view( const utilities::Any &) GetNameSignature
Signature of function to get the name of the function.
std::string_view name() const
Get the name of the function.
GetNameSignature * get_name_
Function to get the name of the function.
void operator()(const std::vector< Number > &args, Number &result) const
Operate on scalars.
MathFunction(T function)
Constructor.
utilities::Any function_
Function object.
ScalarOperatorSignature * scalar_operator_
Function to operate on scalars.
void( const utilities::Any &, const std::vector< Number > &, Number &) ScalarOperatorSignature
Signature of function to operate on scalars.
Class to store any type of value.
Definition any.h:33
const T & get() const
Get the stored value.
Definition any.h:51
Definitions of common types.
std::variant< Integer, Real, Complex > Number
Type of numbers.
Definition of MathFunctionType concept.