Giter VIP home page Giter VIP logo

Comments (5)

krzysztof-jusiak avatar krzysztof-jusiak commented on August 24, 2024

Not sure whether I fully understand, isn't the following what you are asking for 🤔

expect(1_i == 2);

from ut.

jwillikers avatar jwillikers commented on August 24, 2024

If I understand correctly, constant is for evaluating an expression at compile time. Please correct me if I'm wrong. When using constant the output for a failure is either true or false instead of a more detailed message containing the assertion. This is most likely a rather niche concern and possible a terrible idea anyways, but if you want to let users do more at compile time it might make sense. Maybe. 😶

from ut.

krzysztof-jusiak avatar krzysztof-jusiak commented on August 24, 2024

Ah, I see, yeah, you are right, constant is to ensure that expression can be evaluated at compile-time. It actually shows the expression (instead of true/false) if NTTP is supported (only gcc ATM, though, clang doesn't have it yet 😞).

NTTP branch -> https://github.com/boost-experimental/ut/blob/master/include/boost/ut.hpp#L1880
Full example -> https://godbolt.org/z/GJqhsE (it shows the expression in gcc but in clang it only shows true/false)

For the time being, for clang, I'd stick with the run-time version to see the expression and check whether it's constant on top of that (that works for both: clang and gcc)

constexpr auto expr = 1_i == 2;
expect(expr and constant<expr>);

Full example here -> https://godbolt.org/z/Zd-Ni9

from ut.

jwillikers avatar jwillikers commented on August 24, 2024

Awesome! That's exactly what I was talking about. 😌

from ut.

krzysztof-jusiak avatar krzysztof-jusiak commented on August 24, 2024

👍

from ut.

Related Issues (20)

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.