Giter Site home page Giter Site logo

Constexpr If about cpp17_in_tts HOT 7 CLOSED

tvaneerd avatar tvaneerd commented on June 15, 2024
Constexpr If

from cpp17_in_tts.

Comments (7)

kalman5 avatar kalman5 commented on June 15, 2024

You can see in here how it should work

http://cpp-today.blogspot.com/2017/03/structured-binding-c17-inside.html

from cpp17_in_tts.

tvaneerd avatar tvaneerd commented on June 15, 2024

In the constexpr-if example, in C++14 I return void for get when N is out of bounds, but return int const & and string const & for the other 2. I don't see the problem?

For tuple_size/element - I'm leaving that out of the constexpr-if part, but I could be more clear about it in the structured bindings part, so I will update that.

from cpp17_in_tts.

kalman5 avatar kalman5 commented on June 15, 2024

As soon you want to use the get<> the compiler will bash you with something on the line of, I solved with returning auto and I had to not implement the not specialized one otherwise you will get the error at compile time even if you never use the get<2>()

test4.cpp:19:18: error: no function template matches function template specialization 'get'
template<> float get<0>(Y const & foo)
^
test4.cpp:16:22: note: candidate template ignored: could not match 'void (const Y &)' against 'float (const Y &)'
template void get(Y const & foo)

from cpp17_in_tts.

tvaneerd avatar tvaneerd commented on June 15, 2024

Yep I see it. I need to compile my example more. Thanks.
/working on fix...

from cpp17_in_tts.

tvaneerd avatar tvaneerd commented on June 15, 2024

Take a look at https://github.com/tvaneerd/cpp17_in_TTs/blob/master/if_constexpr.md before I merge it into ALL_IN_ONE.

from cpp17_in_tts.

kalman5 avatar kalman5 commented on June 15, 2024

You have a pull request that you can merge. Nice the usage of conditional_t however I sill prefer my implementation of tuple_element:

template<size_t I> struct std::tuple_element<I, Y> { using type = decltype(get<I>(declval<Y>())); };

from cpp17_in_tts.

tvaneerd avatar tvaneerd commented on June 15, 2024

thanks for the pull request

from cpp17_in_tts.

Related Issues (11)

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.