numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
function_object_wrapper.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 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 <type_traits>
23#include <utility>
24
25namespace num_collect::opt {
26
35template <typename Signature, typename Function>
37
47template <typename Value, typename Variable, typename Function>
48class function_object_wrapper<Value(Variable), Function> {
49public:
51 using variable_type = std::decay_t<Variable>;
52
54 using value_type = std::decay_t<Value>;
55
57 using function_type = std::decay_t<Function>;
58
65 : function_(std::move(function)) {}
66
72 void evaluate_on(const variable_type& variable) {
73 value_ = function_(variable);
74 }
75
81 [[nodiscard]] auto value() const -> const value_type& { return value_; }
82
83private:
86
88 value_type value_{};
89};
90
99template <typename Signature, typename Function>
100[[nodiscard]] inline auto make_function_object_wrapper(Function&& function)
103 std::forward<Function>(function));
104}
105
106} // namespace num_collect::opt
auto value() const -> const value_type &
Get function value.
void evaluate_on(const variable_type &variable)
Evaluate function value on a variable.
Wrapper class of a function object to use as an objective function.
Namespace of optimization algorithms.
auto make_function_object_wrapper(Function &&function) -> function_object_wrapper< Signature, Function >
Create function_object_wrapper object.
STL namespace.