hipony / enumerate Goto Github PK
View Code? Open in Web Editor NEWHeader-only, single file, C++11 compatible version of `enumerate`.
License: Boost Software License 1.0
Header-only, single file, C++11 compatible version of `enumerate`.
License: Boost Software License 1.0
for (auto&& [index, value] : enumerate(vec, size)) {}
enumerate(aggregate).each([](auto index, auto& value) {
...
});
for (auto&& [index, value] : enumerate({0, 1, 2, 3, 4, 5}) {}
for (auto&& [index, value] : enumerate(vec.begin(), vec.end()) {}
hipony::enumerate
type is not std::ranges::range
, so there is no way to use ranges algorithmstemplate<typename Self>
concept range = requires(Self& self)
{
ranges::begin(self);
ranges::end(self);
};
ranges::begin
(or ranges::end
) requires the follow concepttemplate<typename Self>
concept __member_begin = requires(Self& self)
{
{self.begin()} -> input_or_output_iterator;
};
input_or_output_iterator
, and then to weakly_incrementible
This is a small example of an iterator and ranges collection
struct iter
{
using difference_type = std::ptrdiff_t;
iter() = default;
iter& operator++() {}
/*any type*/ auto operator++(int) {}
/*non-void*/ int& operator*() {}
bool operator==(const iter& other) const {} // automatically matching operator!=
};
static_assert(std::weakly_incrementable<iter>);
struct collection
{
auto begin() { return iter{}; }
auto end() { return iter{}; }
};
static_assert(std::ranges::range<collection>);
When I'd need to use the same classes under the same namespace - I need a way to reuse them rather than causing a multiple definitions error.
#define HIPONY_ENUMERATE_HAS_NODISCARD HIPONY_ENUMERATE_CPP17_OR_GREATER
Use __has_cpp_attribute
instead
for (auto&& [index, value] : enumerate(container, &Item::member)) {}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.