Giter Site home page Giter Site logo

Comments (4)

simonask avatar simonask commented on June 23, 2024

That line exists solely to silence "no return statement in non-void function" warnings. I wonder if calling std::abort() and adding [[noreturn]] would be more elegant.

from rx-ranges.

Hazurl avatar Hazurl commented on June 23, 2024

No. You just need to not create the _get method with an empty index_sequence, and never call it.
Nevermind you always get a branch with no return statement with my solution.

from rx-ranges.

Hazurl avatar Hazurl commented on June 23, 2024

I end up using your solution as this snippet is ugly (returning the last element if not in range):

    template <size_t i, size_t... rest>
    constexpr output_type _get(std::index_sequence<i, rest...>) const {
        RX_ASSERT(current_input < sizeof...(Rs)); // chain was at end!
        if constexpr (sizeof...(rest) <= 0) {
            return std::get<i>(inputs).get();
        } else {
            if (i == current_input) {
                return std::get<i>(inputs).get();
            } else {
                return _get(std::index_sequence<rest...>{});
            }
        }
    }

from rx-ranges.

simonask avatar simonask commented on June 23, 2024

And now I realize that the drawback of using std::abort() here is that ChainRange can no longer be used at all in a constexpr context. I wonder if throw can be used instead, but I'm not sure because I think the recursion base case will be compiled for any instantiation of get<size_t...>. This might have already been true with the assertion.

Alexandrescu has a solution here, but nobody seems to know why it works: https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions/

Hmm. I think it's more important to lift the default-constructibility requirement than to remain constexpr. I'll have a look at ensuring constexpr-ness later.

from rx-ranges.

Related Issues (10)

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.