FuncSketch
Loading...
Searching...
No Matches
unary_operator.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
28
29namespace func_sketch::math {
30
35public:
42 template <UnaryOperatorType T>
43 explicit UnaryOperator(T operator_object)
44 : operator_(std::move(operator_object)),
45 get_name_([](const utilities::Any& obj) -> std::string_view {
46 return obj.get<T>().name();
47 }),
48 scalar_operator_([](const utilities::Any& obj, const Number& arg,
49 Number& result) { obj.get<T>()(arg, result); }) {
50 }
51
57 [[nodiscard]] std::string_view name() const { return get_name_(operator_); }
58
65 void operator()(const Number& arg, Number& result) const {
66 scalar_operator_(operator_, arg, result);
67 }
68
69private:
71 using GetNameSignature = std::string_view(
72 const utilities::Any& /*operator_object*/);
73
76 const utilities::Any& /*operator_object*/, const Number& /*arg*/,
77 Number& /*result*/);
78
81
84
87};
88
89} // namespace func_sketch::math
Definition of Any class.
utilities::Any operator_
Operator object.
std::string_view name() const
Get the name of the operator.
std::string_view( const utilities::Any &) GetNameSignature
Signature of function to get the name of the operator.
void operator()(const Number &arg, Number &result) const
Operate on a scalar.
void( const utilities::Any &, const Number &, Number &) ScalarOperatorSignature
Signature of function to operate on a scalar.
GetNameSignature * get_name_
Function to get the name of the operator.
UnaryOperator(T operator_object)
Constructor.
ScalarOperatorSignature * scalar_operator_
Function to operate on a scalar.
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 UnaryOperatorType concept.