Skip to content

Commit

Permalink
Merge pull request #79 from NuiCpp/range-improvements
Browse files Browse the repository at this point in the history
Range Improvements
  • Loading branch information
5cript authored Oct 1, 2023
2 parents 279a3d2 + a275b48 commit d751320
Show file tree
Hide file tree
Showing 18 changed files with 731 additions and 217 deletions.
58 changes: 58 additions & 0 deletions nui/include/nui/data_structures/selectables_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,14 @@ namespace Nui
return items_.begin();
}

/**
* @brief Returns a const iterator to the underlying container.
*/
typename ItemContainerType::const_iterator rawConstBegin() const
{
return items_.cbegin();
}

/**
* @brief Returns a const iterator to the underlying container.
*/
Expand All @@ -581,6 +589,56 @@ namespace Nui
return items_.end();
}

/**
* @brief Returns a const iterator to the underlying container.
*/
typename ItemContainerType::const_iterator rawConstEnd() const
{
return items_.cend();
}

template <typename RegistryPtr>
struct RawRangeWrap
{
RegistryPtr registry;
typename ItemContainerType::iterator begin() const
{
return registry->rawBegin();
}
typename ItemContainerType::iterator end() const
{
return registry->rawEnd();
}
typename ItemContainerType::iterator cbegin() const
{
return registry->rawConstBegin();
}
typename ItemContainerType::iterator cend() const
{
return registry->rawConstEnd();
}
};

/**
* @brief Helper for range based for loops.
*
* @return RawRangeWrap
*/
RawRangeWrap<SelectablesRegistry<T>*> rawRange()
{
return {this};
}

/**
* @brief Helper for range based for loops.
*
* @return RawRangeWrap
*/
RawRangeWrap<SelectablesRegistry<T> const*> rawRange() const
{
return {this};
}

private:
typename ItemContainerType::iterator findItem(IdType id)
{
Expand Down
14 changes: 14 additions & 0 deletions nui/include/nui/feature_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#ifdef __has_include
# if __has_include(<version>)
# include <version>
# ifdef __cpp_lib_ranges
# ifndef NUI_HAS_STD_RANGES
# define NUI_HAS_STD_RANGES 1
# elif NUI_HAS_STD_RANGES == 0
# undef NUI_HAS_STD_RANGES
# endif
# endif
# endif
#endif
3 changes: 2 additions & 1 deletion nui/include/nui/frontend/dom/element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,5 @@ namespace Nui::Dom
};
}

#include <nui/frontend/elements/impl/html_element.tpp>
#include <nui/frontend/elements/impl/html_element.tpp>
#include <nui/frontend/elements/impl/range_renderer.tpp>
Loading

0 comments on commit d751320

Please sign in to comment.