Skip to content

Commit

Permalink
SIZED CONTAINER HELPER
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 3, 2023
1 parent d151d0b commit 06d8af2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion nano/lib/container_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ class container_info_leaf : public container_info_component
*/
namespace nano::experimental
{
template <typename T>
concept sized_container = requires (T a) {
typename T::value_type;
{
a.size ()
} -> std::convertible_to<std::size_t>;
};

class container_info
{
public:
Expand Down Expand Up @@ -83,7 +91,7 @@ class container_info
* @param count
* @param sizeof_element
*/
void put (std::string const & name, std::size_t size, std::size_t sizeof_element)
void put (std::string const & name, std::size_t size, std::size_t sizeof_element = 0)
{
entries_m.push_back ({ name, size, sizeof_element });
}
Expand All @@ -94,6 +102,12 @@ class container_info
put (name, size, sizeof (T));
}

template <sized_container T>
void put (std::string const & name, T const & container)
{
put (name, container.size (), sizeof (typename T::value_type));
}

public:
bool children_empty () const
{
Expand Down

0 comments on commit 06d8af2

Please sign in to comment.