ALFI
Advanced Library for Function Interpolation
Loading...
Searching...
No Matches
misc.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <utility>
5
6namespace alfi::util::misc {
7 template <typename Function>
9 public:
10 // ReSharper disable once CppNonExplicitConvertingConstructor
11 SimpleScopeGuard(Function on_exit) : _on_exit(std::move(on_exit)) {} // NOLINT(*-explicit-constructor)
12 ~SimpleScopeGuard() noexcept { _on_exit(); }
15 private:
16 Function _on_exit;
17 };
18
19 template <typename... Ts>
20 struct overload : Ts... {
21 using Ts::operator()...;
22 };
23 template <typename... Ts>
24 overload(Ts...) -> overload<Ts...>;
25
26 template <typename Iterator, typename T>
27 Iterator first_leq_or_begin(Iterator begin, Iterator end, const T& value) {
28 auto iter = std::lower_bound(begin, end - 1, value);
29 if (iter != begin && *iter > value) {
30 --iter;
31 }
32 return iter;
33 }
34}
SimpleScopeGuard(Function on_exit)
Definition misc.h:11
~SimpleScopeGuard() noexcept
Definition misc.h:12
SimpleScopeGuard(const SimpleScopeGuard &)=delete
SimpleScopeGuard & operator=(const SimpleScopeGuard &)=delete
Definition misc.h:6
Iterator first_leq_or_begin(Iterator begin, Iterator end, const T &value)
Definition misc.h:27
overload(Ts...) -> overload< Ts... >
Definition misc.h:20