Code Monkey home page Code Monkey logo

enumerate's People

Contributors

minimonium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

brinkqiang2cpp

enumerate's Issues

Aggregates

enumerate(aggregate).each([](auto index, auto& value) {
    ...
});

Provide support for `std::range` interface

hipony::enumerate type is not std::ranges::range, so there is no way to use ranges algorithms

std::ranges:: range looks something like this:

template<typename Self>
concept range = requires(Self& self)
{
    ranges::begin(self);
    ranges::end(self);
};

and ranges::begin (or ranges::end) requires the follow concept

template<typename Self>
concept __member_begin = requires(Self& self)
{
    {self.begin()} -> input_or_output_iterator;
};

So it all comes down to 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>);

Thus, iterators in this style will help you use various useful things from std::ranges

Better feature detection

#define HIPONY_ENUMERATE_HAS_NODISCARD HIPONY_ENUMERATE_CPP17_OR_GREATER

Use __has_cpp_attribute instead

Projections

for (auto&& [index, value] : enumerate(container, &Item::member)) {}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.