Template
Add variation of 'with' that extracts the trailing string and feeds it back into the callback
This commit is contained in:
1 parent
af1baeeef7
commit
753b64c826
1 file changed
+13
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
#include "core-library/traits/function-traits.h"
|
||||
|
||||
#include <ranges>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
@@ -22,6 +24,17 @@ public:
|
||||
std::invoke(std::forward<F>(function));
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
requires core::callable_with_argument_converted<F, std::string_view>
|
||||
void with(std::string_view arg_to_match_view, F&& function) const
|
||||
{
|
||||
if (m_arg_view.starts_with(arg_to_match_view))
|
||||
{
|
||||
const std::string_view value_part = m_arg_view.substr(arg_to_match_view.size());
|
||||
std::invoke(std::forward<F>(function), core::first_argument_type_t<F>{value_part});
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::string_view m_arg_view;
|
||||
std::span<char*> m_modifiers;
|
||||
|
||||
Reference in new issue
Block a user