Instances of std::function can store, copy, and invoke any CopyConstructible Callable target -- functions (via pointers thereto), lambda expressions, bind expressions, or other function objects, as well as pointers to member functions and pointers to data members.
Class template std::function is a general-purpose polymorphic function wrapper.
Делегат, т.е. std::function, не умеет захватывать указатели на методы.
struct MyStruct
{
void Test(int){}
};
std::function<void(MyStruct&, int)> f = &MyStruct::Test;
template<typename TSender, typename TEventArgs.
using EventHandler = std::function<void(TSender&, TEventArgs)>;
co_await AsyncTasks::Delay(1000); // Ожидаю 1000 мс получаю 1008 мс
void ContentUIElement::SetContent(Ref<IData> content)
{
SetProperty(ContentProperty, _content, content);
auto dataTemplate = content->GetDefaultDataTemplate();
if(dataTemplate != nullptr)
{
SetContentTemplate(std::move(dataTemplate));
}
else
{
InvalidateMeasure();
InvalidateContentPresenter();
}
}
void ContentUIElement::SetContent(Ref<IData> content)
{
SetProperty(ContentProperty, _content, content);
if(content.Is<UIElement>()) // dynamic_cast
{
SetContentTemplate(UIElementDataTemplate());
}
else if(content.Is<TextContent>()) // dynamic_cast
{
SetContentTemplate(TextDataTemplate());
}
else
{
InvalidateMeasure();
InvalidateContentPresenter();
}
}
class ChunkIterator
{
private:
TRange& _range;
size_t _size;
TIterator _begin;
TIterator _end;
public:
constexpr ChunkIterator(TRange& range, size_t size, TIterator begin):
_range(range),
_size(size),
_begin(begin),
_end(begin)
{
MoveNext();
}
constexpr auto operator*() const
{
return std::ranges::subrange(_begin, _end);
}
constexpr ChunkIterator& operator++()
{
MoveNext();
return *this;
}
constexpr ChunkIterator operator++(int)
{
ChunkIterator tmp = *this;
++(*this);
return tmp;
}
constexpr bool operator==(const ChunkIterator& other) const
{
return _begin == other._begin && _end == other._end;
}
constexpr bool operator!=(const ChunkIterator& other) const
{
return !(*this == other);
}
void MoveNext()
{
_begin = _end;
std::ranges::advance(_end, _size, _range.end());
}
};